diff --git a/examples/avatar.js b/examples/avatar.js new file mode 100644 index 000000000..b0eb1bb27 --- /dev/null +++ b/examples/avatar.js @@ -0,0 +1,41 @@ +/* + this bot is an avatar bot, and will give a user their avatar's URL +*/ + +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 === "$avatar") { + + //see if the user has an avatar + if( msg.sender.avatarURL ){ + bot.reply(msg, msg.sender.avatarURL); + }else{ + //using reply with a message automatically does: + // '@sender, ' for you! + bot.reply(msg, "you don't have an avatar!"); + } + + //alert the console + console.log("served " + msg.sender.username); + + } +}); + +bot.login(AuthDetails.email, AuthDetails.password); \ No newline at end of file diff --git a/examples/catapi.js b/examples/catapi.js new file mode 100644 index 000000000..ae5b7f6aa --- /dev/null +++ b/examples/catapi.js @@ -0,0 +1,36 @@ +/* + this bot will send an image of a cat to a channel. + may be slow depending on your internet connection. +*/ + +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 === "$cat") { + + //send a message to the channel the ping message was sent in. + bot.sendMessage(msg.channel, "pong!"); + + //alert the console + console.log("pong-ed " + msg.sender.username); + + } +}); + +bot.login(AuthDetails.email, AuthDetails.password); \ No newline at end of file diff --git a/examples/pingpong.js b/examples/pingpong.js index 5a9ddc9ec..d5d90588f 100644 --- a/examples/pingpong.js +++ b/examples/pingpong.js @@ -11,23 +11,26 @@ var AuthDetails = require("./auth.json"); var bot = new Discord.Client(); -bot.on("ready", function(){ +bot.on("ready", function () { console.log("Ready to begin! Serving in " + bot.channels.length + " channels"); }); -bot.on("disconnected", function(){ - +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"){ +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.sendMessage(msg.channel, "pong!"); + //alert the console + console.log("pong-ed " + msg.sender.username); + } });