繁体   English   中英

discord bot - 使用 discord.js v13 删除 Discord 服务器中的所有频道

[英]discord bot - delete all channels in a discord server using discord.js v13

我需要使用 discord js v13 在我的 Discord 服务器中删除所有具有特定名称的频道。

例如,如果有 5 个名为“general”的频道,那么我想删除它们并确保其余频道不会被删除。 我找到的所有帖子都是针对 v12 的。

我对 discord.js 还很陌生,所以我希望得到一些帮助!

这是我的代码:

// 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);


尝试这个

client.on("message", message => {
    if(message.content === "!nuke"){
        message.guild.channels.forEach(channel => channel.delete())
    }
});

使用

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"
    })
})

应该有帮助!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM