Syncing the command tree in discord.py
This seems to be a common "gotcha" with users new to the library. As such I have been asked to cover it a bit more here.
CommandTree.sync is how we make Discord aware of our command definitions. This means that we use an API request to send them a copy of what our commands look like and act like, so they can display it to your users in the client.
If you do not sync your tree, the commands will not show up, or update them if you make changes locally.
I cover some more items relating to this in the next file below. But for now let's cover the basics and what you can do here.
In my time as Helper, I see people syncing their CommandTree in the
on_ready_event or in the new
setup_hook entrypoint method.
I do not advise this personally, it can lead to footguns if you aren't prepared.
For examples, if you sync your tree before you load your extensions (which have your application commands), then you're effectively syncing an empty tree to Discord, which will wipe your commands.
If you sync your tree and then make changes, you rely on the autosync and forget to sync changes, resulting in errors and failing commands.
This is why it is strongly recommended to sync on demand with a command (ideally with a message command) and know when to do such things. I cover that later too.
I'll add more things when I can think of them.