我正在尝试编写一个显示我的我的世界服务器状态的不和谐机器人,但机器人没有响应命令,即使出现错误
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);
它是否显示任何错误.它只是在发出命令时没有响应.请告诉我的代码有什么问题..并请告诉我如何纠正它.如果我将 'messageCreate'
替换为 'message'
,机器人在发出命令时做出响应,但显示错误消息(node:25372) DeprecationWarning: The message event is deprecated. Use messageCreate instead
".请帮忙我:(
Niether is it showing any error. Its just not responding when the command is being issued. Please tell whats wrong with my code.. and please tell how I can correct it. in the line, "bot.on('messageCreate', message =>{...
" if i am replacing 'messageCreate'
with 'message'
, the bot is responding on issuing the command, but with an error message saying ' (node:25372) DeprecationWarning: The message event is deprecated. Use messageCreate instead
'. Please help me :(
对这个问题的一些回复建议我替换行"ping = ('ip', port, (error, reponse) =>{
" with "ping('ip', port, error, response) =>{
"但随后它给出了错误 ping is not a function
.根据一些建议,我意识到RichEmbed()
"已在 discord v12 中删除,所以我尝试用 const Embed = new MessageEmbed()
替换行 const Embed = new RichEmbed()
但不幸的是这也没有帮助.但是机器人没有响应时命令已发出.问题是,它也没有显示任何错误消息,所以我无法捕捉到我出错的地方.
Some replies to this question suggested me to replace the line " ping = ('ip', port, (error, reponse) =>{
" with "ping('ip', port, error, response) =>{
" but then it gives the error ping is not a function
. On some suggestions i realised that "RichEmbed()
" was removed in discord v12, so i tried replacing the line const Embed = new RichEmbed()
with const Embed = new MessageEmbed()
but unfortunately that also did not help. Yet the bot did not respond when the command was issued. The thing is, it also does not show any error message, so i am not able to catch where i have gone wrong.
推荐答案
试试去掉这行
ping = ('ip', port, (error, reponse) =>{
并将其替换为
ping('ip', port, (error, reponse) =>{
第一个是将变量 ping
设置为两个字符串 'ip'
和 port
,第三个是函数 (error,response) =>{}
,第二个是使用 ping
函数对你的代码进行实际操作
The first one is setting a variable ping
to be two strings 'ip'
and port
and a third one who is a function (error,response) =>{}
, the second one is using the ping
function to actually do something on your code
相关文章