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');
var logger = require('winston');
var auth = require('./auth.json');
// Configure logger settings
logger.remove(logger.transports.Console);
logger.add(new logger.transports.Console, {
colorize: true
});
logger.level = 'debug';
const Discord = require('discord.js');
const auth = require('./auth.json');
// Create bot object
var bot = new Discord.Client({
token: auth.token,
autorun: true
});
const bot = new Discord.Client({autoReconnect:true});
// Display console message when logged in
bot.on('ready', function (evt) {
logger.info('Connected');
logger.info('Logged in as: ');
logger.info(bot.username + ' - (' + bot.id + ')');
bot.once('ready', () => {
console.log('Connected');
});
bot.on('message', function (user, userID, channelID, message, evt) {
bot.on('message', message => {
// Prefix is '!'
if (message.substring(0, 1) == '!') {
var args = message.substring(1).split(' ');
if (message.content.substring(0, 1) == '!') {
var args = message.content.substring(1).split(' ');
var cmd = args[0];
args = args.splice(1);
// Commands
switch(cmd) {
// !ping
case 'ping':
bot.sendMessage({
to: channelID,
message: 'Pong!'
});
break;
// !ping
case 'ping':
message.channel.send('Pong!');
break;
// !help
case 'help':
bot.sendMessage({
to: channelID,
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!'
// !help
case 'help':
message.channel.send('Commands:\n!help: Display this message\n!ping: Test if bot is alive\n!pi: Make O speak');
break;
})
// !pi
case 'pi':
message.channel.send('Pipi? Pipi-pipipipipi!');
break;
// 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",
"author": "gizmo4487",
"dependencies": {
"discord.io": "https://github.com/woor/discord.io/tarball/gateway_v6",
"winston": "^3.2.1"
"bufferutil": "^4.0.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"
}
}