Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pango-Warning Fonts custom #2399

Open
KaynoxDev opened this issue Jul 15, 2024 · 0 comments
Open

Pango-Warning Fonts custom #2399

KaynoxDev opened this issue Jul 15, 2024 · 0 comments

Comments

@KaynoxDev
Copy link

I have this error when i use my command for display my embed , i test multiple police and i have same warning

`(process:24588): Pango-WARNING **: 14:19:30.634: couldn't load font "Roboto Not-Rotated 60px", falling back to "Sans Not-Rotated 60px", expect ugly output.

(process:24588): Pango-WARNING **: 14:19:30.640: couldn't load font "Roboto Not-Rotated 24px", falling back to "Sans Not-Rotated 24px", expect ugly output.

(process:24588): Pango-WARNING **: 14:19:30.644: couldn't load font "Roboto Not-Rotated 50px", falling back to "Sans Not-Rotated 50px", expect ugly output.`

Steps to Reproduce

const { createCanvas, loadImage, registerFont } = require('canvas');
const path = require('path');
const fetch = require('node-fetch');
require('dotenv').config();
const { GUILD_ID, CHANNEL_MEMBER, CHANNEL_WELCOME, EMOJI_WELCOME } = process.env;
const { EmbedBuilder, AttachmentBuilder } = require('discord.js');

let cachedEmoji;

const fontPath = path.resolve(__dirname, '../../assets/fonts/Roboto-Regular.ttf');

try {
  registerFont(fontPath, { family: 'Roboto' });
  console.log('Font registered successfully');
} catch (error) {
  console.error('Error registering font:', error);
}
const createWelcomeImage = async (member) => {
  const canvas = createCanvas(400, 200);
  const ctx = canvas.getContext('2d');

  // Dégradé de fond
  const gradient = ctx.createLinearGradient(0, 0, canvas.width, canvas.height);
  gradient.addColorStop(0, '#36D1DC');
  gradient.addColorStop(1, '#5B86E5');
  ctx.fillStyle = gradient;
  ctx.fillRect(0, 0, canvas.width, canvas.height);

  // Avatar
  let avatarBuffer;
  try {
    const avatarURL = member.user.displayAvatarURL({ format: 'png', size: 128 });
    const response = await fetch(avatarURL);
    if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
    avatarBuffer = await response.buffer();
  } catch (error) {
    console.error('Error fetching avatar, using default:', error);
    const avatarCanvas = createCanvas(128, 128);
    const avatarCtx = avatarCanvas.getContext('2d');
    avatarCtx.fillStyle = '#CCCCCC';
    avatarCtx.fillRect(0, 0, avatarCanvas.width, avatarCanvas.height);
    avatarBuffer = avatarCanvas.toBuffer();
  }

  // Dessiner l'avatar
  ctx.drawImage(await loadImage(avatarBuffer), 25, 36, 128, 128);

  // Texte
  ctx.fillStyle = '#FFFFFF';
  ctx.textAlign = 'left';
  ctx.font = '60px Roboto';
  ctx.fillText('A bientôt', 160, 80);
  ctx.font = '24px Roboto';
  ctx.fillText('Sur le serveur Discord', 160, 120);
  ctx.font = '50px Roboto';
  ctx.fillText('Kokotti-TV', 160, 180);

  return canvas.toBuffer();
};

module.exports = {
  name: "guildMemberRemove",
  once: false,
  async execute(member, client) {
    if (member.user.bot) return;

    const updateChannelName = async () => {
      const guild = client.guilds.cache.get(GUILD_ID);
      if (!guild) return;

      const channel = guild.channels.cache.get(CHANNEL_MEMBER);
      if (!channel) return;

      const memberCount = guild.memberCount;
      await channel.setName(`『𝖪𝖮𝖪𝖮𝖬𝖤𝖬𝖡𝖱𝖤𝖲 - ${memberCount}』`);
    };

    const sendWelcomeEmbed = async () => {
      const guild = client.guilds.cache.get(GUILD_ID);
      if (!guild) return;

      const welcomeChannel = guild.channels.cache.get(CHANNEL_WELCOME);
      if (!welcomeChannel) return;

      let welcomeImage;
      try {
        welcomeImage = await createWelcomeImage(member);
      } catch (error) {
        console.error('Error creating welcome image:', error);
      }

      const secondsElapsed = Math.floor((Date.now() - member.joinedTimestamp) / 1000);
      const footerText = `Avait rejoint le serveur il y a ${secondsElapsed} seconde(s)`;

      if (!cachedEmoji) {
        cachedEmoji = client.emojis.cache.get(EMOJI_WELCOME);
      }

      const welcomeEmbed = new EmbedBuilder()
        .setColor('#0099ff')
        .setTitle('Un membre vient de partir... 🥹!')
        .setDescription(`${cachedEmoji} Kobotti te souhaite un bon retour parmi nous ! ${member.user.username}`)
        .setFooter({ text: footerText });

      if (welcomeImage) {
        const attachment = new AttachmentBuilder(welcomeImage, { name: 'welcome.png' });
        welcomeEmbed.setImage('attachment://welcome.png');
        await welcomeChannel.send({ embeds: [welcomeEmbed], files: [attachment] });
      } else {
        await welcomeChannel.send({ embeds: [welcomeEmbed] });
      }
    };

    try {
      await Promise.all([updateChannelName(), sendWelcomeEmbed()]);
    } catch (error) {
      console.error('Error in guildMemberRemove event:', error);
    }
  },
};

Your Environment

  • Version of node-canvas (output of npm list canvas or yarn list canvas):
  • Environment (Node 20.12.1, discord.js v14.14.1, canvas v2.11.2):
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant