You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
using the client.tree.sync or just tree.sync will not sync the app_commands in any guild
Reproduction Steps
You can define the bot/client as either of these two:
client=commands.Bot(command_prefix="!", intents=discord.Intents.all())
# OR client=discord.Client(intents=discord.Intents.all())
tree=app_commands.CommandTree(client)
I put my guildIds in a list: guild_ids = [MY_GUILD_ID]
Then you have two options for automatically syncing:
Create a setup_hook:
asyncdefsetup_hook() ->None:
client.tree.copy_global_to(guild=discord.Object(id=guild_ids[0])) # Optional if you don't want global?awaitclient.tree.sync(guild=discord.Object(id=guild_ids[0]))
client.setup_hook=setup_hook
Sync on_ready:
@client.eventasyncdefon_ready() ->None:
awaitclient.tree.sync(guild=discord.Object(id=guild_ids[0]))
print(f"Logged in as {client.user}")
There is also the option to create a sync command:
@client.tree.command(name="sync", description="Syncs the bot commands", guild=discord.Object(id=guild_ids[0])) # or just use @tree.commandasyncdefsync(interaction: discord.Interaction):
ifinteraction.user.id==MY_USER_ID:
#client.tree.copy_global_to(guild=discord.Object(id=guild_ids[0])) # I tried putting it here too.awaitclient.tree.sync(guild=discord.Object(id=guild_ids[0]))
awaitinteraction.response.send_message('Command tree synced.')
else:
awaitinteraction.response.send('You must be the owner to use this command!')
Make sure the bot has application.command permissions on the server
Minimal Reproducible Code
No response
Expected Results
I expected the commands to show up in discord.
Actual Results
The commands don't show up during the majority of my attempts. I think in one variation it synced once, but never again even after reproducing it. I have two commands registered and they have not synced since.
Intents
Intents.all()
System Information
discord.py==2.3.2 via requirements.txt (used in docker container)
Checklist
I have searched the open issues for duplicates.
I have shown the entire traceback, if possible.
I have removed my token from display, if visible.
Additional Context
No response
The text was updated successfully, but these errors were encountered:
The reason why is that the command is only synced to the guild, but not globally so it only shows up the commands that are marked to synced to that guild using @app_commands.guilds()
It's recommended to not use the on_ready event to sync due to the dangers of the event being called randomly multiple times without warning.
you can't sync app commands using an app command when the app command itself is not synced. Instead, use a prefixed command instead (mentions for the bot can also work)
subclass setup_hook in discord.Client (and all subclasses) instead of trying to attach it as an attribute
Summary
using the client.tree.sync or just tree.sync will not sync the app_commands in any guild
Reproduction Steps
You can define the bot/client as either of these two:
I put my guildIds in a list:
guild_ids = [MY_GUILD_ID]
Then you have two options for automatically syncing:
There is also the option to create a sync command:
Make sure the bot has
application.command
permissions on the serverMinimal Reproducible Code
No response
Expected Results
I expected the commands to show up in discord.
Actual Results
The commands don't show up during the majority of my attempts. I think in one variation it synced once, but never again even after reproducing it. I have two commands registered and they have not synced since.
Intents
Intents.all()
System Information
discord.py==2.3.2 via requirements.txt (used in docker container)
Checklist
Additional Context
No response
The text was updated successfully, but these errors were encountered: