[英]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.