-
Recently I've been testing several different libraries to use the Discord API, so some commands were generated on these other platforms, but now I need to remove the commands registered by them, since they don't exist in the version using discord.py. I discovered the tree.clear_commands command, but it only excludes the commands that discord.py itself recorded. Is there any way to do this with all BOT commands? |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 2 replies
-
Call |
Beta Was this translation helpful? Give feedback.
-
After executing the code above, it only deletes the commands that discord.py created itself, the rest remain on the server |
Beta Was this translation helpful? Give feedback.
-
they are probably global commands, sync but with |
Beta Was this translation helpful? Give feedback.
-
I was able to clear all bot commands by simply running these 2 lines (replace tree = discord.app_commands.CommandTree(discord_client)
await tree.sync() |
Beta Was this translation helpful? Give feedback.
-
For those who just want a standalone solution to delete all commands for their bot with my extremely limited knowledge I've made this. Surprisingly, it even works. import discord
intents = discord.Intents.default()
client = discord.Client(intents=intents)
tree = discord.app_commands.CommandTree(client)
@client.event
async def on_ready():
print(f'We have logged in as {client.user}')
guilds = [guild.id for guild in client.guilds]
print(f'The {client.user.name} bot is in {len(guilds)} Guilds.\nThe guilds IDs list: {guilds}')
for guildId in guilds:
guild = discord.Object(id=guildId)
print(f'Deleting commands from {guildId}.....')
tree.clear_commands(guild=guild,type=None)
await tree.sync(guild=guild)
print(f'Deleted commands from {guildId}!')
continue
print('Deleting global commands.....')
tree.clear_commands(guild=None,type=None)
await tree.sync(guild=None)
print('Deleted global commands!')
client.run('BOT_TOKEN') More experienced users are more than welcomed to improve this in any way you prefer. |
Beta Was this translation helpful? Give feedback.
they are probably global commands, sync but with
guild=None