Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
441 views
in Technique[技术] by (71.8m points)

bots - How delete a channel with a specific command?

I made a code that closes the specific channel that you write the command in.

This is my code that redirects each command to its own folder and runs the code in it.

eventsmessage.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);
};

And my code that deletes the channel the command is written in.

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();
        
    }
};    

but the problem is that it doesn't want to delete the channel with "ticket-" in his name and it's the channel that the command was written in. any help will be appreciated.

question from:https://stackoverflow.com/questions/65945424/how-delete-a-channel-with-a-specific-command

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Your file name isn't the same ass your command. so when you send the command $ticket-close it runs the ticket-close file but in the ticket-close file, you are verifying if the command was closed and not so it end it.

you need to have the same name for your file code and your command to verify,(if(command == "close")).

or just don't check what was the command.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...