help

Why isn't it working for me?
9 Replies
d.js toolkit
d.js toolkit17mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - 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!
Sedi
SediOP17mo ago
const Canvas = require('canvas');

const channelId = '1130503701107314810';

client.on('guildMemberAdd', async member => {
const channel = member.guild.channels.cache.get(channelId);
if (!channel) {
console.log(`Channel with ID: ${channelId} not found.`);
return;
}

const canvas = Canvas.createCanvas(700, 250);
const ctx = canvas.getContext('2d');

// Load background image
try {
const background = await Canvas.loadImage('https://media.discordapp.net/attachments/1077242624932593785/1134451337162141836/2Q.png');
ctx.drawImage(background, 0, 0, canvas.width, canvas.height);
} catch (error) {
console.log(`Error loading background image: ${error.message}`);
return;
}

// Draw user's avatar
try {
const avatar = await Canvas.loadImage(member.user.displayAvatarURL({ format: 'jpg' }));
ctx.drawImage(avatar, 25, 25, 200, 200);
} catch (error) {
console.log(`Error loading user avatar: ${error.message}`);
return;
}

// Draw welcome text
ctx.font = '30px sans-serif';
ctx.fillStyle = '#ffffff';
ctx.fillText(`Welcome, ${member.displayName}!`, canvas.width / 2.5, canvas.height / 1.8);

const attachment = new Discord.MessageAttachment(canvas.toBuffer(), 'welcome-image.png');

channel.send(`Welcome to the server, ${member}!`, attachment);
});
const Canvas = require('canvas');

const channelId = '1130503701107314810';

client.on('guildMemberAdd', async member => {
const channel = member.guild.channels.cache.get(channelId);
if (!channel) {
console.log(`Channel with ID: ${channelId} not found.`);
return;
}

const canvas = Canvas.createCanvas(700, 250);
const ctx = canvas.getContext('2d');

// Load background image
try {
const background = await Canvas.loadImage('https://media.discordapp.net/attachments/1077242624932593785/1134451337162141836/2Q.png');
ctx.drawImage(background, 0, 0, canvas.width, canvas.height);
} catch (error) {
console.log(`Error loading background image: ${error.message}`);
return;
}

// Draw user's avatar
try {
const avatar = await Canvas.loadImage(member.user.displayAvatarURL({ format: 'jpg' }));
ctx.drawImage(avatar, 25, 25, 200, 200);
} catch (error) {
console.log(`Error loading user avatar: ${error.message}`);
return;
}

// Draw welcome text
ctx.font = '30px sans-serif';
ctx.fillStyle = '#ffffff';
ctx.fillText(`Welcome, ${member.displayName}!`, canvas.width / 2.5, canvas.height / 1.8);

const attachment = new Discord.MessageAttachment(canvas.toBuffer(), 'welcome-image.png');

channel.send(`Welcome to the server, ${member}!`, attachment);
});
This code does not send an image, only text
Unknown User
Unknown User17mo ago
Message Not Public
Sign In & Join Server To View
Sedi
SediOP17mo ago
discord.js 13.16.0 And in the code I want it to send a picture with the background I set, with the content on the picture, but we won't send any picture to the room I set. Just the text
Unknown User
Unknown User17mo ago
Message Not Public
Sign In & Join Server To View
d.js docs
d.js docs17mo ago
method TextChannel#send() Sends a message to this channel.
Sedi
SediOP17mo ago
const Canvas = require('canvas');


const channelId = '1130503701107314810';

client.on('guildMemberAdd', async member => {
const channel = member.guild.channels.cache.get(channelId);
if (!channel) return;

const canvas = Canvas.createCanvas(700, 250);
const ctx = canvas.getContext('2d');

const background = await Canvas.loadImage('https://media.discordapp.net/attachments/1077242624932593785/1134451337162141836/2Q.png');
ctx.drawImage(background, 0, 0, canvas.width, canvas.height);

const avatar = await Canvas.loadImage(member.user.displayAvatarURL({ format: 'jpg' }));
ctx.drawImage(avatar, 25, 25, 200, 200);

ctx.font = '30px sans-serif';
ctx.fillStyle = '#ffffff';
ctx.fillText(`Welcome, ${member.displayName}!`, canvas.width / 2.5, canvas.height / 1.8);

const attachment = new Discord.MessageAttachment(canvas.toBuffer(), 'welcome-image.png');

// Send the welcome message and the image together
channel.send({
content: `Welcome to the server, ${member}!`,
files: [attachment]
});
});
const Canvas = require('canvas');


const channelId = '1130503701107314810';

client.on('guildMemberAdd', async member => {
const channel = member.guild.channels.cache.get(channelId);
if (!channel) return;

const canvas = Canvas.createCanvas(700, 250);
const ctx = canvas.getContext('2d');

const background = await Canvas.loadImage('https://media.discordapp.net/attachments/1077242624932593785/1134451337162141836/2Q.png');
ctx.drawImage(background, 0, 0, canvas.width, canvas.height);

const avatar = await Canvas.loadImage(member.user.displayAvatarURL({ format: 'jpg' }));
ctx.drawImage(avatar, 25, 25, 200, 200);

ctx.font = '30px sans-serif';
ctx.fillStyle = '#ffffff';
ctx.fillText(`Welcome, ${member.displayName}!`, canvas.width / 2.5, canvas.height / 1.8);

const attachment = new Discord.MessageAttachment(canvas.toBuffer(), 'welcome-image.png');

// Send the welcome message and the image together
channel.send({
content: `Welcome to the server, ${member}!`,
files: [attachment]
});
});
like this? work thx !!! @Jô 🌈 🦄 wow thank you so much
Unknown User
Unknown User17mo ago
Message Not Public
Sign In & Join Server To View
bear
bear17mo ago
is banan
Want results from more Discord servers?
Add your server