Discord bot commands not functioning properly

I’m working on a Discord bot and having trouble with some commands. The assistance command and cleanup command aren’t responding when I try to use them. Other commands like kick, ping, ban and echo are working fine though. I also want to add console logging whenever someone uses a command but I’m not sure how to implement that. Can anyone help me figure out what’s wrong?

bot.on("message", async msg => {
  // Handle all incoming messages
  
  // Skip messages from other bots
  if(msg.author.bot) return;
  
  // Only process messages that start with our prefix
  if(msg.content.indexOf(settings.prefix) !== 0) return;
  
  // Split the message into command and parameters
  const params = msg.content.slice(settings.prefix.length).trim().split(/ +/g);
  const cmd = params.shift().toLowerCase();
  
  if(cmd === "ping") {
    const response = await msg.channel.send("Checking...");
    response.edit(`Response time: ${response.createdTimestamp - msg.createdTimestamp}ms. WebSocket: ${Math.round(bot.ping)}ms`);
  }
  
  if(cmd === "echo") {
    const textToSend = params.join(" ");
    msg.delete().catch(err=>{}); 
    msg.channel.send(textToSend);
  }
  
  if(cmd === "kick") {
    let adminRole = msg.guild.roles.find("name", "[Admin]");
    if(msg.member.roles.has(adminRole.id)) { 
      let targetUser = msg.guild.member(msg.mentions.users.first());
      msg.guild.member(targetUser).kick();
      msg.channel.sendMessage("User has been kicked.");
    } else {
      return msg.reply("You don't have permission to kick users.");
    }
  }
  
  if(cmd === "ban") {
    let adminRole = msg.guild.roles.find("name", "[Admin]");
    if(msg.member.roles.has(adminRole.id)) { 
      let targetUser = msg.guild.member(msg.mentions.users.first());
      msg.guild.member(targetUser).ban();
      msg.channel.sendMessage("User has been banned.");
    } else {
      return msg.reply("You don't have permission to ban users.");
    }
  }
  
  if(cmd === "cleanup") {
    const messageCount = parseInt(params[0], 10);
    
    if(!messageCount || messageCount < 2 || messageCount > 100)
      return msg.reply("Please specify a number between 2 and 100 for messages to remove");
    
    const messages = await msg.channel.fetchMessages({count: messageCount});
    msg.channel.bulkDelete(messages)
      .catch(error => msg.reply(`Failed to delete messages: ${error}`));
  }
  
  if(cmd === "assistance") {
    msg.channel.send({embed: {
      color: 0x00AE86,
      author: {
        name: bot.user.username,
        icon_url: bot.user.avatarURL
      },
      title: "Command List",
      description: "Available bot commands and their usage",
      fields: [{
          name: "!assistance",
          value: "Shows this help menu (available to all users)"
        },
        {
          name: "!ping",
          value: "Displays bot response time and API latency"
        },
        {
          name: "!kick @user",
          value: "Removes a user from the server (Admin only)"
        },
        {
          name: "!ban @user",
          value: "Permanently bans a user (Admin only)"
        },
        {
          name: "!cleanup [number]",
          value: "Bulk deletes messages (currently not working)"
        }
      ],
      timestamp: new Date(),
      footer: {
        text: "Bot Support Team"
      }
    });
  }
});

Found the issue with your cleanup and assistance commands. They’re missing permission checks that your other admin commands have. For cleanup, you’re using fetchMessages() which is deprecated - switch to messages.fetch() instead. Also verify you’ve got the right permissions set up for message management.

For console logging, just add console.log(Command ${cmd} used by ${msg.author.tag}); right after you define the cmd variable. I had the same logging problem and this fixed it. The assistance command looks fine as written, but make sure your bot has embed permissions in whatever channel you’re testing.

Your cleanup command is probably failing because fetchMessages() got deprecated in newer Discord.js versions. Use messages.fetch({limit: messageCount}) instead. Also, your cleanup and assistance commands don’t have permission checks like your other admin commands do - that’s probably why they’re failing silently. For command logging, just add this after you define the cmd variable: console.log(${msg.author.tag} executed command: ${cmd}). It’ll log every command to your console. One more thing - your assistance command might break if the bot doesn’t have EMBED_LINKS permission in that channel. Test it somewhere the bot has full permissions first.

you’re using an old discord.js version - fetchMessages() was replaced with messages.fetch() ages ago. that’s why cleanup isn’t working. your assistance command should work fine, but check if the bot has embed permissions. for logging, just add console.log('command used:', cmd, 'by', msg.author.username); after you define cmd.