【问题标题】:Discord bot clear command error [INVALID_TYPE]: Supplied options is not an objectDiscord bot 清除命令错误 [INVALID_TYPE]:提供的选项不是对象
【发布时间】:2020-07-22 16:20:08
【问题描述】:

当我或某个随机用户尝试使用 !clear 命令时,我会在我的频道中看到此消息。

“是啊……这不是数字吗?顺便说一句,我也不能删除 0 条消息。 出了点问题...” + 此错误消息。 TypeError [MESSAGE_BULK_DELETE_TYPE]: The messages must be an Array, Collection, or number.

在我的控制台中,我收到此错误消息: (node:28184) UnhandledPromiseRejectionWarning: TypeError [INVALID_TYPE]: Supplied options is not an object.

这是我的 clear.js 脚本:

const discord = require("discord.js");

module.exports.run = async (bot, message, args) => {


    if (message.deletetable) {
        message.delete(); 
    }

    // Member doesn't have permission
    if (!message.member.hasPermission("MANAGE_MESSAGES")) {
        message.channel.send("You can't delete messages...").then(m => m.delete(5000));
    }

    // Check if args[0] is a number
    if (isNaN(args[0]) || parseInt(args[0]) <= 0) {
        message.channel.send("Yeah... That's not a number? I also can't delete 0 messages by the way.").then(m => m.delete(5000));

    }

    // Maybe the bot can't delete messages
    if (!message.guild.me.hasPermission("MANAGE_MESSAGES")) {
        message.channel.send("Sorry... I can't delete messages.").then(m => m.delete(5000));
    }

    let deleteAmount;

    if (parseInt(args[0]) > 100) {
        deleteAmount = 100;
    } else {
        deleteAmount = parseInt(args[0]);
    }

    message.channel.bulkDelete(deleteAmount, true)
        .then(deleted => message.channel.send(`I deleted \`${deleted.size}\` messages.`))
        .catch(err => message.channel.send(`Something went wrong... ${err}`));
}   


module.exports.help = {
  name: "clear"
}

提前致谢! 问候

【问题讨论】:

    标签: javascript error-handling bots discord discord.js


    【解决方案1】:

    当一个条件不成立时,您必须返回。
    要使命令正常工作,您必须提供一些消息以清除:!clear &lt;Number&gt;

        //...
    
        // Member doesn't have permission
        if (!message.member.hasPermission("MANAGE_MESSAGES")) {
            return message.channel.send("You can't delete messages...").then(m => m.delete(5000));
        }
    
        // Check if args[0] is a number
        if (isNaN(args[0]) || parseInt(args[0]) <= 0) {
            return message.channel.send("Yeah... That's not a number? I also can't delete 0 messages by the way.").then(m => m.delete(5000));
    
        }
    
        // Maybe the bot can't delete messages
        if (!message.guild.me.hasPermission("MANAGE_MESSAGES")) {
            return message.channel.send("Sorry... I can't delete messages.").then(m => m.delete(5000));
        }
    
        //...
    

    您可以在这里找到更多信息:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/return
    希望对您有所帮助!

    【讨论】:

    • 嗨 Rakox,退货有效,谢谢!只有我的控制台不断收到错误node:14532) UnhandledPromiseRejectionWarning: TypeError [INVALID_TYPE]: Supplied options is not an object. 我在使用!clear!clear 0 时收到此错误
    • 当我在 3 行上评论这个 OUT 时。 //.then(m =&gt; m.delete(5000)); 然后我没有得到控制台错误。我不知道这是否是正确的方法。
    猜你喜欢
    • 2020-08-10
    • 1970-01-01
    • 2021-07-25
    • 2018-09-17
    • 2021-04-30
    • 2018-11-21
    • 2021-05-26
    • 2021-06-24
    • 1970-01-01
    相关资源
    最近更新 更多