【问题标题】:Why is my purge command messing up?为什么我的清除命令搞砸了?
【发布时间】: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


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2012-02-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多