Ancient
Ancient

Reputation: 41

TypeError: event() missing 2 required positional discord.py error

I am trying to start coding a discord bot using discord.py however I am always getting this error even though I am following many tutorials

The Error:

TypeError: event() missing 2 required positional arguments: 'self' and 'coro'

The code:

client = discord.Client

@client.event()
async def on_ready():

    guild_count = 0

    for guild in client.guilds:

        print(f"- {guild.id} (name: {guild.name})")

        guild_count = guild_count + 1

    print('Nerdeyes has awoken in ' + str(guild_count) + " servers")

@client.event()
async def on_message(message):

    if message.content == "Nerd":
        await message.channel.send("Eyes")

client.run("My token (that i do not want to reveal)")

Upvotes: 1

Views: 363

Answers (1)

Ibrahim
Ibrahim

Reputation: 844

I prefer you reading this https://discordpy.readthedocs.io/en/stable/index.html as it is the official docs and also you can look at some examples from https://github.com/Rapptz/discord.py/blob/async/examples/

And as molbdnilo said its @client.event and not @client.event().

There is also one more bug in your code you need to add this line await client.process_commands(message) at here

@client.event
async def on_message(message):
    await client.process_commands(message)
    ....

One more thing you should you bot instead of client because Bot is an extended version of Client (it's in a subclass relationship). I.e. it's an extension of Client with commands enabled, thus the name of the subdirectory ext/commands

Upvotes: 1

Related Questions