[英]MessageEmbed field values may not be empty
everytime I am trying to do like: ,help command, if the command doesn't have any aliases, it gives me that error in the console, I tried the following method which if there is no aliases for the specific command, it should return 'None': here's the code:每次我尝试这样做时: ,help 命令,如果命令没有任何别名,它会在控制台中给我那个错误,我尝试了以下方法,如果特定命令没有别名,它应该返回“无”:这是代码:
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)
And here is the error:这是错误:
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.
The error is at.addField('Aliases', ${command.config.aliases?== undefined. command.config:aliases : 'None'}
), I checked each field.错误是 at.addField('Aliases', ${command.config.aliases?== undefined. command.config:aliases : 'None'}
),我检查了每个字段。
I think the error may be, that the method you used in this field causes an error and because of this, the field is empty.我认为错误可能是您在此字段中使用的方法导致错误,因此该字段为空。 To list the aliases in a string you can try the following method.要在字符串中列出别名,您可以尝试以下方法。
let aliases = command.config.aliases.toString();
if (aliases == "") {
aliases = "None";
}
.addField('Aliases', `${aliases}`)
With this method, you create a String from the aliases array of your command config.使用此方法,您可以从命令配置的别名数组中创建一个字符串。 Then you look if there aren't any aliases.然后你看看是否没有任何别名。 If yes the String is "None".如果是,则字符串为“无”。 After this, you need to replace your method in the embed with the variable aliases
.在此之后,您需要将嵌入中的方法替换为变量aliases
。
It seems like command.config.aliases
is indeed empty, even though it is not undefined.看起来command.config.aliases
确实是空的,即使它不是未定义的。 You should modify the check.您应该修改检查。 I do not know what the aliases
field contains, so I cannot say what the check should be.我不知道aliases
字段包含什么,所以我不能说检查应该是什么。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.