From 075c5aa3dc0946ea6ec93bc377ee4117201d0fac Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Wed, 12 Aug 2015 16:38:28 +0100 Subject: [PATCH] updated readme --- README.md | 54 +++++++++++++++++++++++++++--------------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index ecb5a65b8..587d0234a 100644 --- a/README.md +++ b/README.md @@ -10,38 +10,38 @@ The aim of this API is to make it *really* simple to start developing your bots. ### Example usage ```js -var Discord = require("discord.js"); +/* + * 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(); -myBot.login("discord email", "discord password", function(e) { +// Login with an example email and password +myBot.login( "hello@example.com", "password1" ); - if(e){ - console.log("Couldn't log in"); - return; - } - - myBot.on("disconnected", function() { - console.log("Disconnected!"); - process.exit(0); - }); - - myBot.on("ready", function(e) { - console.log("Ready to go!"); - }); - - myBot.on("message", function(message) { - - if(message.content === "Ping!"){ - - myBot.sendMessage(message.channel, "Pong!"); - - } - - } - -} +// The "ready" event is triggered after the bot successfully connected to +// Discord and is ready to send messages. +myBot.on( "ready", function() { + console.log( "Bot connected successfully." ); +} ); +// 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" ); + } +} ); ``` ### TODO * Documentation