Discord.js-commando bot shows unknown command error but still executes clear function

I’m working on a Discord bot using Node.js and the discord.js-commando framework. When I type !clear command, the bot responds with “Unknown command, do !help to view a list of command” but then it actually deletes the messages anyway. So the functionality works correctly but it keeps showing that error message first. I can’t figure out why this happens. Can someone help me understand what’s going wrong?

const commando = require('discord.js-commando');
const client = new commando.Client();
const cmdPrefix = '!';

client.on('message', msg => {
    let content = msg.content.toUpperCase();
    let author = msg.author;
    let command = msg.content.slice(cmdPrefix.length).split(" ");
    let parameters = command.slice(1);
    
    if (content.startsWith(cmdPrefix + 'CLEAR')) {
        async function deleteMessages() {
            msg.delete();
            
            if (isNaN(parameters[0])) {
                msg.channel.send('Please provide a valid number of messages to delete \n Usage: ' + cmdPrefix + 'clear <count>');
                return;
            }
            
            const messageList = await msg.channel.fetchMessages({limit: parameters[0]});
            console.log(messageList.size + ' messages located, removing...');
            
            msg.channel.bulkDelete(messageList)
                .catch(err => msg.channel.send(`Error occurred: ${err}`));
        }
        deleteMessages();
    }
});

client.login('BOT TOKEN GOES HERE');

yep, that’s a common issue. commando is checking for cmd first, and since it don’t find it, it gives that error. But you’re right, the delete still works. maybe just go full manual and drop commando if ur not using its feaures.

You’re running both Discord.js-commando and a raw message listener at the same time. When you type !clear, commando looks for that command first, can’t find it, and throws the “unknown command” error. Then your manual handler kicks in as backup. Pick one approach - either register your clear command properly with client.registry.registerCommand() or ditch commando entirely and stick with your original setup.