Using Discord.JS instead of Discord.io

This commit is contained in:
Max Gorley 2020-03-14 10:03:58 -04:00 committed by GitHub
parent db6c8114cf
commit 3a1d214e84
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 731 additions and 268 deletions

View File

@ -1,60 +1,40 @@
var Discord = require('discord.io'); const Discord = require('discord.js');
var logger = require('winston'); const auth = require('./auth.json');
var auth = require('./auth.json');
// Configure logger settings
logger.remove(logger.transports.Console);
logger.add(new logger.transports.Console, {
colorize: true
});
logger.level = 'debug';
// Create bot object // Create bot object
var bot = new Discord.Client({ const bot = new Discord.Client({autoReconnect:true});
token: auth.token,
autorun: true
});
// Display console message when logged in // Display console message when logged in
bot.on('ready', function (evt) { bot.once('ready', () => {
logger.info('Connected'); console.log('Connected');
logger.info('Logged in as: ');
logger.info(bot.username + ' - (' + bot.id + ')');
}); });
bot.on('message', function (user, userID, channelID, message, evt) { bot.on('message', message => {
// Prefix is '!' // Prefix is '!'
if (message.substring(0, 1) == '!') { if (message.content.substring(0, 1) == '!') {
var args = message.substring(1).split(' '); var args = message.content.substring(1).split(' ');
var cmd = args[0]; var cmd = args[0];
args = args.splice(1); args = args.splice(1);
// Commands // Commands
switch(cmd) { switch(cmd) {
// !ping // !ping
case 'ping': case 'ping':
bot.sendMessage({ message.channel.send('Pong!');
to: channelID, break;
message: 'Pong!'
});
break;
// !help // !help
case 'help': case 'help':
bot.sendMessage({ message.channel.send('Commands:\n!help: Display this message\n!ping: Test if bot is alive\n!pi: Make O speak');
to: channelID, break;
message: 'Commands:\n!help: Display this message\n!ping: Test if bot is alive\n!pi: Make O speak'
});
break;
// !pi
case 'pi':
bot.sendMessage({
to: channelID,
message: 'Pipi? Pipi-pipipipipi!'
}) // !pi
case 'pi':
message.channel.send('Pipi? Pipi-pipipipipi!');
break; break;
// End of command list // End of command list
} }
} }
}); });
bot.login(auth.token);

925
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -5,7 +5,13 @@
"main": "o-bot.js", "main": "o-bot.js",
"author": "gizmo4487", "author": "gizmo4487",
"dependencies": { "dependencies": {
"discord.io": "https://github.com/woor/discord.io/tarball/gateway_v6", "bufferutil": "^4.0.1",
"winston": "^3.2.1" "discord.js": "^12.0.2",
"erlpack": "github:discordapp/erlpack",
"ffmpeg-static": "^3.0.0",
"install-peerdeps": "^2.0.1",
"install-peers": "^1.0.3",
"libsodium-wrappers": "^0.7.6",
"zlib-sync": "^0.1.6"
} }
} }