【问题标题】:Why do I get the error "Empty field value even though it is not empty?为什么我会收到错误“即使字段值不为空也为空?
【发布时间】:2021-12-30 19:26:38
【问题描述】:

我的机器人有问题...我收到错误消息

RangeError [EMBED_FIELD_NAME]: MessageEmbed field names must be non-empty strings.
    at Function.verifyString (C:\Users\****\Documents\r-Wof-bot\node_modules\discord.js\src\util\Util.js:413:41)
    at Function.normalizeField (C:\Users\****\Documents\r-Wof-bot\node_modules\discord.js\src\structures\MessageEmbed.js:479:18)
    at C:\Users\****\Documents\r-Wof-bot\node_modules\discord.js\src\structures\MessageEmbed.js:501:14
    at Array.map (<anonymous>)
    at Function.normalizeFields (C:\Users\****\Documents\r-Wof-bot\node_modules\discord.js\src\structures\MessageEmbed.js:500:8)
    at MessageEmbed.addFields (C:\Users\****\Documents\r-Wof-bot\node_modules\discord.js\src\structures\MessageEmbed.js:322:42)
    at MessageEmbed.addField (C:\Users\****\Documents\r-Wof-bot\node_modules\discord.js\src\structures\MessageEmbed.js:313:17)
    at Client.<anonymous> (C:\Users\****\Documents\r-Wof-bot\bot.js:2081:7)
    at Client.emit (node:events:390:28)
    at InteractionCreateAction.handle (C:\Users\****\Documents\r-Wof-bot\node_modules\discord.js\src\client\actions\InteractionCreate.js:70:12) {  [Symbol(code)]: 'EMBED_FIELD_NAME'
}

即使字段值不为空...谁能帮助我?这是发生错误的代码的sn-p:

case 'help':
        let command = interaction.options.getString('cmd', false);
        if(command === null)
            try{
                let embed = new Discord.MessageEmbed()
                    .setTitle('Help')
                    .setColor('ORANGE')
                    .setFooter('Use /help cmd:<command> for more informations on that command!')
                    .addField({ name: 'kill', value: /*'Kills the bot. (Only available to bot-helper role)'*/'hi' }) //line 2081
                    .addField({ name: 'ping', value: 'Get the time delay between when you send the message and when the bot detects it.' })
                    .addField({ name: 'snek', value: 'snek.' })
                    .addField({ name: 'stalk', value: 'Get notified when the user whith the specified id logs in. Only works with this server\'s members.' })
                    .addField({ name: 'oc get', value: 'Get infos about an oc. Needs to have fetched the oc to the database from the message beforehand. See /help cmd:ocmessage.' })
                    .addField({ name: 'oc edit', value: 'Allows for the owner of the oc to edit in the database in case the data is wrong.' })
                    .addField({ name: 'quote', value: 'Starts a quizz about a quote. Guess the character who said that quote!' })
                    .addField({ name: 'fac, flip a coin', value: 'Flips a swiss coin. Warning: There is 1 in 100000000000000000 chance that the piece lands on its side. Be careful!' })
                    .addField({ name: 'hybridgen', value: 'A hybrid generator for you!' })
                    .addField({ name: 'oc message', value: 'Adds a message to the database' })
                    .addField({ name: 'help', valuse: 'Shows this message!' });
                interaction.reply(embed);
            } catch (e) {
                console.warn(e);
            }
    }

【问题讨论】:

  • 如果可能,您能否向我们展示完整的错误信息?它可能对我们有帮助
  • @MegaMix_Craft 更新

标签: javascript node.js discord discord.js


【解决方案1】:

addField 方法需要 3 个参数

embed.addField(name: string,value: string,inline: boolean)

你可以把你的代码改成这样:

case 'help':
let command = interaction.options.getString('cmd', false);
if(command === null)
    try{
        let embed = new Discord.MessageEmbed()
            .setTitle('Help')
            .setColor('ORANGE')
            .setFooter('Use /help cmd:<command> for more informations on that command!')
            .addField('kill', /*'Kills the bot. (Only available to bot-helper role)'*/'hi')
            .addField('ping', 'Get the time delay between when you send the message and when the bot detects it.')
            .addField('snek', 'snek.')
            .addField('stalk', 'Get notified when the user whith the specified id logs in. Only works with this server\'s members.')
            .addField('oc get', 'Get infos about an oc. Needs to have fetched the oc to the database from the message beforehand. See /help cmd:ocmessage.')
            .addField('oc edit', 'Allows for the owner of the oc to edit in the database in case the data is wrong.')
            .addField('quote', 'Starts a quizz about a quote. Guess the character who said that quote!')
            .addField('fac, flip a coin', 'Flips a swiss coin. Warning: There is 1 in 100000000000000000 chance that the piece lands on its side. Be careful!')
            .addField('hybridgen', 'A hybrid generator for you!')
            .addField('oc message', 'Adds a message to the database')
            .addField('help','Shows this message!');
        interaction.reply({embeds: [embed]});
    } catch (e) {
        console.warn(e);
    }
}

【讨论】:

  • 谢谢!我以为我必须指定它,因为它基于 object() 类型...
【解决方案2】:

我假设您只需要删除每个.addField 中的name:value:,例如:.addField('snek', 'snek.'),但您会收到另一个错误,因为您尝试使用interaction.reply(embed) 发送嵌入,并且您必须使用interaction.reply({embeds: [embed]}) 才能使其工作

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-06-22
    • 1970-01-01
    • 2014-05-15
    • 2021-07-14
    • 2022-06-30
    • 2016-04-05
    • 2020-10-25
    • 1970-01-01
    相关资源
    最近更新 更多