TraxHasACoolDog
TraxHasACoolDog

Reputation: 21

event() missing 1 required positional argument: 'coro' error discord.py

I'm making a bot for a new server and I keep getting this error, I'm fairly new to python and coding in general so any help is appreciated.

event() missing 1 required positional argument: 'coro' error discord.py

When I post this is saying it looks like my post is mostly code so im just going to type random things until it lets me post it. I have a pretty cool dog, he's very cute and he's the goodest boy to ever be good :)

Below is the code where I'm getting the error

@client.event
 

    
async def on_ready():
    print('We have logged in as {0.user}'
    .format(client))

And below is my full code

    import discord


client = discord.Client

@client.event
async def on_ready():
    print('We have logged in as {0.user}'
    .format(client))

@client.event
async def on_message(message):
    if message.author == client.user:
        return

    if message.content.startswith('>Hello Sylas'):
        await message.channel.send('Hello there!')

@client.event
async def on_message(message):
    if message.author == client.user:
        return

    if message.content.startswith('>Is Dobbie cool?'):
        await message.channel.send('Yes, he is the goodest boy!')

@client.event
async def on_message(message):
    if message.author == client.user:
        return
    
    if message.content.startswith('>Hey Sylas'):
        if str(message.author) in ["Trax#8949"]:
            await message.channel.send('Hey Trax!')



@client.event
async def on_message(message):  
    if message.author == client.user:
        return        
async def on_message(message): 
    if message.content.startswith('>'):
     async def ban(ctx, member : discord.Member, *, reason = None):
      await member.ban(reason = reason)





 













client.run('my token :)') 

Upvotes: 1

Views: 15975

Answers (2)

Dominik
Dominik

Reputation: 3592

Multiple on_message events will not work.

You can only have one event at a time, so you have to combine the events. This would look like this:

client = discord.Client() # Added brackets

@client.event
async def on_message(message):
    if message.author == client.user:
        return

    if message.content.startswith('>Hey Sylas'):
        if str(message.author) in ["Trax#8949"]:
            await message.channel.send('Hey Trax!') # First event

    [Shortened]

    if message.content.startswith('>ban'):
      await member.ban(reason = reason) # Last event

You can have multiple client.command() "functions" but this does not count for events.

A post that explains it pretty well: Why multiple on_message events will not work

Upvotes: 1

FileX
FileX

Reputation: 791

Try this:

import discord


client = discord.Client

@client.event
async def on_ready():
    print('We have logged in as {0.user}'
    .format(client))

@client.event
async def on_message(message):
    if message.author == client.user:
        return

    elif message.content.startswith('>Hello Sylas'):
        await message.channel.send('Hello there!')

    elif message.content.startswith('>Is Dobbie cool?'):
        await message.channel.send('Yes, he is the goodest boy!')

    elif message.content.startswith('>Hey Sylas'):
        if str(message.author) == "Trax#8949":
            await message.channel.send('Hey Trax!')

    elif message.content.startswith('>ban'): # You should restrict that to specific roles
        await member.ban(reason = reason)


client.run('now its my token :)')

What I've done:

  • put all on_message in one on_message
  • changed to ">ban" instead of using an uncalled function in it
  • changed "in ['Trax']" to "== 'Trax'"
  • added elifs

Upvotes: 0

Related Questions