New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: asynchronousifying setup function in cogs #536
Conversation
✅ Deploy Preview for nextcord-gh-action ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make your pull request name better, ideally following cc.
Something like feat: Allow cog setup to be async
I personally disagree with making this a breaking change, especially given the overall use-case from what I have seen. Yes, some form of async loading is nice for a minority, however, enforcing the syntax proposed essentially removes |
This comment has been minimized.
This comment has been minimized.
You could use nextcord.utils.maybe_coroutine() for this. |
This requires making |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make an faq entry on the error that may be risen as discussed
This comment has been minimized.
This comment has been minimized.
In extensions.rst this should be changed. You can remove "This setup must be a plain Python function (not a coroutine)."
|
also perhaps handle error then raise an error which shows the faq entry perhaps |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Have you also tested backwards compatibility? |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Sounds good |
This comment has been minimized.
This comment has been minimized.
TIL However, still not removing the requested changes however as it is bad practice since it's creating two loops (I think) and either of the two calls should be the entry point for the bot. async def main():
bot.load_extension("cog_name")
await bot.start("TOKEN")
asyncio.run(main()) Tested on your fork works fine and as expected |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Code? Alternately you can create a task instead, and then use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM and I've tested on:
- 3.8.5
- 3.9.6
- 3.10.0
* uh setup now can being awaitable =) * add faq entry * remove coroutine notice * make a more useful error * code docs * fix weirdo * fix docs * .
Summary
NOTE: THIS WILL RAISE AN KEYBOARDINTERRUPT IF YOU ARE DOING AS SKELMIS SAYS AND IS ENDING THE BOT USING CONTROL + C
setup to be awaitable, fix issue #468
Checklist