Discord.js - Deleting all channels in a server

巧了我就是萌 提交于 2019-12-05 08:52:39

问题


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. Thanks, Codingpro


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/51201440/discord-js-deleting-all-channels-in-a-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!