Skip to content

Instantly share code, notes, and snippets.

@meew0
Created February 23, 2016 16:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save meew0/94dcd2c0f3c7a822c444 to your computer and use it in GitHub Desktop.
Save meew0/94dcd2c0f3c7a822c444 to your computer and use it in GitHub Desktop.
The ping pong example from discord.js, fixed up slightly
/*
this bot is a ping pong bot, and every time a message
beginning with "ping" is sent, it will reply with
"pong!".
*/
// Load discord.js
var Discord = require("discord.js");
// Create a client
var bot = new Discord.Client();
// This code will run once the bot has started up.
bot.on("ready", function () {
console.log("Ready to begin! Serving in " + bot.channels.length + " channels");
});
// This code will run once the bot has disconnected from Discord.
bot.on("disconnected", function () {
// alert the console
console.log("Disconnected!");
// exit node.js with an error
process.exit(1);
});
// This code will run once the bot receives any message.
bot.on("message", function (msg) {
// if message begins with "ping"
if (msg.content.indexOf("ping") === 0) {
// send a message to the channel the ping message was sent in.
bot.sendMessage(msg.channel, "pong!");
// alert the console
console.log("pong-ed " + msg.author.username);
}
});
// Login (replace these auth details with your bot's)
bot.login("email@example.com", "hunter2");
@Porbei
Copy link

Porbei commented Oct 4, 2020

With the bot.login part at the end, what should I put in there? The bot client ID and token? Thanks for making this though!

@Galaxy-Coding
Copy link

@Porbei token

@jsinc-sebastian
Copy link

In the last Line bot.Login, dies it be email and bot client secret?

@UjanRoy
Copy link

UjanRoy commented Nov 1, 2021

With the bot.login part at the end, what should I put in there? The bot client ID and token? Thanks for making this though!

You have to put bot.login("your bot's token");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment