Hey everyone! I'm new to making Discord bots and I've hit a snag. I followed a tutorial but my code isn't working. Here's what I've got:
```python
import discord
TOKEN = 'MY_SECRET_TOKEN'
bot = discord.Client()
@bot.event()
async def bot_ready():
print(f'{bot.user} is online!')
bot.run(TOKEN)
When I try to run it, I get this error:
Traceback (most recent call last):
File "bot_script.py", line 8, in <module>
@bot.event()
TypeError: event() missing 2 required positional arguments: 'self' and 'coro'
I’m really confused. What am I doing wrong? Any help would be awesome!
I ran into a similar issue when I first started with Discord bots. The problem is in how you’re using the @bot.event() decorator. You don’t need to call it as a function with parentheses. Instead, just use @bot.event without the (). Also, the event name for when the bot is ready is ‘on_ready’, not ‘bot_ready’. Here’s how you can fix it:
@bot.event
async def on_ready():
print(f'{bot.user} is online!')
This should resolve the TypeError you’re seeing. Another tip: consider using discord.py’s commands framework (discord.ext.commands) for more advanced functionality. It’ll make your life easier as your bot grows. Good luck with your project!
The issue lies in your event decorator and function name. Remove the parentheses after @bot.event and change the function name to on_ready. Also, you’re using an older version of discord.py. For newer versions, you should use discord.Intents and discord.Client(intents=intents). Here’s an updated version: