'Why is my discord bot not starting after I try and add a new command?
I'm trying to make a bot that has very basic commands, I followed a guide online but it wasn't clear about how to add more commands, so I tried copy pasting some things around, but it just would not even remotely work.
Not too sure what's going on here, I tried messing around with the code to no avail, every time I try and run it, it just spews out errors such as syntax errors:
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';
// 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!'
switch(cmd) {
// ;test
case 'test':
bot.sendMessage({
to: channelID,
message: 'test!'
break;
// Just add any case commands if you want to..
}
}
});
Solution 1:[1]
You did not include any errors. We can't help you solve your error without the logs.
From what I have and my past experience. I would call ready with once() and not on(). Second thing, if I remember correctly, the on("message") event only references Message and not everything you put in your functions. Start by fixing all of this, including an error log, and maybe someone will be able to help you :)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | loom |
