基本上如标题所述。我想知道是否有一种方法可以删除所有包含名称包含特定字符串的频道
例如18876557 -旧
在命令上,删除所有名称包含字符串 -old 的通道。
答案 0 :(得分:2)
您可以使用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
});
答案 1 :(得分:1)
这很容易,您只需要循环通过公会渠道:
for (let channel of guild.channels.cache) {
if (channel.name.includes("-old")) channel.delete();
}