#The image is not sent
30 messages · Page 1 of 1 (latest)
- What's your exact discord.js
npm list discord.jsand nodenode -vversion? - Not a discord.js issue? Check out #1081585952654360687.
- Consider reading #how-to-get-help to improve your question!
- Explain what exactly your issue is.
- Post the full error stack trace, not just the top part!
- Show your code!
- Issue solved? Press the button!
✅Marked as resolved by staff
const welcomeChannelId = '1221463992480960605'; // ID du canal de bienvenue
const backgroundImage = './assets/background.png';
module.exports = {
name: Discord.Events.GuildMemberAdd,
async run(client, member) {
try {
console.log("Début de la génération de l'image...");
const canvas = createCanvas(800, 400);
const ctx = canvas.getContext("2d");
const background = await loadImage(backgroundImage);
ctx.drawImage(background, 0, 0, canvas.width, canvas.height);
ctx.font = "36px Arial";
ctx.fillStyle = "#ffffff";
ctx.fillText(`Bienvenue, ${member.user.username} !`, 50, 50);
const avatar = await loadImage(member.user.displayAvatarURL({ extension: 'jpg', size: 128 }));
ctx.drawImage(avatar, 50, 100, 100, 100);
const buffer = canvas.toBuffer("image/png");
console.log("Image générée avec succès.");
console.log("Début de l'enregistrement de l'image sur le disque...");
await fs.promises.writeFile("./welcome_image.png", buffer);
console.log("Image enregistrée avec succès.");
console.log("Tentative d'envoi de l'image sur Discord...");
const welcomeChannel = client.channels.cache.get(welcomeChannelId);
if (welcomeChannel) {
console.log("Canal de bienvenue trouvé. Tentative d'envoi de l'image...");
await welcomeChannel.send(`Bienvenue ${member.user} !`, {
files: [{ attachment: './welcome_image.png' }] // Assurez-vous que le chemin est correct
});
console.log("Image envoyée avec succès sur Discord.");
} else {
console.error("Canal de bienvenue introuvable.");
}
} catch (error) {
console.error("Une erreur s'est produite :", error);
}
},
};
It takes one object
.send({ content: <String>, files: [ attachment ] })
Also, why save it to your system, you can just pass the buffer into an AttachmentBuilder
Files in embeds should be attached via the message option object and referenced in the embed:
const attachment = new AttachmentBuilder('./image.png', { name: 'image1.png' });
const embed = new EmbedBuilder()
.setTitle('Attachments')
.setImage(`attachment://${attachment.name}`);
channel.send({
embeds: [embed],
files: [attachment]
});
Just ignore the embed builder part
I'm sorry I don't know the JS actually the code given was generated via chatGPT
If I've understood correctly, all I have to do is attachment://${attachment.name}`); right?
- Don’t use ai to generate code for this specific situation. It’s trained on old data, and old versions of djs.
- I basically just coded 70% of it for you, and gave you the rest of the 30%
Just ignore the embed builder part
Can you just tell me if my reasoning is right please?
No. If you read what I say you can work that out as well
Ho okey I think I just understood
Ah well no I tried with
new: AttachmentBuilder('./welcome_image.png', { name: 'welcome_image.png' }),
but it doesn't work
Also, why save it to your system, you can just pass the buffer into an AttachmentBuilder
you can just pass the buffer
Look, I don't know, like I told you, I don't know JS. I was just trying to make a bot that works with the means at my disposal.
Then please follow our rules, #rules . It’s for your own benefit since making a discord bot requires some knowledge of JavaScript
Have you look at the discord js guide about canvas ?
Oh nan I had not seen this guide
The guide is for people who want to create an order. I haven't figured out how to attach a canvas-generated file to my code. I'm sorry if I sound silly.
That guide literally shows how to do that though
There's really something I don't understand, but in my code it doesn't work.
#1081585952654360687 as canvas still is not discord.js
Or follow #how-to-get-help if it i djs related
Bah nique ca mère je vais me débrouiller puisque personne ne veux m'aider ici
#rules 2