本文介绍了MessageEmbed 字段值不能为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次我尝试这样做: !help command ,如果该命令没有任何别名,它会在控制台中给我该错误,我尝试了以下方法,如果特定命令没有别名,它应该返回 'None' ,这是代码:

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:

            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\OneDriveDocumentsGitHubFergus
ode_modulesdiscord.jssrcstructuresMessageEmbed.js:425:23)
    at C:Users\OneDriveDocumentsGitHubFergus
ode_modulesdiscord.jssrcstructuresMessageEmbed.js:445:14
    at Array.map (<anonymous>)
    at Function.normalizeFields (C:Users\OneDriveDocumentsGitHubFergus
ode_modulesdiscord.jssrcstructuresMessageEmbed.js:444:8)
    at MessageEmbed.addFields (C:Users\OneDriveDocumentsGitHubFergus
ode_modulesdiscord.jssrcstructuresMessageEmbed.js:259:42)
    at MessageEmbed.addField (C:Users\OneDriveDocumentsGitHubFergus
ode_modulesdiscord.jssrcstructuresMessageEmbed.js:250:17)
    at Object.module.exports.run (C:Users\OneDriveDocumentsGitHubFerguscommandsInformationhelp.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'}) ,我检查了每个字段.

The error is at .addField('Aliases', ${command.config.aliases !== undefined ? command.config.aliases : 'None'}) , I checked each field.

推荐答案

我认为错误可能是您在该字段中使用的方法导致错误,因此该字段为空.要在字符串中列出别名,您可以尝试以下方法.

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}`)

使用此方法,您可以从命令配置的别名数组中创建一个字符串.然后你看看是否没有任何别名.如果是,则字符串为无".在此之后,您需要将嵌入中的方法替换为变量 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.

这篇关于MessageEmbed 字段值不能为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-01 03:42