【问题标题】:Discord.js Bot help command doesn't workDiscord.js Bot 帮助命令不起作用
【发布时间】:2018-07-28 22:32:10
【问题描述】:

在过去的 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

【问题讨论】:

  • 在第 25 行上方添加 console.log(commands[cmd].name); 并检查您是否收到任何内容。我认为这可能是空白,因此错误“embed.fields[0].name: This field is required”
  • 不起作用。我得到同样的错误。
  • 这不是一个修复...它是检查commands[cmd].name 是否为空白,当您登录时,您是否在控制台中得到任何东西?
  • @newbie 它给出了完全相同的错误。绝对没有任何改变。
  • 请看我的回答。

标签: node.js bots discord.js


【解决方案1】:

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

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

【讨论】:

  • 没有。即使没有 .setColor,我也试过了,即使你说但没有。
【解决方案2】:

正如我在 cmets 中提到的,当我让您 console.log(commands[cmd].name); 时,您说控制台中没有出现任何内容。

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

此外,由于&lt;TextChannel&gt;#send() 返回promise,您应该使用.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);

【讨论】:

  • 我检查了一些东西,如果我指定用户、版主、管理员,它似乎可以工作。部分。部分原因是在使用时它显示如下内容:用法:[object Object]setPrefix 。当我将帮助留空时,它不起作用。
猜你喜欢
  • 2020-11-14
  • 2021-11-19
  • 2020-11-22
  • 2018-09-17
  • 2011-11-27
  • 2021-12-20
  • 2021-01-12
  • 2019-04-13
  • 2021-06-01
相关资源
最近更新 更多