簡體   English   中英

我的 Discord 機器人在顯示服務器時出現錯誤

[英]My Discord bot get error to showing servers

你好,我想讓我的 discordbot 顯示我的 mc 服務器

我試試這個代碼:

 const {Client, RichEmbed } = require('discord.js') const bot = new Client() const ping = require('minecraft-server-util') const token = 'tokenid' const PREFIX = '.' bot,on('ready'. () =>{ console.log('Bot has come online.') }) bot,on('message'. message =>{ if (message,content === 'dnm') { ping('hypixel.net', 25565, (error. reponse) =>{ if(error) throw error const Embed = new Discord.MessageEmbed().setTitle('Sunucu Bilgileri'),addField('Sunucu ip'. reponse.host),addField('Sunucu Versiyonu'. reponse.version),addField('online oyuncu'. reponse.onlinePlayers),addField('Maksimun Oyuncu'. reponse.maxPlayers) message.channel.send(Embed)
    })
}     
 } }) bot.login(token)

但我得到這個錯誤

**

(node:13980) UnhandledPromiseRejectionWarning: TypeError: RichEmbed is not a constructor 在 D:\Discordbot\MCBOT\bas.js:27:31 在 D:\Discordbot\MCBOT\node_modules\minecraft-server-util\src\ 處enter code here index.js:137:23 at processTicksAndRejections (internal/process/task_queues.js:97:5) (node:13980) UnhandledPromiseRejectionWarning: 未處理的 promise 拒絕。 此錯誤源於在沒有 catch 塊的情況下拋出異步 function 內部,或拒絕未使用.catch() 處理的 promise。 要終止未處理的 promise 拒絕的節點進程,請使用 CLI 標志--unhandled-rejections=strict (請參閱https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode )。 (拒絕 ID:1)(節點:13980)[DEP0018] DeprecationWarning:不推薦使用未處理的 promise 拒絕。 將來,未處理的 promise 拒絕將使用非零退出代碼終止 Node.js 進程。

**

在 Discord.js v12 上,刪除了RichEmbed以支持MessageEmbed 幾乎你所要做的就是在代碼中的任何地方用MessageEmbed替換RichEmbed ,就像我在下面所做的那樣:

const {Client, MessageEmbed} = require('discord.js')
 
const bot = new Client()
 
const ping = require('minecraft-server-util')
 
const token = 'tokenid'
 
const PREFIX = '!'
 
bot.on('ready', () =>{
    console.log('Bot has come online.')
})
 
bot.on('message', message =>{
 
    let args = message.content.substring(PREFIX.length).split(' ')
 
    switch(args[0]){
        case 'mc':
 
            if(!args[1]) return message.channel.send('You must type a minecraft server ip')
            if(!args[2]) return message.channel.send('You must type a minecraft server port')
 
            ping(args[1], parseInt(args[2]), (error, reponse) =>{
                if(error) throw error
                const Embed = new MessageEmbed()
                .setTitle('Server Status')
                .addField('Server IP', reponse.host)
                .addField('Server Version', reponse.version)
                .addField('Online Players', reponse.onlinePlayers)
                .addField('Max Players', reponse.maxPlayers)
               
                message.channel.send(Embed)
            })
        break;
    }
})
 
bot.login(token)

我希望這有幫助!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM