如何使用特定命令删除频道?

时间:2021-01-28 21:23:04

标签: command bots channel

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

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

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-”的频道,而这是写入命令的频道。 任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

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

您的文件代码和命令需要具有相同的名称以进行验证,(if(command == "close"))。

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