Search code examples
pythondiscordbots

Discord Python can not find the attribute "event" inside of "bot"


Look at my code down here / This is the output: Traceback (most recent call last): File "C:\Games\Coding\tickets.py", line 8, in @client.event ^^^^^^^^^^^^ AttributeError: module 'discord.client' has no attribute 'event'

Code:

import discord
from discord.ext import commands

client = commands.bot

@client.event
async def on_ready():
    print("Bot is ready to execute action")

What is going wrong here?


Solution

  • It's commands.Bot and you need to call it with command_prefix parameter.

    from discord.ext import commands
    
    client = commands.Bot(command_prefix='!')
    
    @client.event
    async def on_ready():
        print("Make something with the bot")
    
    client.run('BOT_TOKEN')