Discord.js 是否可以仅通过“关闭”(没有频道 ID)删除频道?

时间:2021-02-08 21:51:12

标签: javascript discord bots

嘿,我正在开发一个小型回答机器人。我的成员可以使用现有的不和谐机器人打开票证/频道,并在这些票证中使用我的机器人写。现在我想做一些他们只需要写“删除”的事情,没有任何频道 ID 或名称,频道应该被删除。 我搜索了它,但我发现的并不完全是我想要的。我尝试了一点,但我只是遇到了错误。

这是代码:

const client = new Discord.Client();
const config = require("./config.json");
const prefix = require('discord-prefix');


client.on("ready", () => {
  console.log("I am ready!");
});
//if the server doesn't have a set prefix yet
let defaultPrefix = '.';

client.on('message', (message) => {
    
    if (!message.guild) return;

    //get the prefix for the discord server
    let guildPrefix = prefix.getPrefix(message.guild.id);

    
    if (!guildPrefix) guildPrefix = defaultPrefix;

   
    let args = message.content.slice(guildPrefix.length).split(' ');
    if (!message.content.startsWith(guildPrefix)) return;
    
    
    
    
    if (args[0].toLowerCase() === ('ping')) {
        const user = message.author.name;
        return message.reply('pong');
} else

if (args[0].toLowerCase() === ('close') || args[0].toLowerCase() === ('delete') || args[0].toLowerCase() === ('cancel')) {
    
        const channel = message.guild.channels.find(channel => channel.name === name)
        channel.delete('Deleting the channel')
    .then(deleted => console.log(`Deleted ${deleted.name}`))
    .catch(console.error);
        
    };

});

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

您可以为频道指定一个特殊名称。例如 MEMBERSID-TICKET 并在用户使用 CMD 后搜索包含 Members IDTICKET 的频道。