Reputation: 21
I've followed this tutorial.
I've got 3 files :
package.json
{
"name": "greeter-bot",
"version": "1.0.0",
"description": "My own Discord bot",
"main": "bot.js",
"author": "YOUR-NAME-HERE",
"dependencies": {}
}
auth.json
{
"token": "Abcde123blahblah"
}
bot.js
var Discord = require('discord.io');
var logger = require('winston');
var auth = require('./auth.json');
// Configure logger settings
logger.remove(logger.transports.Console);
logger.add(logger.transports.Console, {
colorize: true
});
logger.level = 'debug';
// Initialize Discord Bot
var bot = new Discord.Client({
token: auth.token,
autorun: true
});
bot.on('ready', function (evt) {
logger.info('Connected');
logger.info('Logged in as: ');
logger.info(bot.username + ' - (' + bot.id + ')');
});
bot.on('message', function (user, userID, channelID, message, evt) {
// Our bot needs to know if it will execute a command
// It will listen for messages that will start with `!`
if (message.substring(0, 1) == '!') {
var args = message.substring(1).split(' ');
var cmd = args[0];
args = args.splice(1);
switch(cmd) {
// !ping
case 'ping':
bot.sendMessage({
to: channelID,
message: 'Pong!'
});
break;
// Just add any case commands if you want to..
}
}
});
Installed dependencies :
npm install discord.io winston --save
Finally, using
node bot.js
should run my bot, if I understand correctly. Sadly it remains offline on the server. Anything I missed ?
Thanks !
Upvotes: 1
Views: 19609
Reputation: 2189
I think you missed this part of the tutorial where it shows you how to get your token in auth.json
(under the auth.json
section). 'YOUR-BOT-TOKEN'
is not going to work.
-----> guide
EDIT: Also, the OP needed these additional dependencies to get the above code from the tutorial to work (see this github discussion):
npm install discord.io github:woor/discord.io#gateway_v6 winston --save
Upvotes: 4