I am trying to code a discord bot that shows the status of my minecraft server but The bot isn#39;t responding to the command not even with an error(我正在尝试编写一个显示我的我的世界服务器状态的不和谐机器人,但机器人没有响应命令,即使出现错误) - IT屋-程序员软件开发技
问题描述
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
这篇关于我正在尝试编写一个显示我的我的世界服务器状态的不和谐机器人,但机器人没有响应命令,即使出现错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:我正在尝试编写一个显示我的我的世界服务器状
基础教程推荐
- 如何在特定日期之前获取消息? 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
