Discord Bot responds in DMs but ignores server channel messages

I created a simple dice rolling bot for my Discord server but I’m having issues with it responding to commands. The bot works perfectly when I send direct messages to it, but when I try to use the same commands in server channels, nothing happens at all.

import discord
import random

BOT_TOKEN = 'YOUR_BOT_TOKEN'
COMMAND_PREFIX = '!'

intents = discord.Intents.default()
intents.typing = False
intents.presences = False

bot_client = discord.Client(intents=intents)

@bot_client.event
async def on_ready():
    print(f'Bot {bot_client.user} is now active!')

@bot_client.event
async def on_message(msg):
    if msg.author == bot_client.user:
        return
    
    if msg.content.startswith(COMMAND_PREFIX + 'roll'):
        await handle_dice_roll(msg)
    
    if msg.content.startswith(COMMAND_PREFIX + 'coin'):
        await handle_coin_flip(msg)

async def handle_dice_roll(msg):
    dice_options = [1, 2, 3, 4, 5, 6]
    bot_roll = random.choice(dice_options)
    user_input = msg.content[len(COMMAND_PREFIX + 'roll'):].strip()
    
    try:
        user_roll = int(user_input)
        if user_roll not in dice_options:
            await msg.channel.send("Invalid number. Use 1-6 only.")
            return
    except ValueError:
        await msg.channel.send("Please enter a valid number.")
        return
    
    if bot_roll == user_roll:
        outcome = 'It\'s a tie!'
    elif bot_roll > user_roll:
        outcome = f'Bot rolled {bot_roll}. You lose!'
    else:
        outcome = f'Bot rolled {bot_roll}. You win!'
    
    await msg.channel.send(outcome)

async def handle_coin_flip(msg):
    coin_sides = ['Heads', 'Tails']
    bot_flip = random.choice(coin_sides)
    user_guess = msg.content[len(COMMAND_PREFIX + 'coin'):].strip().capitalize()
    
    if user_guess not in coin_sides:
        await msg.channel.send("Invalid choice. Use 'Heads' or 'Tails'.")
        return
    
    if bot_flip == user_guess:
        result = f'Coin landed on {bot_flip}. You guessed right!'
    else:
        result = f'Coin landed on {bot_flip}. Better luck next time!'
    
    await msg.channel.send(result)

bot_client.run(BOT_TOKEN)

The weird thing is that the bot shows as online and has all the right permissions in the server. It just seems to completely ignore channel messages while responding fine to private messages. Has anyone encountered this before?

yeah, same thing happened to me last year. your code looks fine, but you probably need to enable the message content intent in your bot settings on discord’s developer portal. bots can’t read server messages without it anymore, though dms still work. also double-check that your bot has send message permissions in the channels you’re testing.

Had this exact problem last month with our gaming bot. Your code’s fine - Discord just needs the Message Content Intent enabled for bots to read server messages. DMs work because they skip this requirement. Go to Discord Developer Portal, find your app, hit the Bot tab and scroll to Privileged Gateway Intents. Flip on Message Content Intent. Restart your bot completely and it’ll start picking up server commands right away.

Had this exact same problem six months ago with my moderation bot. It’s definitely the message content intent being disabled. Discord changed their policy in 2022 - bots now need explicit permission to read message content in servers (DMs still work fine though). Go to Discord Developer Portal → your bot → Bot section → flip the “Message Content Intent” toggle under Privileged Gateway Intents. That’ll fix your server channels. Don’t forget to restart your bot after - the intent only kicks in when it reconnects to Discord’s gateway.