mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-17 03:53:29 +01:00
ping pong example
This commit is contained in:
@@ -1,6 +1,4 @@
|
|||||||
{
|
{
|
||||||
//this is an authentication file used for the examples,
|
"email" : "your discord email here",
|
||||||
//just add your email and password and the examples should work!
|
"password" : "your discord password here"
|
||||||
"email" : "discord@js.com",
|
|
||||||
"password" : "my discord password"
|
|
||||||
}
|
}
|
||||||
34
examples/pingpong.js
Normal file
34
examples/pingpong.js
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
this bot is a ping pong bot, and every time a message
|
||||||
|
beginning with "ping" is sent, it will reply with
|
||||||
|
"pong".
|
||||||
|
*/
|
||||||
|
|
||||||
|
var Discord = require("../");
|
||||||
|
|
||||||
|
// Get the email and password
|
||||||
|
var AuthDetails = require("./auth.json");
|
||||||
|
|
||||||
|
var bot = new Discord.Client();
|
||||||
|
|
||||||
|
bot.on("ready", function(){
|
||||||
|
console.log("Ready to begin! Serving in " + bot.channels.length + " channels");
|
||||||
|
});
|
||||||
|
|
||||||
|
bot.on("disconnected", function(){
|
||||||
|
|
||||||
|
console.log("Disconnected!");
|
||||||
|
process.exit(1); //exit node.js with an error
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
bot.on("message", function(msg){
|
||||||
|
if(msg.content.substring(0,4) === "ping"){
|
||||||
|
|
||||||
|
//send a message to the channel the ping message was sent in.
|
||||||
|
bot.sendMessage( msg.channel, "pong!" );
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
bot.login(AuthDetails.email, AuthDetails.password);
|
||||||
Reference in New Issue
Block a user