send a message to random channel on join
if my bot has permissions, how can i make it so that it sends a message to a random channel when joining a server?
16 Replies
- What's your exact discord.js
npm list discord.js
and node node -v
version?
- Not a discord.js issue? Check out #other-js-ts.
- Consider reading #how-to-get-help to improve your question!
- Explain what exactly your issue is.
- Post the full error stack trace, not just the top part!
- Show your code!
- Issue solved? Press the button!Listen to the
guildCreate
event, get the channels collection, use random
function and send a message to it. You can also add a filter to only do this with textchannels Collection#random()
Obtains unique random value(s) from this Collection#map()
Maps each item to another value into an array. Identical in behavior to Array.map().
Skip the map one
thank you
how can i get the channel?
You define it then send to it?
thank you
there was no error but nothing happened
Well that's how you get the channel no just add a check that it exist, and send to it a message
try this it should work
also you can use this instead of 0 in the type
the bot needs to have access to that channel
and iirc cache contains all channels even if the bot does not have access
^ yes also check for permissions when filtering
TextChannel#permissionsFor()
Gets the overall set of permissions for a member or role in this channel, taking into account channel overwrites.