From 9f049e5e18a01288d269c31567b0f553699768b7 Mon Sep 17 00:00:00 2001 From: meew0 Date: Wed, 12 Aug 2015 13:17:36 +0200 Subject: [PATCH] Add comments to pingpong.js --- examples/pingpong.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/examples/pingpong.js b/examples/pingpong.js index a832a8f62..57d45dc42 100644 --- a/examples/pingpong.js +++ b/examples/pingpong.js @@ -1,10 +1,26 @@ +/* + * A basic bot that shows how to connect to a Discord account, + * how to listen to messages and how to send messages. + * + * This bot responds to every "ping" message with a "pong". + */ + var Discord = require( "discord.js" ); + +// Create the bot var myBot = new Discord.Client(); +// Login with an example email and password myBot.login( "hello@example.com", "password1" ); +// Add a listener to the "message" event, which triggers upon receiving +// any message myBot.on( "message", function( message ) { + // message.content accesses the content of the message as a string. + // If it is equal to "ping", then the bot should respond with "pong". if ( message.content === "ping" ) { + // Send a message ("pong") to the channel the message was sent in, + // which is accessed by message.channel. this.sendMessage( message.channel, "pong" ); } } );