![](/img/trans.png)
[英]Why is my purge command deleting all the messages in the chat and not the given number?
[英]Why is my purge command messing up?
我正在使用discord.js-commando創建清除命令,但是每當我嘗試清除具有兩位數的內容時,它都不會清除我想要的消息數。 例如,我告訴該機器人清除99條消息,並且只清除9條消息。代碼:
const Commando = require("discord.js-commando");
class PurgeCommand extends Commando.Command {
constructor(Client) {
super(Client, {
name: "purge",
group: "moderation",
memberName: "purge",
description: "Deletes a specified amount of messages.",
examples: ["purge [Number of Messages (MAX LIMIT: 100) ]"]
})
}
async run(message, args) {
if (message.guild.me.hasPermission("MANAGE_MESSAGES")) {
if (!isNaN(args[0]) && parseInt(args[0]) > 0) {
if (parseInt(args[0]) > 99) {
async function Purge() {
message.delete();
const fetched = await message.channel.fetchMessages({limit: 99});
message.channel.bulkDelete(fetched);
message.reply("I've successfully purged **" + fetched.size + "** messages.");
}
Purge();
} else {
async function aPurge() {
message.delete();
const afetched = await message.channel.fetchMessages({limit: parseInt(args[0])});
message.channel.bulkDelete(afetched);
message.reply("I've successfully purged **" + afetched.size + "** messages.");
}
aPurge();
}
} else {
message.reply("you have not specified a valid amount of messages to delete.")
}
} else {
message.reply("you do not have permission to execute this command.")
}
}
}
module.exports = PurgeCommand;
`
我解決了這個問題。 args[0]
給了我參數的第一個字符而不是整個參數,所以我只需要手動拆分消息的內容,然后以這種方式獲取第一個參數。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.