Reputation: 43
I want to disable an command, but i dont know how it works
this is the command i want to disable
@client.command(description="Sends an random gif", aliases=['gifje', 'GIF', 'Gif'], brief="Sends an random gif (NO NSFW)")
discord.ext.commands.Command(name="gif", cls=None, enabled=False)
#@commands.cooldown(1, 10, commands.BucketType.user)
async def gif(ctx):
links = ["https://gph.is/1N1s5AR",
"https://gph.is/2nmNhuw",
"https://gph.is/g/ajWp6mj",
"https://gph.is/g/apbGw0O",
"https://gph.is/g/Z5YMP9Q",
"https://gph.is/g/aQOvqQ5",
"https://gph.is/g/ajW9Nx8",
"https://gph.is/2CF8W7r",
"http://gph.is/17GL4ua",
"https://gph.is/12kQg0y"]
await ctx.send(random.choice(links))
i believe i have to do it with discord.ext.commands but i dont know how (i dont want to use cogs)
Upvotes: 0
Views: 6974
Reputation: 1
@commands.command(name="toggle", description="Enable or disable a command!")
@commands.is_owner()
async def toggle(self, ctx, *, command):
command = self.client.get_command(command)
if command is None:
embed = discord.Embed(title="ERROR", description="I can't find a command with that name!", color=0xff0000)
await ctx.send(embed=embed)
elif ctx.command == command:
embed = discord.Embed(title="ERROR", description="You cannot disable this command.", color=0xff0000)
await ctx.send(embed=embed)
else:
command.enabled = not command.enabled
ternary = "enabled" if command.enabled else "disabled"
embed = discord.Embed(title="Toggle", description=f"I have {ternary} {command.qualified_name} for you!", color=0xff00c8)
await ctx.send(embed=embed)
This is the easiest way I use to disable/enable commands
Upvotes: 0
Reputation: 884
.update(enabled=False)
You can get the Command
object by going through Bot.commands
to find the command you're looking for. Once you've found the right command object, you can use its update
method to edit the enabled
attribute.
Setting this attribute to False
will result in a DisabledCommand
error being raised upon calling the command, which you can handle as you wish.
Upvotes: 1
Reputation: 164
client.remove_command(name)
You can create a command that runs this command and it will be unavailable until added back or the bot is restarted.
Upvotes: 0