Discord.js-commando 缺少参数回复

Posted

技术标签:

【中文标题】Discord.js-commando 缺少参数回复【英文标题】:Discord.js-commando missing argument reply 【发布时间】: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 丢失时自动向用户发出回复警告。 我的问题是,我怎样才能覆盖它?

提前致谢!

【问题讨论】:

【参考方案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();
    

【讨论】:

以上是关于Discord.js-commando 缺少参数回复的主要内容,如果未能解决你的问题,请参考以下文章

discord.js-commando RangeError:参数类型“字符串”未注册

嵌入命令(颜色)(discord.js-commando)

Discord.js 和 discord.js-commando 防止命令在特定通道中运行

discord.js-commando TypeError:RichEmbed 不是构造函数

广播所有命令不自动删除广播 - Discord.js-Commando

Discord.js-commando 节流不起作用