Basically as the title says. I'm wondering if there's a way of deleting all channels that contain a specific string for their name
Eg 18876557 -old
On command, delete all channels that names contain the string -old .
You can use Array.prototype.forEach()
and 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
});
This is pretty easy, you just need to loop through the guild channels:
for (let channel of guild.channels.cache) {
if (channel.name.includes("-old")) channel.delete();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.