#`WelcomeChannel` is `undefined` i don t

1 messages · Page 1 of 1 (latest)

coral canyon
#

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");
whole trail
#

Does the bot have access to it?

coral canyon
#

yes

#

my "beta bot" is admin on my server (yes i know not safe)

vapid badger
whole trail
#

You should use

WelcomeChannel.send({content: `your content`, attachments:  })
vapid badger
#

you could have a constant id and then use that for the get from cache, but you can't get from cache here

vapid badger
whole trail
#

or is this the formate ?

vapid badger
#

it'll be ignored, that's fixable later, and it's files, not attachments

whole trail
#

ah all commas are red nvm

vapid badger
#

they're orange, that's just syntax highlighting

coral canyon
#

😐 i don't know why this time i don't have error , but the canvas (attachement) don't come 😦

whole trail
vapid badger
#

whoops forgot to disable the ping, sorry

whole trail
#

np

coral canyon
#

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 ?

vapid badger
#

you didn't change message, attachment to { content: message, files: [attachment] }

coral canyon
#

so it's would be :

WelcomeChannel.send({content:`:wave::skin-tone-2: Salutation ${member}, bienvenue sur ${member.guild.name}`,files: [Attachment]}); 
```?
vapid badger
#

lgtm

whole trail
#

for me too

coral canyon
#

finally

#

i've just separate it into 2 different "message"

#

now let's go to make it pretty

vapid badger
#

you don't need to though

#

you can send those in a single message

coral canyon
vapid badger
#

you don't need to wrap the content in an array

coral canyon
#

ho ?

whole trail
#

the []

#

remove it from the content