Sedi
Sedi
DIAdiscord.js - Imagine an app
Created by Sedi on 8/8/2023 in #djs-questions
Help with canvas
ok thx
4 replies
DIAdiscord.js - Imagine an app
Created by Sedi on 8/8/2023 in #djs-questions
Help with canvas
const { createCanvas, loadImage, registerFont } = require('canvas');
const { MessageAttachment } = require('discord.js');

client.on('guildMemberAdd', async (member) => {
const canvas = createCanvas(1024, 500);
const ctx = canvas.getContext('2d');
const bannerPath = 'https://media.discordapp.net/attachments/1077242624932593785/1138422426670203000/file.png?width=969&height=473'; // background URL here
const banner = await loadImage(bannerPath);
ctx.drawImage(banner, 0, 0, canvas.width, canvas.height);
ctx.fillStyle = '#FFFFFF';
const titleFont = '48px Arial';
const footerFont = '20px Arial';

// Register custom font if needed
// registerFont('path/to/font.ttf', { family: 'FontName' });

const circleX = canvas.width / 2;
const circleY = 240;
const circleRadius = 120;
const avatarX = circleX - circleRadius;
const avatarY = circleY - circleRadius;

ctx.beginPath();
ctx.arc(circleX, circleY, circleRadius, 0, Math.PI * 2);
ctx.closePath();
ctx.lineWidth = 10;
ctx.strokeStyle = 'white';
ctx.stroke();
ctx.clip();

const avatarURL = `https://cdn.discordapp.com/avatars/${member.id}/${member.user.avatar}.png`;
const avatar = await loadImage(avatarURL).catch(() => {
return loadImage(member.user.defaultAvatarURL);
});
ctx.drawImage(avatar, avatarX, avatarY, circleRadius * 2, circleRadius * 2);

ctx.fillStyle = '#000000'; // Set text background color to black
ctx.fillRect(0, circleY + circleRadius + 20, canvas.width, 80); // Draw black background

ctx.fillStyle = '#FFFFFF';
ctx.font = titleFont;
ctx.textAlign = 'end'; // Center the text
ctx.fillText(`${member.user.username}`, 400, 265);

const attachment = new MessageAttachment(canvas.toBuffer(), 'welcome.png');
member.send({ files: [attachment] }).catch(console.error);
});
const { createCanvas, loadImage, registerFont } = require('canvas');
const { MessageAttachment } = require('discord.js');

client.on('guildMemberAdd', async (member) => {
const canvas = createCanvas(1024, 500);
const ctx = canvas.getContext('2d');
const bannerPath = 'https://media.discordapp.net/attachments/1077242624932593785/1138422426670203000/file.png?width=969&height=473'; // background URL here
const banner = await loadImage(bannerPath);
ctx.drawImage(banner, 0, 0, canvas.width, canvas.height);
ctx.fillStyle = '#FFFFFF';
const titleFont = '48px Arial';
const footerFont = '20px Arial';

// Register custom font if needed
// registerFont('path/to/font.ttf', { family: 'FontName' });

const circleX = canvas.width / 2;
const circleY = 240;
const circleRadius = 120;
const avatarX = circleX - circleRadius;
const avatarY = circleY - circleRadius;

ctx.beginPath();
ctx.arc(circleX, circleY, circleRadius, 0, Math.PI * 2);
ctx.closePath();
ctx.lineWidth = 10;
ctx.strokeStyle = 'white';
ctx.stroke();
ctx.clip();

const avatarURL = `https://cdn.discordapp.com/avatars/${member.id}/${member.user.avatar}.png`;
const avatar = await loadImage(avatarURL).catch(() => {
return loadImage(member.user.defaultAvatarURL);
});
ctx.drawImage(avatar, avatarX, avatarY, circleRadius * 2, circleRadius * 2);

ctx.fillStyle = '#000000'; // Set text background color to black
ctx.fillRect(0, circleY + circleRadius + 20, canvas.width, 80); // Draw black background

ctx.fillStyle = '#FFFFFF';
ctx.font = titleFont;
ctx.textAlign = 'end'; // Center the text
ctx.fillText(`${member.user.username}`, 400, 265);

const attachment = new MessageAttachment(canvas.toBuffer(), 'welcome.png');
member.send({ files: [attachment] }).catch(console.error);
});
4 replies
DIAdiscord.js - Imagine an app
Created by Sedi on 8/8/2023 in #djs-questions
HELP
const { createCanvas, loadImage, registerFont } = require('canvas');
const { MessageAttachment } = require('discord.js');

