简体   繁体   中英

Discord bot not able to create the embed RangeError [EMBED_FIELD_VALUE]: MessageEmbed field values must be non-empty strings

const {Client, RichEmbed, Intents, MessageEmbed } = require('discord.js'); 

 
const bot = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
 
 
const token = 'token is a secret';
 
const PREFIX = '!';
 
bot.on('ready', () =>{
    console.log('Bot has come online.');
});
 
bot.on('messageCreate', message =>{
 
    
    let args = message.content.substring(PREFIX.length).split(' ')
 
    switch(args[0]){
        case 'mc':
            
            const ping = require('minecraft-server-util')
 
 
            ping.status('ip', { port: port})
             .then((response)=>{
                
                const Embed = new MessageEmbed()
                .setTitle('Server Status', )
                .addField('Server IP', response.host)
                .addField('Server Version', response.version)
                .addField('Online Players', response.onlinePlayers)
                .addField('Max Players', response.maxPlayers)
                
                message.channel.send({ embeds: [Embed] });
            })
            .catch((error)=>{console.error(error);});
        break
 
    }
 
    })
 
bot.login(token);

I am coding a discord bot that sends the status of my minecraft server when the assigned command is issued. But for some reason it is not able to create the embed. This is the error i am getting: RangeError [EMBED_FIELD_VALUE]: MessageEmbed field values must be non-empty strings . I tried to google this error but i couldn't understand clearly. Please tell me where i have gone wrong and how should i correct it. :(

Try this:

.setTitle('Server Status')
.addField('Server IP', `** ** ${response.host}`)
.addField('Server Version', `** ** ${response.version}`)
.addField('Online Players', `** ** ${response.onlinePlayers}`)
.addField('Max Players', `** ** ${response.maxPlayers}`)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM