DevTaube
DevTaube

Reputation: 315

(Discord.js) get channel by it's name

So basically my goal is to get a specific channel by it's name. I want to store it in a variable so I can delete it later.

let channel = //store specific channel in this variable using its name// ;
channel.delete();

And yes, I know I should use its ID because it's better, but in this case I can't use it's ID, I have to use its name.

Upvotes: 0

Views: 3319

Answers (1)

Elitezen
Elitezen

Reputation: 6710

Use GuildChannelManager#find()

let channel = message.guild.channels.cache.find(channel => channel.name === 'channel-name-here');

channel.delete();

Upvotes: 0

Related Questions