Enable and Disable Command in Nextcord

261 Views Asked by At

I'm trying to make a command that can disable and enable any of my current commands. But it keeps returning the following error:

nextcord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: module 'nextcord.ext.commands' has no attribute 'get'

This is my current code for that command:

@commands.command()
@commands.has_role("HR")
async def toggle(self, ctx, *, command):
    command = commands.get.command(command)
    role = nextcord.utils.get(ctx.guild.roles, name="owner")

    if ctx.command == command:
        await ctx.reply("nice try")
    else:
        command.enabled = not command.enabled
        tf = "enabled" if command.enabled else "disabled"
        await ctx.send(f"I have {tf} {command.qualified_name} for you!")
1

There are 1 best solutions below

0
On BEST ANSWER

It's just a typo. The function's name is get_command. You might also wanna use @commands.is_owner() so that only the owner of the bot can disable commands instead of a guild role but its up to you. Also it seems like this is in a cog so you should use self.client or self.bot depending on what you have in your __init__().

@commands.command()
@commands.is_owner()
async def toggle(self, ctx, command):
    command = self.client.get_command(command)
    role = nextcord.utils.get(ctx.guild.roles, name="owner")

    if ctx.command == command:
        await ctx.reply("nice try")
    else:
        command.enabled = not command.enabled
        tf = "enabled" if command.enabled else "disabled"
        await ctx.send(f"I have {tf} {command.qualified_name} for you!")