Discord bot 无法创建嵌入 RangeError [EMBED_FIELD_VALUE]:MessageEmbed 字段值必须是非空字符串
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);
我正在编写一个 discord 机器人,它会在发出分配的命令时发送我的 minecraft 服务器的状态。但由于某种原因,它无法创建嵌入。这是我收到的错误:RangeError [EMBED_FIELD_VALUE]: MessageEmbed field values must be non-empty strings
。我试图google这个错误,但我无法理解清楚。请告诉我哪里出了问题,我应该如何纠正。 :(
试试这个:
.setTitle('Server Status')
.addField('Server IP', `** ** ${response.host}`)
.addField('Server Version', `** ** ${response.version}`)
.addField('Online Players', `** ** ${response.onlinePlayers}`)
.addField('Max Players', `** ** ${response.maxPlayers}`)
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);
我正在编写一个 discord 机器人,它会在发出分配的命令时发送我的 minecraft 服务器的状态。但由于某种原因,它无法创建嵌入。这是我收到的错误:RangeError [EMBED_FIELD_VALUE]: MessageEmbed field values must be non-empty strings
。我试图google这个错误,但我无法理解清楚。请告诉我哪里出了问题,我应该如何纠正。 :(
试试这个:
.setTitle('Server Status')
.addField('Server IP', `** ** ${response.host}`)
.addField('Server Version', `** ** ${response.version}`)
.addField('Online Players', `** ** ${response.onlinePlayers}`)
.addField('Max Players', `** ** ${response.maxPlayers}`)