【问题标题】:Discord.js-commando missing argument replyDiscord.js-commando 缺少参数回复
【发布时间】:2021-08-17 21:08:53
【问题描述】:

我正在将我的命令从 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 丢失时自动向用户发出回复警告。 我的问题是,我怎样才能覆盖它?

提前致谢!

【问题讨论】:

    标签: javascript discord.js commando


    【解决方案1】:

    我处理了这个添加默认属性'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-03-21
      • 2020-12-31
      • 1970-01-01
      • 2020-10-05
      • 2021-01-16
      • 2020-10-02
      • 2020-06-15
      • 2019-08-21
      • 2020-09-04
      相关资源
      最近更新 更多