discord.js example bot
Example 1: discord.js example
const Discord = require('discord.js');
const client = new Discord.Client();
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
client.on('message', msg => {
if (msg.content === 'ping') {
msg.reply('Pong!');
}
});
client.login('token');
Example 2: discord js ping command
if(cmd === `${prefix}ping `) {
message.channel.send("Pinging...").then(m =>{
var ping = m.createdTimestamp - message.createdTimestamp;
var embed = new Discord.MessageEmbed()
.setAuthor(`Your ping is ${ping}`)
.setColor("Your Color")
m.edit(embed)
});
}
Example 3: Bots latency discord js
var yourping = new Date().getTime() - message.createdTimestamp
var botping = Math.round(bot.ws.ping)
message.channel.send(`Your ping: ${yourping} \nBots ping: ${botping}`)