問題描述
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);
它是否顯示任何錯誤.它只是在發(fā)出命令時沒有響應(yīng).請告訴我的代碼有什么問題..并請告訴我如何糾正它.如果我將 'messageCreate'
替換為 'message'
,機(jī)器人在發(fā)出命令時做出響應(yīng),但顯示錯誤消息(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 :(
對這個問題的一些回復(fù)建議我替換行"ping = ('ip', port, (error, reponse) =>{
" with "ping('ip', port, error, response) =>{
"但隨后它給出了錯誤 ping is not a function
.根據(jù)一些建議,我意識到RichEmbed()
"已在 discord v12 中刪除,所以我嘗試用 const Embed = new MessageEmbed()
替換行 const Embed = new RichEmbed()
但不幸的是這也沒有幫助.但是機(jī)器人沒有響應(yīng)時命令已發(fā)出.問題是,它也沒有顯示任何錯誤消息,所以我無法捕捉到我出錯的地方.
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
設(shè)置為兩個字符串 'ip'
和 port
,第三個是函數(shù) (error,response) =>{}
,第二個是使用 ping
函數(shù)對你的代碼進(jìn)行實際操作
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
這篇關(guān)于我正在嘗試編寫一個顯示我的我的世界服務(wù)器狀態(tài)的不和諧機(jī)器人,但機(jī)器人沒有響應(yīng)命令,即使出現(xiàn)錯誤的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!