Bot Not Responding to Commands

When your bot appears online in Discord but does not respond to commands, there are several potential causes to investigate. This is one of the most frequently reported issues and usually has a straightforward solution.

The most common reason a bot stops responding to message-based commands is the Message Content intent. Discord made this a privileged intent, which means it must be explicitly enabled in both the Discord Developer Portal and your bot code. Without this intent, your bot receives message events but the message content field is empty, so command matching fails silently.

To fix this, visit the Discord Developer Portal, navigate to your application, go to the Bot section, and scroll down to the Privileged Gateway Intents section. Ensure that "Message Content Intent" is toggled on. Then verify that your bot code includes the MessageContent intent in its client configuration:

const client = new Client({
    intents: [
        GatewayIntentBits.Guilds,
        GatewayIntentBits.GuildMessages,
        GatewayIntentBits.MessageContent, // Required for reading message text
    ],
});

Another common cause is the bot responding only in certain channels due to permission restrictions. Check that the bot has the "View Channel" and "Send Messages" permissions in the channel where you are testing. You can verify this by checking the channel permission overwrites in your Discord server settings.

If your bot uses slash commands rather than message-based commands, ensure that the commands have been registered with Discord. Slash commands require a separate registration step where you submit your command definitions to the Discord API. If commands were registered to a specific guild for testing, they will not appear in other servers. Global commands can take up to an hour to propagate across all servers.

Finally, check your bot console output for any error messages. Many issues that cause a bot to stop responding produce error output that indicates exactly what went wrong. If you are using MonkeyBytes Hosting, you can view the console output directly in the server dashboard.

Invalid Token Errors

An invalid token error occurs when your bot attempts to connect to Discord with a token that Discord does not recognise or has been invalidated. This error prevents your bot from starting entirely and will appear in your console output as a login failure.

The error message typically looks like this:

Error [TOKEN_INVALID]: An invalid token was provided.

There are several reasons why a token might be invalid. The most common is that the token was regenerated in the Developer Portal but the old token is still being used in your bot configuration. When you click "Reset Token" in the Developer Portal, the previous token is immediately invalidated and cannot be used again.

Check the following to resolve invalid token errors:

  • Verify the token value: Open your .env file or configuration and ensure the token is complete and has not been truncated. Bot tokens are long strings and it is easy to accidentally miss characters when copying.
  • Check for extra whitespace: Ensure there are no leading or trailing spaces around the token in your configuration file. Some text editors add invisible characters that can break the token.
  • Confirm the correct .env file is being loaded: If your project has multiple .env files or if you recently moved files, your bot might be reading an outdated configuration. Add a console.log statement before the login call to verify the token is being loaded correctly (log only the first few characters for security).
  • Regenerate the token: If you cannot determine why the token is invalid, go to the Developer Portal and generate a new one. Update the token in all locations where it is stored and restart your bot.
  • Check for bot vs user token: Ensure you are using a bot token, not a user token or OAuth2 client secret. The bot token is found specifically in the Bot section of the Developer Portal.

Missing Gateway Intents

Gateway intents are a mechanism Discord uses to control which events your bot receives. If your bot is missing required intents, it will either fail to start with an error or start successfully but not receive certain events, causing features to silently fail.

Discord categorises intents into two groups: standard intents and privileged intents. Standard intents can be used by any bot without special approval. Privileged intents, which include Server Members, Message Content, and Presence, must be explicitly enabled in the Developer Portal before they can be used in your code.

If you attempt to use a privileged intent in your code without enabling it in the Developer Portal, you will receive an error similar to:

Error [DisallowedIntents]: Privileged intent provided is not enabled or has not been approved for your bot.

To resolve this, go to the Developer Portal, select your application, navigate to the Bot page, and enable the required privileged intents. The changes take effect immediately, so you can restart your bot right after enabling them.

It is important to only request the intents your bot actually needs. Each intent enables a category of events, and requesting unnecessary intents increases the volume of data your bot processes. For bots in more than 100 servers, Discord may require verification before granting access to privileged intents. This verification process involves explaining why your bot needs the requested intents and may take several days to complete.

Common intents and when you need them:

  • Guilds: Required for receiving guild (server) events. Almost all bots need this.
  • GuildMessages: Required for receiving message events in servers. Needed for message-based commands.
  • MessageContent (privileged): Required for reading the text content of messages. Without this, message.content will be empty.
  • GuildMembers (privileged): Required for receiving member join, leave, and update events. Needed for welcome messages or member tracking.
  • GuildPresences (privileged): Required for tracking member online status and activities. Most bots do not need this.

