Add command helper
parent
860c793259
commit
f3c7c9a70a
17
index.js
17
index.js
|
@ -8,6 +8,7 @@ const sqlite = require('sqlite3');
|
||||||
|
|
||||||
let joinedVoiceChannels = [];
|
let joinedVoiceChannels = [];
|
||||||
let modules = [];
|
let modules = [];
|
||||||
|
let commandHandlers = new Map();
|
||||||
|
|
||||||
const bot = new Discord.Client();
|
const bot = new Discord.Client();
|
||||||
|
|
||||||
|
@ -56,6 +57,10 @@ const api = {
|
||||||
const conn = api.getConnectionForVoiceChannel(channel);
|
const conn = api.getConnectionForVoiceChannel(channel);
|
||||||
const filepath = await api.generateVoice(message);
|
const filepath = await api.generateVoice(message);
|
||||||
if (conn) conn.play(filepath);
|
if (conn) conn.play(filepath);
|
||||||
|
},
|
||||||
|
|
||||||
|
registerCommand: async (commandString, commandFunc) => {
|
||||||
|
commandHandlers.set(commandString, commandFunc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,5 +74,17 @@ function registerModules() {
|
||||||
modules.forEach((mod) => mod(bot, api));
|
modules.forEach((mod) => mod(bot, api));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleMessage(message) {
|
||||||
|
if (message.contents.startsWith(process.env.PREFIX)) {
|
||||||
|
const args = message.contents.split(" ");
|
||||||
|
const command = args[0].substr(1, args[0].length);
|
||||||
|
const execution = commandHandlers.get(command);
|
||||||
|
if (command) {
|
||||||
|
command(args, message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
registerModules();
|
registerModules();
|
||||||
bot.login(process.env.TOKEN);
|
bot.login(process.env.TOKEN);
|
||||||
|
bot.on('message', handleMessage);
|
Loading…
Reference in New Issue