Ask coding questions

← Back to all posts
basic Discord bot issues node.js
Mathman05 (1)

I have a discord server that I have my bot on and I have a channel I would like it to post to, I can figure out how to get the channel. Does anyone know how I would do this?

Answered by SixBeeps (5321) [earned 5 cycles]
View Answer
Comments
hotnewtop
SixBeeps (5321)

First get the channel ID

Then fetch the ID in code and send a message to it

client.channels.fetch('CHANNEL ID HERE')
  .then(channel => channel.send("This is a message!"))
  .catch(console.error);
Coder100 (18819)

but that's only if you know the id, and sometimes you don't know the id? @SixBeeps

SixBeeps (5321)

@Coder100 No, you'll always have access to the ID as long as the channel is visible. Either way, using the channel name is more intuitive, so your answer is better.

Mathman05 (1)

@SixBeeps thanks I can't test it right now but that should work! I know the ID.

Mathman05 (1)

@Coder100 I already have the ID and it's not responding to a message. it's just making a message.