mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-09-06 09:56:09 +00:00
[commads] Change cog/extension load/unload methods to be async
This commit is contained in:
@ -58,7 +58,7 @@ Once you have defined your cogs, you need to tell the bot to register the cogs t
|
||||
|
||||
.. code-block:: python3
|
||||
|
||||
bot.add_cog(Greetings(bot))
|
||||
await bot.add_cog(Greetings(bot))
|
||||
|
||||
This binds the cog to the bot, adding all commands and listeners to the bot automatically.
|
||||
|
||||
@ -66,7 +66,7 @@ Note that we reference the cog by name, which we can override through :ref:`ext_
|
||||
|
||||
.. code-block:: python3
|
||||
|
||||
bot.remove_cog('Greetings')
|
||||
await bot.remove_cog('Greetings')
|
||||
|
||||
Using Cogs
|
||||
-------------
|
||||
@ -112,6 +112,7 @@ As cogs get more complicated and have more commands, there comes a point where w
|
||||
|
||||
They are as follows:
|
||||
|
||||
- :meth:`.Cog.cog_load`
|
||||
- :meth:`.Cog.cog_unload`
|
||||
- :meth:`.Cog.cog_check`
|
||||
- :meth:`.Cog.cog_command_error`
|
||||
|
@ -24,10 +24,10 @@ An example extension looks like this:
|
||||
async def hello(ctx):
|
||||
await ctx.send(f'Hello {ctx.author.display_name}.')
|
||||
|
||||
def setup(bot):
|
||||
async def setup(bot):
|
||||
bot.add_command(hello)
|
||||
|
||||
In this example we define a simple command, and when the extension is loaded this command is added to the bot. Now the final step to this is loading the extension, which we do by calling :meth:`.Bot.load_extension`. To load this extension we call ``bot.load_extension('hello')``.
|
||||
In this example we define a simple command, and when the extension is loaded this command is added to the bot. Now the final step to this is loading the extension, which we do by calling :meth:`.Bot.load_extension`. To load this extension we call ``await bot.load_extension('hello')``.
|
||||
|
||||
.. admonition:: Cogs
|
||||
:class: helpful
|
||||
@ -45,7 +45,7 @@ When you make a change to the extension and want to reload the references, the l
|
||||
|
||||
.. code-block:: python3
|
||||
|
||||
>>> bot.reload_extension('hello')
|
||||
>>> await bot.reload_extension('hello')
|
||||
|
||||
Once the extension reloads, any changes that we did will be applied. This is useful if we want to add or remove functionality without restarting our bot. If an error occurred during the reloading process, the bot will pretend as if the reload never happened.
|
||||
|
||||
@ -57,8 +57,8 @@ Although rare, sometimes an extension needs to clean-up or know when it's being
|
||||
.. code-block:: python3
|
||||
:caption: basic_ext.py
|
||||
|
||||
def setup(bot):
|
||||
async def setup(bot):
|
||||
print('I am being loaded!')
|
||||
|
||||
def teardown(bot):
|
||||
async def teardown(bot):
|
||||
print('I am being unloaded!')
|
||||
|
Reference in New Issue
Block a user