Skip to content

tanchan.components#

Commands, message components and modals implemented by Tan-chan for use with Tanjun and Yuyo.

tanchan.components.buttons #

Standard constant message components provided and used by Tanchan.

DELETE_CUSTOM_ID module-attribute #

DELETE_CUSTOM_ID = 'TC_DEL'

Match ID used for delete buttons.

DELETE_EMOJI module-attribute #

DELETE_EMOJI = UnicodeEmoji('✖️')

Emoji used for "delete" buttons.

OWNER_QS_KEY module-attribute #

OWNER_QS_KEY = 'a'

Query string key for the author field.

delete_row #

delete_row(ctx_or_author, /, *ctx_or_authors)

Make an action row builder with a delete button from a list of authors.

Parameters:

  • *ctx_or_authors (Snowflakeish | Context | AutocompleteContext | BaseContext[Any], default: () ) –

    IDs of authors who should be allowed to delete the response.

    Both user IDs and role IDs are supported with no IDs indicating that anybody should be able to delete the response.

    Tanjun and Yuyo contexts can also be passed here to target their author.

Returns:

  • ActionRowBuilder

    Action row builder with a delete button.

load_buttons #

load_buttons(client)

Load this module's components into a bot.

make_delete_id #

make_delete_id(author, /, *authors)

Make a delete button custom ID.

on_delete_button async #

on_delete_button(ctx)

Default implementation of a constant callback used by delete buttons.

Parameters:

  • ctx (ComponentContext) –

    The context that triggered this delete.

unload_buttons #

unload_buttons(client)

Unload this module's components from a bot.

tanchan.components.config #

Configuration classes for Tanchan's command components.

Config #

Bases: EvalConfig, HelpConfig

Full configuration for Tan-chan's commands and components.

Config.add_to_client should be used to set this config.

Examples:

client = tanjun.Client.from_gateway_bot(bot)
config = yuyo.components.config.Config(
    eval_guild_ids=None,
    enable_slash_command=True,
)

config.add_to_client(client)

enable_message_command class-attribute instance-attribute #

enable_message_command = True

Whether the help message command should be enabled.

enable_slash_command class-attribute instance-attribute #

enable_slash_command = False

Whether the help slash command should be enabled.

eval_guild_ids class-attribute instance-attribute #

eval_guild_ids = field(default=())

ID of the guilds the eval slash command should be declared in.

If None then the slash command will be declared in every guild (globally) and an empty collection ensures it isn't declared.

include_message_commands class-attribute instance-attribute #

include_message_commands = True

Whether message commands should be included without the with_help decorator.

If True then the command's callback docstring will be used as the description by default.

include_slash_commands class-attribute instance-attribute #

include_slash_commands = False

Whether slash commands should be included without the with_help decorator.

If True then the command.description will be used as the description by default.

add_to_client #

add_to_client(client)

Add this config to a Tanjun client.

Parameters:

  • client (Client | Client) –

    The client to add this config to.

EvalConfig #

Configuration for the eval commands.

EvalConfig.add_to_client should be used to set this config.

Examples:

client = tanjun.Client.from_gateway_bot(bot)
(
    yuyo.components.config.EvalConfig(eval_guild_ids=None)
    .add_to_client(client)
)

eval_guild_ids class-attribute instance-attribute #

eval_guild_ids = field(default=())

ID of the guilds the eval slash command should be declared in.

If None then the slash command will be declared in every guild (globally) and an empty collection ensures it isn't declared.

add_to_client #

add_to_client(client)

Add this config to a Tanjun client.

Parameters:

  • client (Client | Client) –

    The client to add this config to.

HelpConfig #

Configuration for the help commands.

HelpConfig.add_to_client should be used to set this config.

Examples:

client = tanjun.Client.from_gateway_bot(bot)
(
    yuyo.components.config.HelpConfig(enable_slash_command=True)
    .add_to_client(client)
)

enable_message_command class-attribute instance-attribute #

enable_message_command = True

Whether the help message command should be enabled.

enable_slash_command class-attribute instance-attribute #

enable_slash_command = False

Whether the help slash command should be enabled.

include_message_commands class-attribute instance-attribute #

include_message_commands = True

Whether message commands should be included without the with_help decorator.

If True then the command's callback docstring will be used as the description by default.

include_slash_commands class-attribute instance-attribute #

include_slash_commands = False

Whether slash commands should be included without the with_help decorator.

If True then the command.description will be used as the description by default.

add_to_client #

add_to_client(client)

Add this config to a Tanjun client.

Parameters:

  • client (Client | Client) –

    The client to add this config to.

tanchan.components.eval #

Bot owner-only commands for dynamically executing code in the bot.

load_sudo #

load_sudo(client)

Load this module's components into a bot.

unload_sudo #

unload_sudo(client)

Unload this module's components from a bot.

tanchan.components.help #

A components powered help command.

hide_from_help #

hide_from_help(cmd: _CommandT) -> _CommandT
hide_from_help(*, follow_wrapped: bool = False) -> collections.Callable[[_CommandT], _CommandT]
hide_from_help(cmd=None, /, *, follow_wrapped=False)

Hide a global command from the help command.

Parameters:

  • follow_wrapped (bool, default: False ) –

    Whether this should also apply the help information to the other command objects this wraps in a decorator call chain.

Examples:

@hide_from_command
@tanjun.as_message_command("name")
async def command(ctx: tanjun.abc.Context) -> None:
    '''Meow command.'''

load_help #

load_help(client)

Load this module's components into a bot.

unload_help #

unload_help(client)

Unload this module's components from a bot.

with_help #

with_help(description=None, /, *, category=None, follow_wrapped=False)

Override the help string for the command.

Parameters:

  • description (str | Mapping[str, str] | None, default: None ) –

    Description to set for the command.

    This supports Tanjun's localisation.

  • category (str | None, default: None ) –

    Name of the category this command should be in. Defaults to the component's name.

  • follow_wrapped (bool, default: False ) –

    Whether this should also apply the help information to the other command objects this wraps in a decorator call chain.

Examples:

@hide_from_command("Alternative description.")
@tanjun.as_message_command("name")
async def command(ctx: tanjun.abc.Context) -> None:
    ...