【发布时间】:2018-11-05 12:19:21
【问题描述】:
我正在使用 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]长什么样子? -
我会试试的
-
您找到问题所在了吗?
-
是的,args[0] 给了我第一个字符而不是整个单词。
-
如果您修复了它,请发布并接受您的答案,这样这个问题就不会显示为未回答:)
标签: javascript node.js discord discord.js