Search code examples
javascriptdiscord.jscommando

Discord.js-commando missing argument reply


I'm porting my commands from vanilla discord.js to commando framework. I had a command that, when the argument was missing, it warned the user.

const { Command } = require('discord.js-commando');

module.exports = class ServerCommand extends Command {
    constructor(client) {
        super(client, {
            name: 'say',
            aliases: ['s'],
            group: 'mod',
            memberName: 'say',
            description: 'Make the bot speak for you.',
            userPermissions: ['MANAGE_CHANNELS'],
            examples: [client.commandPrefix + 'say <text>',client.commandPrefix + 'say hello world'],
            args: [{
                key: 'text',
                prompt: 'What should the bot say?',
                type: 'string',
            }]
        })
    }

    run(message, { text }) {
        if (text == '' || !text)
            message.say("You didn't specify what the bot should say.")
        message.say(text);
        message.delete();
    }
}

Now, with commando, it automatically warns the user with a reply when the arg is missing. My question is, how can I overwrite it?

Thanks in advance!


Solution

  • I handled this adding default property 'default': 'isempty' and then I catch it in the command's code. So, the code looks like it:

    const { Command } = require('discord.js-commando');
    
    module.exports = class ServerCommand extends Command {
        constructor(client) {
            super(client, {
                name: 'say',
                aliases: ['s'],
                group: 'mod',
                memberName: 'say',
                description: 'Make the bot speak for you.',
                userPermissions: ['MANAGE_CHANNELS'],
                examples: [client.commandPrefix + 'say <text>',client.commandPrefix + 'say hello world'],
                args: [{
                    key: 'text',
                    prompt: 'What should the bot say?',
                    type: 'string',
                    'default': 'isempty',
                }]
            })
        }
    
        run(message, { text }) {
            if (text == 'isempty') return message.say("You didn't specify what the bot should say.");
    
            message.say(text);
            message.delete();
        }
    }