The issue seems to stem from using ‘userInput’ without proper context. In Discord.js, you typically work with a ‘message’ object. Try refactoring your code to use the ‘message’ event:
bot.on(‘message’, message => {
if (!message.content.startsWith(cmdPrefix) || message.author.bot) return;
if (command === ‘clean’) {
bot.commands.get(‘clean’).run(message, args);
}
});
This approach should resolve your reference error and provide the necessary context for your commands. Remember to adjust your command files accordingly to accept ‘message’ as the first parameter.
I’ve encountered similar issues when working on Discord bots. The problem seems to be in how the message event is handled. Instead of relying on ‘userInput’, try using the actual ‘message’ object from the event listener. For instance, you can modify your code like this:
bot.on(‘message’, message => {
if (!message.content.startsWith(cmdPrefix) || message.author.bot) return;
if (command === ‘clean’) {
bot.commands.get(‘clean’).execute(message, args);
}
});
Ensure your command files are updated to use ‘execute’ and accept the ‘message’ object as the first parameter. This adjustment should resolve the reference error and get your bot working correctly.