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);
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 :(
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.
Try removing this line
ping = ('ip', port, (error, reponse) =>{
and replacing it with
ping('ip', port, (error, reponse) =>{
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