I am trying to create a discord bot using node.js. I want the bot to send a welcome message. At the moment I copied the channel_id of the the welcome channel from discord. Though I want to write code to get the id of the welcome channel by its name. (Or if there is another more effective method). Using discord.js v13. Sorry if this is a stupid question or I am not following stackoverflow etiquette, first time posting.
CodePudding user response:
Fetch the channels of the guild and then find in the cache by its name
<Guild>.channels.fetch().then(channels => channels.cache.find(c=> c.name === "channel_name_here"))
CodePudding user response:
Use Guild.channels
to get the list of channel
s in the server, then loop through them using the fetch()
method to find a channel
with a matching name.