I'm using discord.js-commando to create a purge command, but whenever I try to purge something that has double digits, it doesn't purge the number of messages I want. Example, I tell the bot to purge 99 messages, and it only purges 9. Code:
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;
`
I figured out the problem. args[0]
gave me the first char of the argument instead of the entire argument, so I just had to manually split the message's content then get the first parameter that way.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.