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);
我正在编写一个不和谐机器人,当分配的命令发出时,它会发送我的minecraft服务器的状态。但由于某些原因,它无法创建嵌入。这是我得到的错误:RangeError [EMBED_FIELD_VALUE]: MessageEmbed field values must be non-empty strings
。我试着用谷歌搜索这个错误,但我看不清楚。请告诉我哪里做错了,我该如何改正?(
试试这个:
.setTitle('Server Status')
.addField('Server IP', `** ** ${response.host}`)
.addField('Server Version', `** ** ${response.version}`)
.addField('Online Players', `** ** ${response.onlinePlayers}`)
.addField('Max Players', `** ** ${response.maxPlayers}`)