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':
ping = require('minecraft-server-util')
ping = ('ip', port, (error, reponse) =>{
if(error) throw error
const Embed = new RichEmbed()
.setTitle('Server Status')
.addField('Server IP', reponse.host)
.addField('Server Version', reponse.version)
.addField('Online Players', reponse.onlinePlayers)
.addField('Max Players', reponse.maxPlayers)
message.reply({ embeds: [Embed] });
})
break
}
})
bot.login(token);
也没有显示任何错误。它只是在发出命令时没有响应。请告诉我的代码有什么问题…请告诉我如何改正。在这一行,"bot.on('messageCreate', message =>{...
";如果我用'message'
代替'messageCreate'
,机器人在发出命令时响应,但有一个错误消息说"(node:25372) DeprecationWarning: The message event is deprecated. Use messageCreate instead
"。请帮帮我:
对这个问题的一些回复建议我把"ping = ('ip', port, (error, reponse) =>{
";";ping('ip', port, error, response) =>{
";但它给出了错误ping is not a function
。根据一些建议,我意识到"RichEmbed()
";在不和谐v12中被删除,所以我尝试用const Embed = new MessageEmbed()
替换const Embed = new RichEmbed()
,但不幸的是,这也没有帮助。然而,当发出命令时,机器人没有回应。问题是,它也不显示任何错误消息,所以我不能抓住我哪里出错了。
尝试删除这一行
ping = ('ip', port, (error, reponse) =>{
并替换为
ping('ip', port, (error, reponse) =>{
第一个是将变量ping
设置为两个字符串'ip'
和port
,第三个是函数(error,response) =>{}
,第二个是使用ping
函数在你的代码上实际做一些事情