From babf550459cf104f9a347deb43dec421de45b04e Mon Sep 17 00:00:00 2001 From: Gus Caplan Date: Tue, 26 Jul 2016 09:38:01 -0500 Subject: [PATCH] Add tonicdev support (#479) * example file for tonicdev * add tonicdev to the package.json * meh --- examples/tonicdev.js | 31 +++++++++++++++++++++++++++++++ package.json | 3 ++- 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 examples/tonicdev.js diff --git a/examples/tonicdev.js b/examples/tonicdev.js new file mode 100644 index 000000000..83fe65b3f --- /dev/null +++ b/examples/tonicdev.js @@ -0,0 +1,31 @@ +var Discord = require('discord.js'); + +const token = ''; // token for bot login + +//when the bot is ready +bot.on("ready", () => { + console.log(`Ready to begin! Serving in ${bot.channels.length} channels`); +}); + +//when the bot disconnects +bot.on("disconnected", () => { + //alert the console + console.log("Disconnected!"); + + //exit node.js with an error + process.exit(1); +}); + +//when the bot receives a message +bot.on("message", msg => { + //if message begins with "ping" + if (msg.content.startsWith("ping")) { + //send a message to the channel the ping message was sent in. + bot.sendMessage(msg, "pong!"); + + //alert the console + console.log("pong-ed " + msg.author.username); + } +}); + +bot.loginWithToken(token); diff --git a/package.json b/package.json index 6521ba9a1..cf18ea5b6 100644 --- a/package.json +++ b/package.json @@ -49,5 +49,6 @@ "browser": { "./src/Util/TokenCacher.js": "./src/Util/TokenCacher-shim.js", "./lib/Util/TokenCacher.js": "./lib/Util/TokenCacher-shim.js" - } + }, + "tonicExampleFilename": "./examples/tonicdev.js" }