updated readme

This commit is contained in:
hydrabolt
2015-08-12 16:38:28 +01:00
parent c57895e358
commit 075c5aa3dc

View File

@@ -10,38 +10,38 @@ The aim of this API is to make it *really* simple to start developing your bots.
### Example usage ### Example usage
```js ```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" ); var Discord = require( "discord.js" );
// Create the bot
var myBot = new Discord.Client(); 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){ // The "ready" event is triggered after the bot successfully connected to
console.log("Couldn't log in"); // Discord and is ready to send messages.
return; myBot.on( "ready", function() {
} console.log( "Bot connected successfully." );
myBot.on("disconnected", function() {
console.log("Disconnected!");
process.exit(0);
});
myBot.on("ready", function(e) {
console.log("Ready to go!");
} ); } );
// Add a listener to the "message" event, which triggers upon receiving
// any message
myBot.on( "message", function( message ) { myBot.on( "message", function( message ) {
// message.content accesses the content of the message as a string.
if(message.content === "Ping!"){ // If it is equal to "ping", then the bot should respond with "pong".
if ( message.content === "ping" ) {
myBot.sendMessage(message.channel, "Pong!"); // Send a message ("pong") to the channel the message was sent in,
// which is accessed by message.channel.
this.sendMessage( message.channel, "pong" );
} }
} );
}
}
``` ```
### TODO ### TODO
* Documentation * Documentation