繁体   English   中英

(Discord.js) 删除频道名称中带有指定文本的频道

[英](Discord.js) Delete channels with specified text in name of Channel

基本上如标题所说。 我想知道是否有办法删除所有包含特定字符串名称的频道

例如 18876557 -

在命令中,删除名称包含字符串-old 的所有频道。

您可以使用Array.prototype.forEach()Channel.delete()

// iterate a function through all channels in the guild
guild.channels.cache.forEach((channel) => {
  if (guild.name.includes('-old')) // if the string '-old' is found within the channel name
    channel.delete() // delete the channel
      .then(() => console.log(`Deleted ${channel.name}`))
      .catch((e) => console.log(`Could not delete ${channel.name} because of ${e}`)) // handle any errors
});

这很简单,你只需要遍历公会频道:

for (let channel of guild.channels.cache) {
    if (channel.name.includes("-old")) channel.delete();
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM