【问题标题】:I am trying to code a discord bot that shows the status of my minecraft server but The bot isn't responding to the command not even with an error我正在尝试编写一个显示我的我的世界服务器状态的不和谐机器人,但机器人没有响应命令,即使出现错误
【发布时间】:2021-12-08 11:42:11
【问题描述】:
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 =>{...”行中,如果我将'messageCreate' 替换为'message',则机器人会在发出命令时做出响应,但会显示错误消息“(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(),但不幸的是这也没有帮助。然而,当命令发出时,机器人没有响应。问题是,它也没有显示任何错误消息,所以我无法找到我出错的地方。

【问题讨论】:

标签: javascript discord.js minecraft


【解决方案1】:

尝试删除此行

            ping = ('ip', port, (error, reponse) =>{

并将其替换为

            ping('ip', port, (error, reponse) =>{

第一个是将变量ping 设置为两个字符串'ip'port,第三个是函数(error,response) =>{},第二个是使用ping 函数来实际执行某些操作在你的代码上

【讨论】:

    猜你喜欢
    • 2022-11-15
    • 1970-01-01
    • 2021-11-21
    • 2021-12-03
    • 2021-05-03
    • 2021-11-04
    • 2022-12-15
    相关资源
    最近更新 更多