Hey everyone! I’m having trouble with my Python Discord bot. It shows up as online but won’t send any messages. Here’s my code:
import discord
from dotenv import load_dotenv
load_dotenv()
BOT_TOKEN = 'my_secret_token'
bot = discord.Client(intents=discord.Intents.all())
@bot.event
async def on_ready():
print(f'{bot.user} is now connected!')
@bot.event
async def on_message(msg):
if msg.content.lower() == 'hi':
await msg.channel.send('Go away!')
bot.run(BOT_TOKEN)
The bot connects fine but doesn’t respond to messages. My old bot with similar code worked great. What am I doing wrong? Thanks for any help!
I encountered a similar issue with my Discord bot recently. The problem likely stems from your bot’s intents configuration. While you’ve enabled all intents, Discord now requires explicit permission for certain privileged intents, like reading message content.
Try modifying your intents setup like this:
intents = discord.Intents.default()
intents.message_content = True
bot = discord.Client(intents=intents)
This explicitly enables the message content intent. Also, ensure you’ve toggled the ‘Message Content Intent’ option in your Discord Developer Portal for this bot.
If that doesn’t work, double-check your bot’s permissions in the server settings. Sometimes, channel-specific permissions can override the bot’s global permissions, preventing it from sending messages in certain channels.
Lastly, verify your bot token is correct and up-to-date. Discord occasionally requires token resets for security reasons.
I’ve dealt with this exact problem before. The issue is likely related to Discord’s recent changes to message intents. You need to explicitly enable the message content intent in your code and in the Discord Developer Portal.
In your code, modify the intents setup:
intents = discord.Intents.default()
intents.message_content = True
bot = discord.Client(intents=intents)
Also, make sure you’ve enabled the ‘Message Content Intent’ in your bot’s settings on the Discord Developer Portal. Without this, your bot won’t be able to read message content.
If you’ve done both these steps and it’s still not working, check your bot’s permissions in the server and ensure it has the necessary permissions to send messages in the channels you’re testing in.
hey man, i had dis problem too. make sure u enable the message content intent in ur discord dev portal. also, check if ur bot has the right permissions in the server. sometimes it cant send messages cuz of that. good luck!