【问题标题】:Creating a BulkDelete command | Discord.JS创建 BulkDelete 命令 |不和谐.JS
【发布时间】:2020-11-22 02:24:16
【问题描述】:

正如你读到的标题,我正在尝试为我的 Discord 机器人制定一个明确的命令,但我无法让它工作。

这是一个sn-p:

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!');
        }
    }
});

另外,不要问我在做什么,以及为什么我从其他人那里复制了一些东西,但代码已经过时了。 有人可以帮我吗?

【问题讨论】:

    标签: javascript node.js discord discord.js


    【解决方案1】:
    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));
        };
    });
    

    【讨论】:

      猜你喜欢
      • 2021-06-30
      • 2021-07-17
      • 2018-06-08
      • 1970-01-01
      • 2021-06-09
      • 2020-08-26
      • 2020-04-29
      • 2020-11-23
      • 2021-05-08
      相关资源
      最近更新 更多