I’m having a hard time with my Discord bot. I built a simple bot using a guide and it worked fine with basic commands. But when I tried to introduce extra commands, the bot completely stopped running. I ended up copying and pasting segments of code, and now it won’t start at all. Every time I run the bot, I encounter syntax errors that I just can’t seem to fix. I’ve spent hours tweaking the code with no success.
Below is a reworked version of my bot code:
const DiscordModule = require('discord-api');
const logger = require('logger-tool');
const settings = require('./settings.json');
logger.initialize({ level: 'info', color: true });
const bot = new DiscordModule.Bot({
token: settings.token,
autoConnect: true
});
bot.on('ready', () => {
logger.log(`Bot ${bot.username} is now online!`);
});
bot.on('message', message => {
if (message.content.startsWith('!')) {
const [command, ...params] = message.content.slice(1).split(' ');
switch (command) {
case 'greet':
message.reply('Hello!');
break;
case 'repeat':
message.channel.send(params.join(' '));
break;
// Additional commands can be added here
}
}
});
bot.connect();
Can anyone help me figure out why the syntax errors are occurring and how to fix them? I’m really stuck on this issue!