繁体   English   中英

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

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM