【问题标题】:How delete a channel with a specific command?如何使用特定命令删除频道?
【发布时间】:2021-05-02 20:07:50
【问题描述】:

我编写了一个代码来关闭您在其中编写命令的特定通道。

这是我的代码,它将每个命令重定向到它自己的文件夹并运行其中的代码。

events\message.js

    module.exports = (client, message) => {
    // Ignore all bots
    if (message.author.bot) return;
  
    // Ignore messages not starting with the prefix (in config.json)
    if (message.content.indexOf(client.config.prefix) !== 0) return;
  
    // Our standard argument/command name definition.
    const args = message.content.slice(client.config.prefix.length).trim().split(/ +/g);
    const command = args.shift().toLowerCase();
  
    // Grab the command data from the client.commands Enmap
    const cmd = client.commands.get(command);
  
    // If that command doesn't exist, silently exit and do nothing
    if (!cmd) return;
  
    // Run the command
    cmd.run(client, message, args);
};

我的代码删除了写入命令的通道。

const ms = require('ms');

const Discord = require('discord.js');
const client = new Discord.Client();

exports.run = async (client, message, args) => {

    if (!message.member.permissions.has("ADMINISTRATOR", "Ticket Admin"))
        return message.reply('You need a specify permission to setup a ticket!');

    if (message.author.bot) return;

    const msgargs = message.content.slice(client.config.prefix.length).trim().split(/ +/g);
    const command = msgargs.shift().toLowerCase();

    if(command == "close") {
        if(!message.channel.name.includes("ticket-")) return message.channel.send("You cannot use that here!")
        message.channel.delete();
        
    }
};    

但问题是它不想删除他名字中带有“ticket-”的频道,而这是写入命令的频道。 任何帮助将不胜感激。

【问题讨论】:

    标签: command bots channel


    【解决方案1】:

    您的文件名与您的命令不同。 因此,当您发送命令$ticket-close 时,它会运行票证关闭文件,但在票证关闭文件中,您正在验证命令是否已关闭而不是结束它。

    您的文件代码和您的命令必须具有相同的名称才能验证,(if(command == "close"))。

    或者只是不检查命令是什么。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-18
      • 2020-12-26
      • 2019-09-05
      • 2022-01-12
      • 1970-01-01
      • 2020-11-22
      • 1970-01-01
      • 2021-11-17
      相关资源
      最近更新 更多