(Discord.js) 按名称获取频道

时间:2021-04-13 16:59:46

标签: discord.js

所以基本上我的目标是通过它的名字获得一个特定的频道。我想将它存储在一个变量中,以便稍后删除它。

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

是的,我知道我应该使用它的 ID 因为它更好,但是在这种情况下我不能使用它的 ID,我必须使用它的名称。

1 个答案:

答案 0 :(得分:1)

使用GuildChannelManager#find()

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

channel.delete();