#`WelcomeChannel` is `undefined` i don t
1 messages · Page 1 of 1 (latest)
I define it with other variable like i do everytime with "supervariable/variable global" in other langages :
//Variables
const { Client, GatewayIntentBits } = require("discord.js");
const Discord = require("discord.js");
const Canvas = require("canvas");
const client = new Client(
{
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers
]
});
let MyTestingReplyVar = "quoi";
let MyLeavingMessage01 = " est parti sans un aurevoir.";
let MyLeavingMessage02 = " a voyagé dans le passé où il n'était pas encore sur le serveur !";
let MyLeavingMessage03 = " a rejoint la planete prison des Dalek, on ne l'a plus jamais revu.";
let MyLeavingMessage04 = " est parti en quête d'aventure, on ne l'a plus jamais revu.";
const WelcomeChannel = client.channels.cache.get("1035551789833007237");
Does the bot have access to it?
you can't define it here, the channel cache won't be populated before the client is ready. get the channel from cache when needed instead of defining a global variable
You should use
WelcomeChannel.send({content: `your content`, attachments: })
you could have a constant id and then use that for the get from cache, but you can't get from cache here
this is not relevant in the absolute slightest
sure but there is an error in the end...
or is this the formate ?
it'll be ignored, that's fixable later, and it's files, not attachments
ah all commas are red nvm
they're orange, that's just syntax highlighting
😐 i don't know why this time i don't have error , but the canvas (attachement) don't come 😦
^^
my bots are admin too, don't that worry
if you want to send additional data or options other than the content, you have to use this format
for example
- sending embeds:
embeds: [...] - files/attachments:
files: [...] - mention options:
allowedMentions: { ... }
etc
whoops forgot to disable the ping, sorry
np
canvas setup :js var welcomeCanvas = {}; welcomeCanvas.create = Canvas.createCanvas(1024,500); welcomeCanvas.context = welcomeCanvas.create.getContext("2d"); welcomeCanvas.context.font = "72px sans-serif"; welcomeCanvas.context.fillStyle = "#ffffff"; Canvas.loadImage("./img/bg.png").then(async (img) => { welcomeCanvas.context.drawImage(img,0,0,1024,500); welcomeCanvas.context.fillText("Bienvenue", 360,360); welcomeCanvas.context.beginPath(); welcomeCanvas.context.arc(512,166,128,0, Math.PI * 2, true); welcomeCanvas.context.stroke(); welcomeCanvas.context.fill(); })
guildMemberAdd :js client.on("guildMemberAdd", async member => { console.log("guildMemberAdd Action SUCCEED !"); const WelcomeChannel = client.channels.cache.get("1035551789833007237"); let canvas = welcomeCanvas; canvas.context.font = "42px sans-serif"; canvas.context.textAlign = "center"; canvas.context.fillText(member.user.tag.toUpperCase(),512,410); canvas.context.font = "32px sans-serif"; canvas.context.fillText(`Tu es le ${member.guild.memberCount}e membres`, 512,455); canvas.context.beginPath(); canvas.context.arc(512,166,119,0,Math.PI * 2, true); canvas.context.closePath(); canvas.context.clip(); await Canvas.loadImage(member.user.displayAvatarURL({size: 1024,format:'png'})).then(img => { canvas.context.drawImage(img, 393,47,238,238); }) let Attachment = new Discord.AttachmentBuilder(canvas.create.toBuffer()); Attachment.setName(`welcome-${member.id}`); try{ WelcomeChannel.send(`:wave::skin-tone-2: Salutation ${member}, bienvenue sur ${member.guild.name}`,Attachment) } catch (error){ console.log(error); } //member.role.add(""); });
now it's just the attachement (canvas) who don't be here... the message come properly like as the picture
i forgot one thing ?
you didn't change message, attachment to { content: message, files: [attachment] }
so it's would be :
WelcomeChannel.send({content:`:wave::skin-tone-2: Salutation ${member}, bienvenue sur ${member.guild.name}`,files: [Attachment]});
```?
lgtm
for me too
finally
i've just separate it into 2 different "message"
now let's go to make it pretty
yes that's right
yes with that :
WelcomeChannel.send({content:[`:wave::skin-tone-2: Salutation ${member}, bienvenue sur ${member.guild.name}`],files: [Attachment]});
you don't need to wrap the content in an array
ho ?