Discord bot 清除命令错误 [INVALID_TYPE]:提供的选项不是对象

Posted

技术标签:

【中文标题】Discord bot 清除命令错误 [INVALID_TYPE]:提供的选项不是对象【英文标题】:Discord bot clear command error [INVALID_TYPE]: Supplied options is not an object 【发布时间】: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"

提前致谢! 问候

【问题讨论】:

【参考方案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)); 然后我没有得到控制台错误。我不知道这是否是正确的方法。

以上是关于Discord bot 清除命令错误 [INVALID_TYPE]:提供的选项不是对象的主要内容,如果未能解决你的问题,请参考以下文章

Java Discord Bot (JDA) 检查是不是固定

Python discord bot“找不到命令'ban'”错误

Discord bot命令不起作用返回错误

bot.js 中的 Discord BOT 错误(SyntaxError:无效或意外令牌)

Discord Python代码中的命令未找到错误

Discord bot 发送消息特定通道错误