Bot commands not responding in server despite no console errors

I’m building a Discord bot using discord.js that should automatically assign roles to members. The bot reads its prefix from a configuration file but the commands aren’t responding when I test them in my server.

main.js

const { Client, Intents, EmbedBuilder } = require("discord.js");
const database = require("quick.db");
const settings = require("./settings.json");

const bot = new Client({ intents: 32767 });

bot.once("ready", () => {
  console.log("Bot is running!");
});

bot.runCommand = async function (bot, msg, parameters, cmdPrefix) {
  const commandFile = require(`./commands/rolemanager`);
  commandFile.run(bot, msg, parameters, cmdPrefix);
};

bot.login(settings.botToken);

rolemanager.js

const { EmbedBuilder } = require("discord.js");
const database = require("quick.db");

module.exports = {
  commandName: "setrole",
  shortcuts: ["sr"],
  info: "Configure automatic role assignment.",
  run(bot, msg, parameters, cmdPrefix) {
    if (!msg.member.permissions.has("Administrator")) {
      const errorEmbed = new EmbedBuilder()
        .setColor("#Red")
        .setTitle("🚫 Access Denied 🚫")
        .setDescription("You need administrator permissions for this command.")
        .setTimestamp();
      return msg.channel.send({ embeds: [errorEmbed] });
    }

    const operation = parameters[0];
    const targetRole = msg.mentions.roles.first() || 
      msg.guild.roles.cache.find(r => r.name === parameters[1]);

    if (!operation || !targetRole) {
      const usageEmbed = new EmbedBuilder()
        .setColor("#Red")
        .setTitle("🚫 Wrong Format 🚫")
        .setDescription(`Use: \`${cmdPrefix}setrole create/delete @role\``);
      return msg.channel.send({ embeds: [usageEmbed] });
    }

    if (operation === "create") {
      database.set(`role_${msg.guildId}`, targetRole.id);
      const successEmbed = new EmbedBuilder()
        .setColor("#Green")
        .setTitle("✅ Role Configuration Updated ✅")
        .setDescription(`Auto role \`${targetRole.name}\` has been configured.`);
      return msg.channel.send({ embeds: [successEmbed] });
    }
  }
};

settings.json

{
  "botToken": "your-token-here",
  "cmdPrefix": "!"
}

The bot shows as online but when I type commands in the server nothing happens. No error messages appear in the console either. What could be causing this issue?

dude you’re missing the messageCreate event listener completely. your bot can see messages but has no way to process them or trigger commands. add bot.on('messageCreate', msg => { /* command handling logic */ }) to actually listen for messages and parse commands.

Your bot is missing the key piece - there’s no event handler to catch messages and run commands. You’ve got the runCommand method defined, but nothing’s actually calling it when someone types a message. You need a messageCreate event that grabs messages starting with your prefix, pulls out the command name and parameters, then fires off your runCommand function. Also double-check your bot’s permissions in the server - it needs Read Messages, Send Messages, and Use External Emojis for those embeds to show up right. Your intents look good, but without that message event handler, your command system’s just sitting there doing nothing.

Your main.js file is missing message event handling. You’ve got the runCommand function defined, but nothing’s calling it when users send messages. You need to add a messageCreate event listener that checks if messages start with your prefix, grabs the command name, and calls runCommand. Without this listener, your bot gets messages but can’t detect commands or run your rolemanager module. Also double-check that your bot has permissions to read messages and send embeds in the server.

This topic was automatically closed 4 days after the last reply. New replies are no longer allowed.