繁体   English   中英

Discord.js Bot帮助命令不起作用

[英]Discord.js Bot help command doesn't work

在过去的2-3天内,我尝试解决此问题。 当我输入chat!help时,该命令不起作用,并且在控制台中收到以下消息:

(node:13264) UnhandledPromiseRejectionWarning: DiscordAPIError: Invalid Form Body
embed.fields[0].name: This field is required
    at item.request.gen.end (C:\Users\alexx\Dropbox\Bot Try\node_modules\discord.js\src\client\rest\RequestHandlers\Sequential.js:71:65)
    at then (C:\Users\alexx\Dropbox\Bot Try\node_modules\snekfetch\src\index.js:215:21)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:160:7)
(node:13264) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:13264) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

运行帮助时运行的文件: https : //pastebin.com/jMRjy7Dw
app.js: https ://pastebin.com/PmVBKszM

正如我在评论中提到的那样,当我要求您进行console.log(commands[cmd].name); 您说控制台中什么都没发生。

这意味着您尝试使用空name尝试添加.addField() ,这将引发错误,因为该name不是可选的。

此外,由于<TextChannel>#send()返回一个承诺 ,你应该处理由使用这个承诺拒绝.catch() 在您的情况下, .catch(console.error)将在控制台中显示更详细的错误。 这是一个示例,以进一步阐明我的意思:

/* Here it is used correctly and will output an embed without any errors */
const embed = new Discord.RichEmbed()
 .addField('test', '123');
message.channel.send(embed).catch(console.error);

/* Here it is used incorrectly and will throw an error similar to your case */
const embed = new Discord.RichEmbed()
 .addField('', '123'); // as the name of the field is empty it will throw the error
message.channel.send(embed).catch(console.error);

在您发布的第一个链接中,我想您在“更新”实例时应该在括号中加上括号,即:

const embed = (new Discord.RichEmbed()).setColor(0x1D82B6);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM