javascript - MessageEmbed 字段值不能为空
问题描述
每次我尝试这样做时: !help command ,如果该命令没有任何别名,它会在控制台中给我那个错误,我尝试了以下方法,如果特定命令没有别名,它应该返回'无',代码如下:
let command = helpArgs[0]
if(helpArgs[0]){
if(bot.commands.has(command)) {
command = bot.commands.get(command)
const embed = new Discord.MessageEmbed()
.setTitle(`${command.config.name}`)
.addField('Name', `${command.config.name}`)
.addField('Description', `${command.config.description}`)
.addField('Usage', `${command.config.usage}`)
.addField('Aliases', `${command.config.aliases !== undefined ? command.config.aliases : 'None'}`)
message.channel.send(embed)
这是错误:
7:14 GMT+0300 (Eastern European Summer Time)
(node:11744) UnhandledPromiseRejectionWarning: RangeError [EMBED_FIELD_VALUE]: MessageEmbed field values may not be empty.
at Function.normalizeField (C:\Users\\OneDrive\Documents\GitHub\Fergus\node_modules\discord.js\src\structures\MessageEmbed.js:425:23)
at C:\Users\\OneDrive\Documents\GitHub\Fergus\node_modules\discord.js\src\structures\MessageEmbed.js:445:14
at Array.map (<anonymous>)
at Function.normalizeFields (C:\Users\\OneDrive\Documents\GitHub\Fergus\node_modules\discord.js\src\structures\MessageEmbed.js:444:8)
at MessageEmbed.addFields (C:\Users\\OneDrive\Documents\GitHub\Fergus\node_modules\discord.js\src\structures\MessageEmbed.js:259:42)
at MessageEmbed.addField (C:\Users\\OneDrive\Documents\GitHub\Fergus\node_modules\discord.js\src\structures\MessageEmbed.js:250:17)
at Object.module.exports.run (C:\Users\\OneDrive\Documents\GitHub\Fergus\commands\Information\help.js:115:18)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:11744) 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(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:11744) [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.
错误在 .addField('Aliases', ${command.config.aliases !== undefined ? command.config.aliases : 'None'}
) ,我检查了每个字段。
解决方案
看起来command.config.aliases
确实是空的,即使它不是未定义的。您应该修改检查。我不知道该aliases
字段包含什么,所以我不能说检查应该是什么。
推荐阅读
- error-handling - 配置的1234端口无法使用怎么办?
- airflow-scheduler - 气流插件 - 删除和重新创建同名 DAG 期间的奇怪行为
- algorithm - 比较分解时间得到素数
- linux - 如何在 linux OS 的 Hunspell 工具中为我自己的语言创建拼写检查器
- ios - 从 UILabel 文本掩码中获取 PDF
- node.js - 将耗时的任务委托给 Node.js 中的其他后台服务
- angular - 将数据显示为树角
- android - 如何使用 hashmap 迭代键值对并在 kotlin 的 recycleView 中显示?
- ios - 无法在 AppTests XCode 中加载模块“App”
- java - GitHub Actions:在 Windows 环境中缓存 Maven .m2 存储库 C\:\\Users\runneradmin\\.m2\repository:无法统计:没有这样的文件或目录