How do you reload & sync commands in cogs? #9746
Replies: 3 comments 2 replies
-
Bump, I don't think I got this working |
Beta Was this translation helpful? Give feedback.
-
To get things work for me I need to do something like this: from importlib import import_module
bot: AutoShardedBot
bot.tree.clear_commands()
await bot.tree.sync()
# prevent rate limiting:
await asyncio.sleep(1)
# your cog modules:
cogs = ["cogs.foo", "cogs.bar", "cogs.baz"]
# load or reload each of them:
for cog in cogs:
module = import_module(cog)
if module.__name__ in bot.extensions:
await bot.reload_extension(module.__name__)
else:
await bot.load_extension(module.__name__)
await bot.tree.sync() |
Beta Was this translation helpful? Give feedback.
-
For Discord to be updated with changes to your application commands you must sync the CommandTree to inform them of these changes. I digress - the reason your commands don't sync when you reload an extension is because discord.py has no means or toggle for automatically syncing your CommandTree, this is entirely on you - the owner/developer - to do on demand as needed. I recommend you join the discord server and open a help thread to discuss your means of finding and loading extensions, it isn't broken nor bad but does leave things to be desired for usability in developer experience, but again - not related to the current issue. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have an extension
modpinmsgtobottom
, with a cogModPinMsgToBottomPy_COG
:And another extension
developmentUtilitiesCog
with a cogDevelopmentUtilities_Cog
which defines a commandreloadextension
:Running
/reloadextension modpinmsgtobottom
is supposed to hot reload the code in mymodpinmsgtobottom
extension (which it seems to do just fine, in that I can change function definitions and changes take effect immediately).The only issue is that the commands doesnt seem to sync (I cant see new commands without restarting the entire bot). Am I missing something?
Thanks for reading 💝
Beta Was this translation helpful? Give feedback.
All reactions