Bot Appears Offline

When your bot shows as offline in the Discord member list, it means the bot process is not running or has lost its connection to the Discord Gateway. This is different from the bot being online but not responding, which usually indicates a code issue rather than a connection problem.

Start by checking whether your bot process is actually running on your hosting platform. On MonkeyBytes Hosting, you can see the server status in your dashboard. If the server shows as stopped, start it and check the console output for any startup errors. If the server is running but the bot appears offline, there may be a crash occurring shortly after startup that prevents the bot from establishing its Discord connection.

Network issues can also cause a bot to appear offline. If the hosting server cannot reach Discord servers, the Gateway connection will fail. This is usually temporary and resolves itself when the network issue clears. Discord bot libraries include automatic reconnection logic that will re-establish the connection without intervention once the network is restored.

If your bot was previously online and suddenly went offline, check the console logs for crash reports. Common causes of unexpected shutdowns include unhandled promise rejections, out-of-memory errors, and unhandled exceptions in event handlers. Adding proper error handling prevents most of these issues:

process.on('unhandledRejection', (error) => {
    console.error('Unhandled promise rejection:', error);
});

process.on('uncaughtException', (error) => {
    console.error('Uncaught exception:', error);
});

client.on('error', (error) => {
    console.error('Client error:', error);
});

Another cause of a bot appearing offline is running multiple instances of the same bot simultaneously. If two processes try to connect with the same token, Discord will disconnect the first connection when the second one establishes. This creates a cycle where the bot repeatedly connects and disconnects, appearing to flicker between online and offline states. Ensure only one instance of your bot is running at a time.

Memory or CPU Limits

Exceeding memory or CPU limits is a common issue for bots that grow beyond their initial scope or have inefficient code. When a bot exceeds its allocated resources, the hosting platform may throttle it, causing slow responses, or terminate it entirely, causing the bot to go offline.

Memory issues are often caused by memory leaks, where the bot gradually consumes more memory over time without releasing it. Common causes of memory leaks in Discord bots include storing data in global variables that grow indefinitely, not cleaning up event listeners, caching user data without setting limits, and not closing database connections properly.

To diagnose memory issues, monitor your bot memory usage over time. On MonkeyBytes Hosting, the dashboard shows real-time memory consumption. If you see memory usage steadily increasing without levelling off, you likely have a memory leak. Add periodic memory logging to help identify when the leak occurs:

setInterval(() => {
    const mem = process.memoryUsage();
    console.log(`Memory: RSS=${Math.round(mem.rss / 1024 / 1024)}MB, ` +
        `Heap=${Math.round(mem.heapUsed / 1024 / 1024)}MB`);
}, 60000);

CPU issues typically arise from intensive operations performed on the main thread. Image processing, complex calculations, large data sorting, and frequent API calls can all spike CPU usage. If your bot performs CPU-intensive tasks, consider offloading them to worker threads or optimising the algorithms involved.

To reduce memory usage, consider disabling caching for data your bot does not need. Discord.js allows you to configure which caches are maintained and set limits on their size. For example, if your bot does not need to track messages, you can disable the message cache entirely or limit it to a small number of recent messages per channel.

Rate Limits

Discord enforces rate limits on all API requests to prevent abuse and ensure fair usage of their infrastructure. When your bot exceeds these limits, Discord returns a 429 (Too Many Requests) response, and your bot must wait before making additional requests. Understanding and respecting rate limits is essential for building a reliable bot.

Rate limits in Discord operate on multiple levels. There are per-route limits that restrict how many times you can call a specific endpoint within a time window, and global limits that restrict the total number of requests your bot can make across all endpoints. The discord.js library handles rate limiting automatically by queuing requests and waiting the appropriate amount of time before retrying, but excessive rate limiting still causes noticeable delays in your bot responses.

Common actions that trigger rate limits include sending messages too quickly in a channel, editing messages repeatedly, adding many reactions to a single message, and bulk-modifying roles or channels. If your bot performs batch operations, implement delays between actions to stay within rate limits.

Signs that your bot is being rate limited include delayed responses to commands, warnings in your console output about rate limiting, and intermittent failures when performing actions. The discord.js library logs rate limit warnings that indicate which endpoint was limited and how long the bot must wait.

