【发布时间】:2021-04-27 10:53:44
【问题描述】:
我正在尝试为我的自定义 discord 机器人制定一个明确的命令,并且我已经编写了一些代码并且它运行良好!问题是该命令删除的消息比它被告知的少 1 条消息,例如:>clear 5 删除 4 条消息,我知道这是因为为启动批量删除而编写的命令本身是一条消息,但我不想要这发生了,args[0] + 1 似乎不起作用!
这是我当前的代码:
module.exports = {
name: 'clear',
description: "Delete/Clear messages with a simple command",
async execute(message, args) {
if (message.member.permissions.has("KICK_MEMBERS")) {
if (!args[0]) return message.reply("Please enter the amount of messages to clear!");
if (isNaN(args[0])) return message.reply("Please type a real number!");
if (args[0] > 100) return message.reply("You can't remove more than 100 messages at once!");
if (args[0] < 1) return message.reply("You have to delete at least one message!");
await message.channel.messages.fetch({ limit: args[0] }).then(messages => {
message.channel.bulkDelete(messages);
message.channel.send("<a:ces_Tick:774694116042342411> **Successfully deleted " + "`" + args[0] + " messages`**")
.then(msg => {
msg.delete({ timeout: 3000 })
})
});
} else {
message.channel.send("You don't have sufficient permissions to use this command!");
}
}
}
提前致谢! :)
【问题讨论】:
标签: javascript discord.js