Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var Discord = require('discord.io');
- var mysql = require('mysql');
- var auth = require('./auth.json');
- var bot = new Discord.Client({
- token: auth.token,
- autorun: true
- });
- var connection = mysql.createConnection({
- host: 'localhost',
- user: 'advil0',
- password: '#####',
- database: 'discord_bot'
- });
- connection.connect();
- bot.on('ready', function (evt) {
- console.log('Connected');
- console.log('Logged in as: ');
- console.log(bot.username + ' - (' + bot.id + ')');
- });
- bot.on('message', function (user, userID, channelID, message, evt) {
- if(message.substring(0, 1) == '!') {
- console.log('Incoming command: ' + message);
- var args = message.substring(1).split(' ');
- var cmd = args[0];
- if(cmd == 'help')
- {
- var helpMsg = 'List of commands: ';
- var index = 0;
- connection.query('SELECT command FROM commands', function(error, results, fields) {
- for(index = 0; index < results.length; ++index) {
- helpMsg += `!${results[index].command.toLowerCase()} `;
- }
- bot.sendMessage({
- to: channelID,
- message: helpMsg
- });
- });
- }
- else {
- connection.query('SELECT response FROM commands WHERE command = ?', [cmd.toLowerCase()], function(error, results, fields) {
- bot.sendMessage({
- to: channelID,
- message: results[0].response
- });
- });
- }
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement