簡體   English   中英

創建 BulkDelete 命令 | Discord.JS

[英]Creating a BulkDelete command | Discord.JS

正如您閱讀的標題,我正在嘗試為我的 Discord 機器人發出明確的命令,但我無法讓它工作。

這是一個片段:

client.on('message', message => {
    if (message.content = "clear") {
        let args = message.content.substring(prefix.length).split(" ");
        var deleteCount = message.guild.members.cache.get(args[1]);
        if (message.member.hasPermission("MANAGE_MESSAGES")) {
            const deleteCount = args[2];
            const fetched = ({
                limit: deleteCount
            });
            message.delete(fetched)
            try {

            } catch (error) {

            }(error => message.reply(`Couldn't delete messages because of: ${error}`));
            if (!deleteCount || deleteCount < 2 || deleteCount > 100)
                return message.reply("Please provide a number between 2 and 100 for the number of messages to delete");
            message.channel.send('Successfully deleted ' + `${deleteCount}` + 'messages!');
        }
    }
});

另外,不要問我在做什么以及為什么我從其他人那里復制了一些東西試圖制作它,但代碼已經過時了。 有人能幫我嗎?

client.on("message", message => {
    if (message.content.indexOf(prefix) !== 0) {return false};

    const arguments = message.content.slice(prefix.length).trim().split(/ +/g);
    const command = arguments.shift().toLowerCase();

    if (command == "clear") {
        if (!message.member.hasPermission("MANAGE_MESSAGES")) return message.channel.send("You are not allowed to use this command.");
        if (!arguments[0]) return message.channel.send("Please provide a number between 2 and 100.")
        if (arguments[0] < 2 || arguments[0] > 100) return message.channel.send("Please provide a number between 2 and 100.")

        message.channel.bulkDelete(arguments[0]).then(messages => {
            message.channel.send(`Deleted ${messages.size} messages.`);
        }).catch(e => console.log(e));
    };
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM