【问题标题】:Discord.js is it possible to delete a channel only with "close" (without channeID)?Discord.js 是否可以仅使用“关闭”(没有 channeID)删除频道?
【发布时间】:2021-05-12 13:08:03
【问题描述】:

嘿,我正在开发一个小型应答机器人。我的成员可以使用已经存在的不和谐机器人打开工单/频道,并在这些工单中使用我的机器人编写。现在我想做一些他们只需要写“删除”的事情,没有任何频道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);
        
    };

});

感谢您的帮助!

【问题讨论】:

    标签: javascript discord bots


    【解决方案1】:

    您可以给频道起一个特殊的名称。例如 MEMBERSID-TICKET,在用户使用 CMD 后,它会搜索包含 Members IDTICKET 的频道。

    【讨论】:

    • Vielen Dank für deine Antwort。 Es klingt sinnvoll, aber ehrlich gesagt habe ich keine Ahnung 是 ich in dem Code umändern muss, damit das funktioniert。 Ich habe gegooglet, aber nicht so richtig was dazu gefunden。 Kannst du mir bitte etwas auf die Sprünge helfen?对不起,ich habe erst gerade vor 2 Tagen mit meinen ersten Versuchen angefangen, weiss noch nicht 所以auf anhieb 是wohin kommt。 ?
    • @TimeToLearn du kannst einfach auf Github danachsuchen。谎言 dir auch nochmal discord.js.org durch c:
    猜你喜欢
    • 2020-10-15
    • 2021-07-31
    • 2019-09-05
    • 2022-10-01
    • 2021-06-07
    • 1970-01-01
    • 2021-12-02
    • 2019-04-01
    • 2021-04-13
    相关资源
    最近更新 更多