To minimise rate limit issues:

  • Avoid sending multiple messages when one would suffice. Use embeds to consolidate information into a single message.
  • Use bulk operations where available, such as bulk-deleting messages instead of deleting them one at a time.
  • Add cooldowns to user-facing commands to prevent users from spamming commands rapidly.
  • Cache responses for commands that produce the same output regardless of who runs them.
  • Avoid unnecessary API calls by using cached data from the bot internal cache whenever possible.

Permission Errors

Permission errors occur when your bot attempts to perform an action it does not have the necessary permissions for in a specific server or channel. Discord has a detailed permission system that controls what bots and users can do, and missing permissions will cause API requests to fail with a "Missing Permissions" or "Missing Access" error.

The most common permission issues involve the bot not having the required permissions in specific channels. Discord permissions are hierarchical: server-level permissions provide the base, and channel-level permission overwrites can grant or deny specific permissions. A bot might have the "Send Messages" permission at the server level but have it denied in a specific channel through an overwrite.

To debug permission issues, first identify which permission is required for the action your bot is trying to perform. Common permissions and their associated actions include:

  • Send Messages: Required to send messages in a channel
  • Embed Links: Required to send messages with rich embeds
  • Manage Messages: Required to delete other users messages or pin messages
  • Manage Roles: Required to assign or remove roles from members
  • Kick Members / Ban Members: Required for moderation actions
  • View Channel: Required to see and interact with a channel at all
  • Add Reactions: Required to add reactions to messages
  • Manage Channels: Required to modify channel settings

When designing your bot, check for permissions before attempting actions and provide helpful error messages when permissions are missing. This improves the user experience and makes it easier for server administrators to understand what permissions need to be granted.

Debugging Tips

Effective debugging is a skill that saves significant time when troubleshooting bot issues. Having a systematic approach to identifying and resolving problems helps you fix issues faster and build more reliable bots.

Start with the console output. Most errors produce stack traces that indicate exactly which file and line number caused the problem. Read the error message carefully before searching for solutions, as it often contains the information needed to understand what went wrong. Stack traces should be read from bottom to top to find the originating line in your code, as the top entries typically refer to internal library code.

Use console.log statements strategically to trace the flow of your code. When a command is not working, add log statements at key points: when the event fires, when conditions are evaluated, and when actions are taken. This reveals whether the issue is with event reception, condition matching, or action execution.

Test in isolation. If a specific feature is not working, create a minimal test case that only includes the code necessary to reproduce the issue. This eliminates interference from other parts of your bot and makes the problem easier to identify. Once you fix the issue in the minimal case, apply the fix to your full bot.

Check the Discord API status page when experiencing widespread connectivity or functionality issues. Discord occasionally experiences outages or degraded performance that affect all bots. During these periods, errors are not caused by your code and will resolve when Discord services recover.

Review recent changes. If your bot was working before and stopped after an update, the most likely cause is something in the recent changes. Use version control (Git) to compare the current code with the last working version and identify what changed. This approach narrows down the problem to a specific set of modifications rather than searching the entire codebase.

Logging Best Practices

Good logging practices are the foundation of maintainable bot operations. Logs provide the historical record you need to diagnose issues, understand bot behaviour, and track performance over time. Investing in proper logging from the beginning pays dividends as your bot grows.

Include timestamps in all log entries so you can correlate events with specific times. When a user reports that the bot was not working at a particular time, timestamps allow you to quickly find the relevant log entries and understand what was happening.

Use different log levels to categorise the importance of messages. Common levels include:

  • Error: Something failed and needs attention. Examples: API errors, unhandled exceptions, failed database queries.
  • Warning: Something unexpected happened but the bot can continue. Examples: rate limit hits, deprecated feature usage, missing optional configuration.
  • Info: Normal operational events worth recording. Examples: bot startup, command executions, configuration changes.
  • Debug: Detailed information useful during development. Examples: variable values, function entry and exit, API response details.

Avoid logging sensitive information such as bot tokens, user passwords, or personal data. If you need to log identifiers for debugging, use Discord user IDs or guild IDs rather than usernames or email addresses. This protects user privacy and prevents accidental exposure of sensitive data in log files.

Consider implementing log rotation or size limits to prevent log files from consuming all available storage. On hosting platforms with limited storage, unbounded logging can eventually fill the disk and cause your bot to crash. Many logging libraries support automatic rotation based on file size or time intervals.

For further help with your bot, check our hosting guide for deployment best practices, or visit our step-by-step tutorial to set up your bot from scratch. Browse our features page to learn about MonkeyBytes tools, check the FAQ for common questions, or return to the home page.

Guide Complete Hosting Guide Tutorial Host a Bot for Free Comparison Free Hosting Platforms