From d4cd1ec6f82118b0162105d7f743e520c36af38b Mon Sep 17 00:00:00 2001 From: meew0 Date: Wed, 12 Aug 2015 13:30:46 +0200 Subject: [PATCH] Add an example that shows the bot status events --- examples/status.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 examples/status.js diff --git a/examples/status.js b/examples/status.js new file mode 100644 index 000000000..a54814b01 --- /dev/null +++ b/examples/status.js @@ -0,0 +1,24 @@ +/* + * A bot that doesn't interact with Discord, but instead shows how to listen + * to the "ready" and "disconnected" events, that are triggered when the bot + * starts up or shuts down, respectively. + */ + +var Discord = require( "discord.js" ); +var myBot = new Discord.Client(); + +myBot.login( "hello@example.com", "password1" ); + +// 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." ); +} ); + +// The "disconnected" event is triggered after the connection to Discord +// ended. +// It is also triggered when the connection attempt fails, for example due +// to a wrong password. +myBot.on( "disconnected", function() { + console.log( "Bot disconnected from Discord." ); +} );