Reputation: 11605
I used dslash and nextcord to make a simple slash command:
import nextcord
import dslash
client = dslash.CommandClient()
@client.event
async def on_ready():
print(f'Running')
class Options(dslash.Choices):
trouble = 'trouble'
foil = 'foil'
@client.command()
async def rps(interaction: nextcord.Interaction, choice: Options):
if choice == Option.foil:
await interaction.response.send_message("You were foiled")
else:
await interaction.response.send_message(f"You picked {choice}.")
client.run(token.fetch())
Runs fine, however now I have changed the name for the function, and I don't want /rps
to be available from my bot anymore.
How do I delete it? I've checked in server settings and I can't find anything, so I assume it's supposed to be done with dslash?
Upvotes: 2
Views: 6079
Reputation: 1
If someone needs to delete a team that is not synced in the guild, then here is the deletion code:
import requests
from os import getenv
application = APPLICATION_ID # your bot's application id
guild = GUILD_ID # your guild's ID for deleting commands
headers = {"Authorization": f"Bot {getenv('BOTTOKEN')}"}
# bot token ^^^^^^^^^^^^^^^^^^^^
# MAIN INFO PAGE: https://discord.com/developers/docs/interactions/application-commands#updating-and-deleting-a-command
while True:
cmd = input("[global|guild] ")
if "global" in cmd:
cmd = input("[get|delete] ")
if "get" in cmd:
r = requests.get(f"https://discord.com/api/v10//applications/{application}/commands", headers=headers)
print(r)
print(r.text, "\n")
elif "delete" in cmd:
r = requests.delete(f"https://discord.com/api/v10//applications/{application}/commands/{input('command_id ')}", headers=headers)
print(r)
print(r.text, "\n")
elif "guild" in cmd:
cmd = input("[get|delete] ")
if "get" in cmd:
r = requests.get(f"https://discord.com/api/v10//applications/{application}/guilds/{guild}/commands", headers=headers)
print(r)
print(r.text, "\n")
elif "delete" in cmd:
r = requests.delete(f"https://discord.com/api/v10//applications/{application}/guilds/{guild}/commands/{input('command_id ')}", headers=headers)
print(r)
print(r.text, "\n")
You can find the command ID along the path: Server Settings > Integration > [bot name] Management. Or use the code above (enter "guild" then "get")
Upvotes: 0
Reputation: 1
I used a solution I found on another website where you clear the commands that aren't used by typing !clear
in the discord chat while the bot is running.
Here's the code:
@bot.command(name='deletecommands', aliases=['clear'])
@commands.has_any_role('Owner')
async def delete_commands(ctx):
bot.tree.clear_commands(guild=None)
await bot.tree.sync()
await ctx.send('Commands deleted.')
Be aware you must have the Owner
role, have your prefix set to !
and put it in the on_ready()
event for this code to work.
Here is the Original post from the discord.js Reddit in which the Python solution was posted: https://www.reddit.com/r/Discordjs/comments/12cx5yq/how_to_remove_slash_commands/
Upvotes: 0
Reputation: 2721
When you start the bot, dslash should automatically clear any commands from the bot that are no longer registered in your code - so if you change the name of the function, as you said, the name of the command should be updated next time you run the bot.
However, Discord caches global commands in the client for up to an hour, meaning that you may have to wait that long for the command to update. In order to get around this during development, Discord recommends using server-specific commands, which are not cached. You can quickly make all your commands server-specific in dslash by adding the guild_id
parameter to the client, for example:
client = dslash.CommandClient(guild_id=640606716442050605)
Upvotes: 1
Reputation: 11605
One solution (I used) was to kick the bot and invite it back, and it cleared.
There should be an api method for it (such as in Discord.js where you can just supply an empty list), but I have not been able to find one. Throught the documentation, github or otherwise, so for now I believe this to be the only solution.
Upvotes: 0