Twentysix26 / x26-Cogs

General purpose cogs for Red V3
GNU General Public License v3.0
41 stars 28 forks source link

[Defender] Await `Bot.add_cog` call #58

Closed quachtridat closed 1 year ago

quachtridat commented 1 year ago

Since discord.py v2's Bot.add_cog() is a coroutine, this commit makes setup async and await the said coroutine. Without it, Red will complain like this:

[HH:MM:SS] WARNING  [py.warnings] /path/to/Red-DiscordBot/data/Bot.Instance/cogs/CogManager/cogs/defender/__init__.py:10: RuntimeWarning: coroutine 'Red.add_cog' was never awaited
  bot.add_cog(Defender(bot))

Reference: https://discordpy.readthedocs.io/en/stable/ext/commands/api.html#discord.ext.commands.Bot.add_cog

Injabie3 commented 1 year ago

FWIW, in our empirical testing, we are able to load Defender with this PR's change on an instance of Red running at https://github.com/Cog-Creators/Red-DiscordBot/commit/f13d910f66dbb38cbf546666807f4eec660ae279 . We tested one of our Warden rules, and it seems to be working 😀

Twentysix26 commented 1 year ago

Thanks for your contribution. I'm closing this PR as the dpy2 branch is rather stale by now and it's missing major changes from master. I have decided to resume work on a separate branch (dev-dpy2) where I'm gradually porting over the work I did back then.