我为我的机器人设置了清除功能,但是如果有人没有输入正确数量的消息进行清除,我希望它重新运行命令。唯一的问题是我似乎不知道该怎么办。 这就是我所要做的:
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.');
}
}
};
此后它将停止,您需要再次调用该命令。 在用户输入正确的数字之前,是否有循环的方法?
谢谢!
答案 0 :(得分:0)
您可以通过提供min
和max
值让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.'
}
]