Hey everyone, I’m in a bit of a pickle with my Discord bot. I was trying to add some cool new stuff, but it didn’t work out. So I got rid of the new code, but now my bot’s acting like a stubborn mule – it won’t respond to any commands! It’s still online, just totally ignoring everything. I’ve gone through my code but can’t spot the problem. I’m pretty new to this bot-coding thing, so I might be missing something obvious.
Here’s my main file:
const fs = require('fs');
const DiscordBot = require('discord.js');
const { commandPrefix, botToken } = require('./settings.json');
const bot = new DiscordBot.Client();
bot.actions = new DiscordBot.Collection();
const actionFiles = fs.readdirSync('./actions').filter(file => file.endsWith('.js'));
for (const file of actionFiles) {
const action = require(`./actions/${file}`);
bot.actions.set(action.trigger, action);
}
bot.once('ready', () => {
console.log('Bot is up and running!');
});
bot.on('message', msg => {
console.log(msg);
if (!msg.content.startsWith(commandPrefix) || msg.author.bot) return;
const params = msg.content.slice(commandPrefix.length).trim().split(/ +/);
const action = params.shift().toLowerCase();
if (!bot.actions.has(action)) return;
try {
bot.actions.get(action).run(msg, params);
} catch (err) {
console.error(err);
msg.reply('Oops! Something went wrong with that command!');
}
});
bot.login(botToken);
And here’s one of my action files:
function selectRandom(list) {
return list[Math.floor(Math.random() * list.length)];
}
module.exports = {
trigger: 'toss',
info: 'This command tosses an item!',
run(msg, params) {
const items = ['an apple', 'a watermelon', 'a carrot', 'an ice cube', 'a wrench', 'a laptop'];
msg.channel.send(
`${msg.author} tossed ${selectRandom(items)} at ${msg.mentions.users.first() ?? 'everyone'}!`
);
},
};
Any ideas what could be causing this?