How to Make a Discord Bot Respond to Specific Words Only
🔍 WiseChecker

How to Make a Discord Bot Respond to Specific Words Only

You want your Discord bot to react only when someone says a particular word or phrase, not every message in the channel. Without this control, a bot can spam the chat with unwanted replies or miss the exact trigger you need. This article explains how to configure your bot using Discord’s built-in prefix system and a simple code filter. By the end, you will have a bot that listens only for the words you choose and ignores everything else.

Key Takeaways: How to Filter Bot Responses to Specific Words

  • Prefix-based filtering in code: Use a command prefix like “!” so the bot only responds when that prefix appears before the trigger word.
  • Message content filter in Discord Developer Portal: Enable the “Message Content Intent” to allow your bot to read message text.
  • String matching in your bot script: Write an if statement that checks for exact word matches or includes() for partial matches.

What You Need Before Setting Up Word-Specific Bot Responses

A Discord bot responds to all messages it can read unless you add code to filter them. The most reliable method is to use a command prefix, such as an exclamation mark or a slash, combined with a word check in your bot’s code. This requires two things: the correct permissions in the Discord Developer Portal and a small script in a language like Python, JavaScript, or Java. The script runs on your computer or a cloud server and communicates with Discord’s API.

Prerequisites

Before writing code, you must have a Discord bot application created in the Discord Developer Portal. You need the bot token, which is a unique key that lets your code control the bot. Also, you must enable the “Message Content Intent” under the Bot settings in the portal. Without this intent, the bot cannot see the text of messages and will not be able to check for specific words.

Choosing a Programming Language

The most common libraries are discord.py for Python and discord.js for Node.js. Both provide built-in functions to handle message events and check for prefixes. This article uses Python with discord.py because it is beginner-friendly. The same logic applies to any language: listen for a message event, check the content, and reply only if it matches.

Steps to Make a Discord Bot Respond to Specific Words Only

Follow these steps to create a bot that replies only when a user types a specific word or phrase. The example uses a Python bot that responds to the word “hello” when it appears at the start of a message or after a prefix.

Step 1: Create the Bot Application and Get the Token

  1. Go to the Discord Developer Portal
    Open your browser and visit discord.com/developers/applications. Click the “New Application” button and give it a name. This creates your bot’s application.
  2. Navigate to Bot settings
    In the left sidebar, click “Bot” and then click “Add Bot.” Confirm the pop-up. You will see a token section. Click “Copy” to save the token. Keep this token private — anyone with it can control your bot.
  3. Enable Message Content Intent
    Scroll down to the “Privileged Gateway Intents” section. Toggle on “Message Content Intent.” This is required for the bot to read message text. Click “Save Changes.”

Step 2: Invite the Bot to Your Server

  1. Open OAuth2 settings
    In the Developer Portal, click “OAuth2” then “URL Generator” in the left sidebar.
  2. Select scopes and permissions
    Under Scopes, check “bot.” Under Bot Permissions, choose “Send Messages” and “Read Message History.” A URL appears at the bottom of the page.
  3. Use the invite URL
    Copy the generated URL, paste it into your browser, select your server from the dropdown, and click “Authorize.” Complete the CAPTCHA if prompted.

Step 3: Write the Bot Script

  1. Install discord.py
    Open a terminal or command prompt and run: pip install discord.py. This installs the Python library.
  2. Create a Python file
    Open a text editor and create a new file named bot.py. Paste the following code:
    import discord
    
    client = discord.Client()
    
    @client.event
    async def on_ready():
        print(f'Logged in as {client.user}')
    
    @client.event
    async def on_message(message):
        if message.author == client.user:
            return
    
        # Check if the message starts with the trigger word
        if message.content.lower().startswith("hello"):
            await message.channel.send("Hi there! I only respond to hello.")
    
    client.run("YOUR_BOT_TOKEN")
    
  3. Replace the token
    Replace YOUR_BOT_TOKEN with the token you copied from the Developer Portal. Do not share this file publicly.
  4. Run the bot
    In the terminal, run python bot.py. You should see “Logged in as [bot name].” The bot is now online.

Step 4: Test the Bot

  1. Send a message with the trigger word
    In any channel the bot can see, type “hello” or “Hello everyone.” The bot should reply with “Hi there!”
  2. Send a message without the trigger word
    Type “goodbye” or “how are you.” The bot should not respond. If it does, check your code for missing conditions.

Common Mistakes and Things to Avoid

Even with correct code, several issues can cause the bot to respond incorrectly or not at all. Here are the most frequent problems and how to fix them.

Bot Responds to Every Message

If your bot replies to all messages, you likely forgot to add the if condition that checks for the specific word. Ensure your on_message event contains a check like if "hello" in message.content.lower():. Without this, the bot will process every message.

Bot Does Not Respond at All

First, verify that the bot is online by checking the member list in your Discord server. If it is offline, the token may be incorrect or the script is not running. Second, confirm that the Message Content Intent is enabled in the Developer Portal. Without it, message.content will be empty. Finally, check that the bot has permission to read messages in the channel.

Case Sensitivity Problems

If you type “Hello” but your code checks for “hello” without converting case, the bot will not respond. Always use .lower() on the message content and the trigger word to make the comparison case-insensitive.

Bot Responds to Its Own Messages

The code includes if message.author == client.user: return to prevent the bot from replying to itself. If you removed this line, the bot will create an infinite loop. Always keep this check.

Prefix-Based Filtering vs Word-Only Filtering

Item Prefix-Based Filtering Word-Only Filtering
Trigger example !hello hello
Code check message.content.startswith(“!hello”) “hello” in message.content.lower()
Accidental triggers Rare — only fires when prefix is typed Common — fires if word appears anywhere in message
User experience Requires learning the prefix Feels more natural but can be noisy
Best use case Commands like !help or !rules Auto-replies for specific keywords

This article covers the word-only approach. If you prefer prefix-based filtering, change the condition to check for a prefix like “!” followed by your word. Both methods work with the same script structure.

You now know how to create a Discord bot that responds only to specific words. Start by enabling Message Content Intent in the Developer Portal. Next, write a simple Python script that checks message content with an if statement. Test with a trigger word and confirm the bot ignores other messages. For more advanced control, add multiple trigger words or use regular expressions for pattern matching. Try adding a second trigger word like “goodbye” by duplicating the if condition in your code.