I’m new to Python and trying to make a Discord bot. It’s not working and the error points to the client.run() function on line 4. It mentions something about ‘intents’ not being specified. I tried adding intents after looking it up, but it’s still not working. Can someone help me figure out what’s wrong?
Here’s my code:
import discord
import time
intents = discord.Intents.default()
intents.message_content = True
bot = discord.Client(intents=intents)
def start_bot():
secret = 'YOUR_BOT_TOKEN'
bot.run(secret)
@bot.event
async def on_ready():
print('ChattyBot v1.0 launched')
print('Created by Alex Johnson')
print(f'Logged in at {time.strftime('%H:%M:%S')} as {bot.user}')
@bot.event
async def on_message(msg):
if msg.author == bot.user:
return
if msg.content.startswith('!greet'):
await msg.channel.send('Hello there! How can I assist you?')
elif msg.content.startswith('!info'):
await msg.channel.send('Check the documentation for more information.')
start_bot()
I know this might not be the best place to ask, but I’m not sure where else to turn for help. Any advice would be appreciated!
Ethan, I think I see the issue. Your code structure is correct, but the problem likely lies in how you’re initializing the bot. Instead of using discord.Client, try using discord.Bot for newer versions of discord.py. Here’s a quick fix:
Replace:
bot = discord.Client(intents=intents)
With:
bot = discord.Bot(intents=intents)
This change aligns with the latest discord.py practices. Also, ensure you’ve enabled the required intents in the Discord Developer Portal as others mentioned. If you’re still facing issues, consider checking your Python version - discord.py 2.0+ requires Python 3.8 or higher. Let us know if this solves your problem!
I’ve been there, Ethan. The intents issue can be a real pain. From what I see, your code structure looks good, but there might be a version mismatch. Have you tried running ‘pip freeze | grep discord’ in your terminal? This will show you the exact version of discord.py you’re using. If it’s below 2.0, that could explain the problem.
Also, make sure you’ve enabled the necessary intents in the Discord Developer Portal for your bot. Sometimes we forget this crucial step. Go to the portal, find your application, navigate to the ‘Bot’ section, and ensure ‘Message Content Intent’ is toggled on.
If these don’t work, try creating a new virtual environment and installing discord.py fresh. It’s saved me more times than I can count when dealing with dependency issues. Good luck with your bot!
hey ethan, i’ve run into this before. Looks like ur using an older version of discord.py. Try upgrading it with ‘pip install -U discord.py’. That should fix the intents issue. if not, double check ur bot token is correct. hope this helps!