【发布时间】:2021-09-05 17:33:17
【问题描述】:
当我使用该命令时,如果有超过 14 天的消息和一些不超过 14 天的消息,我可以删除那些不超过 14 天的消息,但仍然会出现 14 天错误.我希望它仅在有 0 条不超过 14 天的消息时才返回错误。 请帮忙。
我的代码:
文件名:purge.js
module.exports = {
name: "purge",
aliases: ['clear'],
category: "moderation",
permissions: "MANAGE_MESSAGES",
description: "Deletes messages from a channel.",
usage: "purge [amount of messages] [ignore pinned messages]",
execute: async (message, args) => {
if (!message.member.hasPermission("MANAGE_MESSAGES")) return message.channel.send("You don't have enough perms! You require: [MANAGE_MESSAGES]")
message.delete()
if (!args[0]) {
message.channel.bulkDelete(100)
.then().catch(e => {
message.channel.send(e.message)
})
.then(messages => message.channel.send(`**Succesfully deleted ${messages.size - 1} messages**`).then(msg => msg.delete({ timeout: 5000 }))).catch(() => null)
return
}
else if (args[0] === "true") {
const fetched = await message.channel.messages.fetch({ limit: 100 });
const notPinned = fetched.filter(fetchedMsg => !fetchedMsg.pinned);
await message.channel.bulkDelete(notPinned)
.then().catch(e => {
message.channel.send(e.message)
})
.then(messages => message.channel.send(`**Succesfully deleted ${messages.size - 1} messages.**`).then(msg => msg.delete({ timeout: 5000 }))).catch(() => null)
return
}
else if (parseInt(args[0]) > 100) {
return message.channel.send("**Please Supply A Number Less Than 100!**");
}
else if (parseInt(args[0]) < 1) {
return message.channel.send("**Please Supply A Number More Than 1!**");
}
if (args[1] === "true") {
const fetched = await message.channel.messages.fetch({ limit: args[0] });
const notPinned = fetched.filter(fetchedMsg => !fetchedMsg.pinned);
await message.channel.bulkDelete(notPinned)
.then().catch(e => {
message.channel.send(e.message)
})
.then(messages => message.channel.send(`**Succesfully deleted ${messages.size - 1} messages**`).then(msg => msg.delete({ timeout: 5000 }))).catch(() => null)
return
}
else {
message.channel.bulkDelete(args[0])
.then().catch(e => {
message.channel.send(e.message)
})
.then(messages => message.channel.send(`**Succesfully deleted ${messages.size - 1} messages**`).then(msg => msg.delete({ timeout: 5000 }))).catch(() => null)
return
}
},
};
【问题讨论】:
标签: javascript discord.js