I have been making a discord bot and wanted to make it send a message to a specific "Welcome" channel. Unfortunately, I have been unable to do so. I tried this.
const welcomeChannel = bot.channels.get("name", "welcome")
welcomeChannel.sendMessage("Welcome\n"+member.user.username);
However in this "welcomeChannel is undefined".
Edit:
I tried using
const welcomeChannel = bot.channels.get("id", "18NUMBERIDHERE")
welcomeChannel.sendMessage("Welcome\n"+member.user.username);
but this is still undefined, strangely
You should use the channnel id instead of it's name.
How to get the channel id of a channel:
Open up your Discord Settings
Go to Appearance
Tick Developer Mode
(And close the Discord settings)
Right click on your desired channel
Now there's an option Copy ID
to copy the channel id
Also checkout the discord.js documentation for (channel) collections
Furthermore your approach won't work because .get
wants a channel id (see the linked documentation above). In case you REALLY want to get an channel by its name, use .find
instead for that.
This is however a really bad idea in case your bot runs on more than one server since channel names can now occur multiple times.