discord.js-commando if else 循环

discord.js-commando if else loop

我已经为我的 bot 创建了一个清除功能,但是如果有人没有输入正确数量的消息来清除我希望它重新运行命令。唯一的问题是我似乎无法弄清楚该怎么做。 这就是我取得的进展:

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

module.exports = class SayCommand extends Command {
    constructor(client) {
        super(client, {
            name: 'purge',
            group: 'group1',
            memberName: 'purge',
            description: 'Deletes messages from the current channel.',
            examples: ['purge'],
            args: [
                {
                    key: 'count',
                    prompt: 'How many messages do you want to delete?',
                    type: 'integer'
                }
            ]
        });
    }

    run(msg, { count }) {
        if(count < 1 || count > 30) {
            msg.channel.bulkDelete(count).then(() => {
            msg.say('Deleted ' + count + ' messages.').then(msg => msg.delete(3000));
            });
        } else {
        msg.say('You can delete 1 to 30 messages at a time.');
    }
    }
};

在此之后它会停止,您需要再次调用该命令。 有没有一种循环直到用户输入正确数字的方法?

提前致谢!

您可以通过提供 minmax 值让 Commando 执行此操作:

args: [
            {
                key: 'count',
                prompt: 'How many messages do you want to delete?',
                type: 'integer',
                min: 1,
                max: 30,
                error: 'You can delete 1 to 30 messages at a time.'
            }
        ]

Docs