Created
June 22, 2016 00:15
-
-
Save CWFranklin/c959a421f0019d8523e3b1ebff045611 to your computer and use it in GitHub Desktop.
Simple score counter for Discord API running in NodeJS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var discord = require('discord.js'); | |
var prefix = '!'; | |
var status = []; | |
var bot = new discord.Client({ | |
autoReconnect: true | |
}); | |
bot.on('message', function(msg) { | |
if (msg.author === bot.user) return; | |
var cmd = ''; | |
var channelId = msg.channel.id; | |
if (msg.content.indexOf(prefix) == 0) { | |
cmd = msg.content.substring(1); | |
} else { | |
return; | |
} | |
switch (cmd) { | |
case 'reset': | |
if (status[channelId]) { | |
status[channelId] = []; | |
} | |
bot.sendMessage(msg.channel, 'Scores reset.'); | |
return; | |
//break; | |
default: | |
if (!status[channelId]) { | |
status[channelId] = []; | |
} | |
if (!status[channelId][cmd]) { | |
status[channelId][cmd] = 0; | |
} | |
status[channelId][cmd]++; | |
} | |
var output = ''; | |
for (var team in status[channelId]) { | |
output += team + ': ' + status[channelId][team] + ', '; | |
} | |
bot.sendMessage(msg.channel, output); | |
}); | |
bot.loginWithToken( | |
'BOT TOKEN', | |
function(error) { | |
if (error) console.log(error); | |
} | |
); | |
bot.on('ready', function() { | |
console.log('Bot Serving. Setting status...'); | |
bot.setStatus('online', 'Love Games', function(err) { | |
if (err) console.log(err); | |
console.log('Status set.'); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment