为什么我的清除命令搞乱了?

时间:2018-05-26 07:24:38

标签: javascript node.js discord discord.js

我正在使用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;

`

1 个答案:

答案 0 :(得分:0)

我发现了问题所在。 args[0]给了我参数的第一个字符,而不是整个参数,所以我只需要手动分割邮件的内容,然后以这种方式获取第一个参数。