Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subcommand object not accessible from context in checks added to groups #835

Open
sdf9s8d76f opened this issue Nov 11, 2023 · 0 comments
Open

Comments

@sdf9s8d76f
Copy link

sdf9s8d76f commented Nov 11, 2023

When adding checks to command groups, it is not possible to get access to the executed subcommand object from the context, which would be required for getting data from it, for example, in a subcommand permission system. Example:
Example code:

import hikari

import tanjun


def check(ctx: tanjun.abc.SlashContext) -> bool:
    print(ctx.command.metadata.get("required_subcommand_permission"))
    return True


group = tanjun.slash_command_group("testgroup", ".")
group.add_check(check)


@group.as_sub_command("test", ".")
async def test_command(ctx: tanjun.abc.SlashContext) -> None:
    await ctx.respond(f"{ctx.command.metadata.get('required_subcommand_permission')}")


test_command.set_metadata("required_subcommand_permission", "some permission")

loader = tanjun.Component().load_from_scope().make_loader()

bot = hikari.impl.GatewayBot("MTE3MjQ5OTUzMDE5Mzg0NjI5Mg.GS629g.jhAkLkkPG9ixAliL_2TW2xYCDiWIFf5i_BXE5Y") # Doesn't exist
client = tanjun.Client.from_gateway_bot(bot, declare_global_commands=True)
client.load_modules("main")

if __name__ == "__main__":
    bot.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant