Click here to Skip to main content
15,896,269 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to understand how Client.event works in discord.py. This is the source code for the event method.
Python
def event(self, coro):
    # Validation we don't need to worry about
    setattr(self, coro.__name__, coro)
    return coro

According to what I understand, a coroutine is passed into the event function and an attribute of the object is created with name same as the name of the coroutine and the value equal to the output of coroutine. What I don't understand is that what is the object we are talking about?

Here is the source code for discord.py and I am unable to figure out where an object is being created. Please help.

Also, since a coroutine is taken as an argument, does it mean that only function which are preceded by async can be passed?

What I have tried:

I tried looking for a declaration of an object of the class client in the source code but could not find one.
Posted
Updated 23-Mar-20 8:09am
v2
Comments
Richard MacCutchan 24-Mar-20 5:50am    
The source of discord.py has over 3000 lines. No one is going to read all that. You need to study the documentation for the package to see how to use it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900