client.on('guildMemberAdd', async (member) => {
const canvas = createCanvas(1024, 500);
const ctx = canvas.getContext('2d');
const bannerPath = 'https://media.discordapp.net/attachments/1077242624932593785/1138422426670203000/file.png?width=969&height=473'; // background URL here
const banner = await loadImage(bannerPath);
ctx.drawImage(banner, 0, 0, canvas.width, canvas.height);
ctx.fillStyle = '#FFFFFF';
const titleFont = '48px Arial';
const footerFont = '20px Arial';

// Register custom font if needed
// registerFont('path/to/font.ttf', { family: 'FontName' });

const circleX = canvas.width / 2;
const circleY = 240;
const circleRadius = 120;
const avatarX = circleX - circleRadius;
const avatarY = circleY - circleRadius;

ctx.beginPath();
ctx.arc(circleX, circleY, circleRadius, 0, Math.PI * 2);
ctx.closePath();
ctx.lineWidth = 10;
ctx.strokeStyle = 'white';
ctx.stroke();
ctx.clip();

const avatarURL = `https://cdn.discordapp.com/avatars/${member.id}/${member.user.avatar}.png`;
const avatar = await loadImage(avatarURL).catch(() => {
return loadImage(member.user.defaultAvatarURL);
});
ctx.drawImage(avatar, avatarX, avatarY, circleRadius * 2, circleRadius * 2);

ctx.fillStyle = '#000000'; // Set text background color to black
ctx.fillRect(0, circleY + circleRadius + 20, canvas.width, 80); // Draw black background

ctx.fillStyle = '#FFFFFF';
ctx.font = titleFont;
ctx.textAlign = 'end'; // Center the text
ctx.fillText(`${member.user.username}`, 400, 265);

const attachment = new MessageAttachment(canvas.toBuffer(), 'welcome.png');
member.send({ files: [attachment] }).catch(console.error);
});
const { createCanvas, loadImage, registerFont } = require('canvas');
const { MessageAttachment } = require('discord.js');

client.on('guildMemberAdd', async (member) => {
const canvas = createCanvas(1024, 500);
const ctx = canvas.getContext('2d');
const bannerPath = 'https://media.discordapp.net/attachments/1077242624932593785/1138422426670203000/file.png?width=969&height=473'; // background URL here
const banner = await loadImage(bannerPath);
ctx.drawImage(banner, 0, 0, canvas.width, canvas.height);
ctx.fillStyle = '#FFFFFF';
const titleFont = '48px Arial';
const footerFont = '20px Arial';

// Register custom font if needed
// registerFont('path/to/font.ttf', { family: 'FontName' });

const circleX = canvas.width / 2;
const circleY = 240;
const circleRadius = 120;
const avatarX = circleX - circleRadius;
const avatarY = circleY - circleRadius;

ctx.beginPath();
ctx.arc(circleX, circleY, circleRadius, 0, Math.PI * 2);
ctx.closePath();
ctx.lineWidth = 10;
ctx.strokeStyle = 'white';
ctx.stroke();
ctx.clip();

const avatarURL = `https://cdn.discordapp.com/avatars/${member.id}/${member.user.avatar}.png`;
const avatar = await loadImage(avatarURL).catch(() => {
return loadImage(member.user.defaultAvatarURL);
});
ctx.drawImage(avatar, avatarX, avatarY, circleRadius * 2, circleRadius * 2);

ctx.fillStyle = '#000000'; // Set text background color to black
ctx.fillRect(0, circleY + circleRadius + 20, canvas.width, 80); // Draw black background

ctx.fillStyle = '#FFFFFF';
ctx.font = titleFont;
ctx.textAlign = 'end'; // Center the text
ctx.fillText(`${member.user.username}`, 400, 265);

const attachment = new MessageAttachment(canvas.toBuffer(), 'welcome.png');
member.send({ files: [attachment] }).catch(console.error);
});
3 replies
DIAdiscord.js - Imagine an app
Created by Sedi on 7/28/2023 in #djs-questions
help
wow thank you so much
16 replies
DIAdiscord.js - Imagine an app
Created by Sedi on 7/28/2023 in #djs-questions
help
work thx !!! @Jô 🌈 🦄
16 replies
DIAdiscord.js - Imagine an app
Created by Sedi on 7/28/2023 in #djs-questions
help
like this?
16 replies
DIAdiscord.js - Imagine an app
Created by Sedi on 7/28/2023 in #djs-questions
help
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]
});
});
16 replies
DIAdiscord.js - Imagine an app
Created by Sedi on 7/28/2023 in #djs-questions
help
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
16 replies
DIAdiscord.js - Imagine an app
Created by Sedi on 7/28/2023 in #djs-questions
help
discord.js 13.16.0
16 replies
DIAdiscord.js - Imagine an app
Created by Sedi on 7/28/2023 in #djs-questions
help
This code does not send an image, only text
16 replies
DIAdiscord.js - Imagine an app
Created by Sedi on 7/28/2023 in #djs-questions
help
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);
});
16 replies