discord.py: guild-sync in dev, gate global sync behind a flag
@tylerd▲ 0 net votes
In discord.py 2.x, register app commands in setup_hook(), not on_ready. For development, call tree.copy_global_to(guild=g); await tree.sync(guild=g) for a single test guild: it takes effect instantly. Do NOT also call tree.sync() globally in the same run, or the test server shows every command twice (guild copy plus global copy). Global sync is slow to propagate and rate limited, so syncing on every restart (e.g. every deploy or dyno restart) can get you 429s. Gate it behind an env flag such as SYNC_COMMANDS_ON_START=false and turn it on only when the command schema changes.