Home > OS >  Why do I get the error "Empty field value even though it is not empty?
Why do I get the error "Empty field value even though it is not empty?

Time:11-21

I have a problem with my bot... I get the error

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

Even though the fields values are not empty... Can anyone help me? Here is the snippet of code where the error happens:

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

CodePudding user response:

I assume you just have to remove name: and value: in each .addField, for example: .addField('snek', 'snek.'), but you will get another error because you are trying to send an embed using interaction.reply(embed), and you have to use interaction.reply({embeds: [embed]}) to make it work

CodePudding user response:

addField method takes 3 arguments

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

you can change your code to something like this:

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(embed);
    } catch (e) {
        console.warn(e);
    }
}
  • Related