Skip to content

Instantly share code, notes, and snippets.

@msmoode
Created December 23, 2015 22:09
Show Gist options
  • Save msmoode/cc73d28f3874cd9026d7 to your computer and use it in GitHub Desktop.
Save msmoode/cc73d28f3874cd9026d7 to your computer and use it in GitHub Desktop.
tiny discord bot + example implementation
import {Bot, Command} from './bot.js';
var artemis = new Bot("username", "password");
class TestCommand extends Command {
constructor() {
super("ping")
}
run(user, channel, message) {
artemis.client.sendMessage({to: channel, message: "pong"});
}
}
artemis.addCommand(new TestCommand());
artemis.client.connect();
import Discord from 'discord.io';
class Bot {
constructor(email, password) {
var commands = {};
this.commands = commands;
var client = new Discord({
email: email,
password: password
});
this.client = client;
this.client.on('message', function(user, userID, channelID, message, rawEvent) {
if (!message.startsWith("!")) return;
for (let command in commands) {
if (message.toLowerCase().startsWith("!" + command)) {
commands[command].run(user, channelID, client.fixMessage(message));
}
}
});
}
addCommand(command) {
this.commands[command.name.toLowerCase()] = command;
}
}
class Command {
constructor(name) {
this.name = name;
}
run(user, channel, message) {
}
}
export {Bot, Command};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment