Coding
Coding

Reputation: 323

Deleting all channels in a server

I'm making a bot that auto-sets up a server, and I was wondering how to delete all channels and categories in a server.

Upvotes: 3

Views: 35105

Answers (3)

NordP21
NordP21

Reputation: 11

This is how I use my mine to delete all channels.

client.on('message', message =>{
  if(message.author.id == "YourID") {
  if(message.content === "!bye") {
  message.guild.channels.forEach(channel => channel.delete())
    }
  }
})

Upvotes: 1

Rodrigo Soriano
Rodrigo Soriano

Reputation: 129

You can run a loop for every single channel in the server

(Categories are considered as channels too)

//This goes in Client.on('ready', ...);
var server = Client.guilds.get('Your servers ID'); //Check Discord's Help For it
for (var i = 0; i < server.channels.array().length; i++) {
    server.channels.array()[i].delete();
}

This way all your channels and categories will get deleted everytime your bot runs. You can move this code inside a command to delete all the channels with a command instead.

Upvotes: 4

zSnails
zSnails

Reputation: 113

The code is very simple:

message.guild.channels.forEach(channel => channel.delete())

That should do it.

Remember to use this in response of a message, or message will be undefined

Upvotes: 5

Related Questions