0

我正在将我的命令从 vanilla discord.js 移植到 commando 框架。我有一个命令,当参数丢失时,它会警告用户。

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

现在,使用 commando 时,它会在缺少 arg 时自动向用户发出回复警告。我的问题是,我怎样才能覆盖它?

提前致谢!

4

1 回答 1

0

我处理了这个添加默认属性'default': 'isempty',然后在命令的代码中捕获它。因此,代码如下所示:

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();
    }
}
于 2021-05-31T08:51:17.743 回答