I need to delete all the channels with a certain name in my discord server using discord js v13.
For example if there are 5 channels with the name "general" then I want to delete them and make sure that the rest of the channels don't get deleted. All the posts that I found were for v12.
I'm pretty new to discord.js, so I would appreciate some help!
This is my code:
// Require the necessary discord.js classes
const { Client, Intents } = require('discord.js');
const { token } = require('./config.json');
// Create a new client instance
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
// When the client is ready, run this code (only once)
client.once('ready', () => {
console.log('Ready!');
});
// Login to Discord with your client's token
client.login(token);
CodePudding user response:
Using
client.once('ready', () => {
console.log('Ready!');
let guild = client.guilds.cache.get('YOUR_GUILD_ID');
guild.channels.cache.forEach((channel) => { // check each channel in guild your command was executed in
if(channel.name == "general") channel.delete() // delete channel if its name is "general"
})
})
should help!