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
Tl; dr: How to find Discord IDs To find a Server, Channel, or Message ID, right-click on the server/ channel name, or message, and select 'Copy ID'.
Go to the Channel Permissions (right click->Edit Channel->Permissions) and add the bot user to the Roles/Members Permission list, then you can disable Read permissions for that specific user (or bot) so they are unable to see or interact with the channel.
On Android press and hold the Server name above the channel list. You should see the last item on the drop-down menu: 'Copy ID'. Click Copy ID to get the ID.
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 Advanced
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.
You can also use
bot.channels.find("name","welcome").send("Welcome!")
I tried a lot with the same error, and that's how I fixed it. I used client as my Client().
client.channels.cache.get("18NUMBERIDHERE").send("Welcome!");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With