Skip to content

tanjun.clients#

Standard Tanjun client.

ClientCallbackNames = tanjun.ClientCallbackNames module-attribute #

PrefixGetterSig = collections.Callable[Ellipsis, collections.Coroutine[typing.Any, typing.Any, collections.Iterable[str]]] module-attribute #

Type hint of a callable used to get the prefix(es) for a specific guild.

This should be an asynchronous callable which returns an iterable of strings.

Note

While dependency injection is supported for this, the first positional argument will always be a tanjun.abc.MessageContext.

Client #

Bases: tanjun.Client

Tanjun's standard tanjun.abc.Client implementation.

This implementation supports dependency injection for checks, command callbacks, prefix getters and event listeners. For more information on how this works see alluka.

Note

By default this client includes a parser error handling hook which will by overwritten if you call tanjun.Client.set_hooks.

__init__(rest, *, cache=None, events=None, server=None, shards=None, voice=None, event_managed=False, injector=None, mention_prefix=False, set_global_commands=False, declare_global_commands=False, command_ids=None, message_ids=None, user_ids=None, _stack_level=0) #

Initialise a Tanjun client.

Note

For a quicker way to initiate this client around a standard bot aware client, see tanjun.Client.from_gateway_bot and tanjun.Client.from_rest_bot.

PARAMETER DESCRIPTION
rest

The Hikari REST client this will use.

TYPE: hikari.api.RESTClient

cache

The Hikari cache client this will use if applicable.

TYPE: typing.Optional[hikari.api.Cache] DEFAULT: None

events

The Hikari event manager client this will use if applicable.

This is necessary for message command dispatch and will also be necessary for interaction command dispatch if server isn't provided.

TYPE: typing.Optional[hikari.api.EventManager] DEFAULT: None

server

The Hikari interaction server client this will use if applicable.

This is used for interaction command dispatch if interaction events aren't being received from the event manager.

TYPE: typing.Optional[hikari.api.InteractionServer] DEFAULT: None

shards

The Hikari shard aware client this will use if applicable.

TYPE: typing.Optional[hikari.ShardAware] DEFAULT: None

voice

The Hikari voice component this will use if applicable.

TYPE: typing.Optional[hikari.api.VoiceComponent] DEFAULT: None

event_managed

Whether or not this client is managed by the event manager.

An event managed client will be automatically started and closed based on Hikari's lifetime events.

This can only be passed as True if events is also provided.

TYPE: bool DEFAULT: False

injector

The alluka client this should use for dependency injection.

If not provided then the client will initialise its own DI client.

TYPE: typing.Optional[alluka.abc.Client] DEFAULT: None

mention_prefix

Whether or not mention prefixes should be automatically set when this client is first started.

It should be noted that this only applies to message commands.

TYPE: bool DEFAULT: False

declare_global_commands

Whether or not to automatically set global slash commands when this client is first started.

If one or more guild objects/IDs are passed here then the registered global commands will be set on the specified guild(s) at startup rather than globally.

The endpoint this uses has a strict ratelimit which, as of writing, only allows for 2 requests per minute (with that ratelimit either being per-guild if targeting a specific guild otherwise globally).

TYPE: typing.Union[hikari.SnowflakeishSequence[hikari.PartialGuild], hikari.SnowflakeishOr[hikari.PartialGuild], bool] DEFAULT: False

set_global_commands

Deprecated as of v2.1.1a1 alias of declare_global_commands.

TYPE: typing.Union[hikari.SnowflakeishOr[hikari.PartialGuild], bool] DEFAULT: False

command_ids

If provided, a mapping of top level command names to IDs of the existing commands to update.

This will be used for all application commands but in cases where commands have overlapping names, message_ids and user_ids will take priority over this for their relevant command type.

This field is complementary to declare_global_commands and, while it isn't necessarily required, this will in some situations help avoid permissions which were previously set for a command from being lost after a rename.

This currently isn't supported when multiple guild IDs are passed for declare_global_commands.

TYPE: typing.Optional[collections.Mapping[str, hikari.SnowflakeishOr[hikari.PartialCommand]]] DEFAULT: None

message_ids

If provided, a mapping of message context menu command names to the IDs of existing commands to update.

TYPE: typing.Optional[collections.Mapping[str, hikari.SnowflakeishOr[hikari.PartialCommand]]] DEFAULT: None

user_ids

If provided, a mapping of user context menu command names to the IDs of existing commands to update.

TYPE: typing.Optional[collections.Mapping[str, hikari.SnowflakeishOr[hikari.PartialCommand]]] DEFAULT: None

RAISES DESCRIPTION
ValueError

Raises for the following reasons:

  • If event_managed is True when event_manager is None.
  • If command_ids is passed when multiple guild ids are provided for declare_global_commands.
  • If command_ids is passed when declare_global_commands is False.

add_check(check) #

Add a generic check to this client.

This will be applied to both message and slash command execution.

PARAMETER DESCRIPTION
check

The check to add. This may be either synchronous or asynchronous and must take one positional argument of type tanjun.abc.Context with dependency injection being supported for its keyword arguments.

TYPE: tanjun.CheckSig

RETURNS DESCRIPTION
Self

The client instance to enable chained calls.

add_component(component) #

Add a component to this client.

PARAMETER DESCRIPTION
component

The component to move to this client.

TYPE: tanjun.Component

RETURNS DESCRIPTION
Self

The client instance to allow chained calls.

RAISES DESCRIPTION
ValueError

If the component's name is already registered.

add_prefix(prefixes) #

Add a prefix used to filter message command calls.

This will be matched against the first character(s) in a message's content to determine whether the message command search stage of execution should be initiated.

PARAMETER DESCRIPTION
prefixes

Either a single string or an iterable of strings to be used as prefixes.

TYPE: typing.Union[collections.Iterable[str], str]

RETURNS DESCRIPTION
Self

The client instance to enable chained calls.

checks() property #

Collection of the level tanjun.abc.Context checks registered to this client.

Note

These may be taking advantage of the standard dependency injection.

close(*, deregister_listeners=True) async #

Close the client.

RAISES DESCRIPTION
RuntimeError

If the client isn't running.

fetch_rest_application_id() async #

Fetch the ID of the application this client is linked to.

RETURNS DESCRIPTION
hikari.Snowflake

The application ID of the application this client is linked to.

from_gateway_bot(bot, /, *, event_managed=True, injector=None, mention_prefix=False, declare_global_commands=False, set_global_commands=False, command_ids=None, message_ids=None, user_ids=None) classmethod #

Build a tanjun.Client from a hikari.traits.GatewayBotAware instance.

Note

This defaults the client to human only mode and sets type dependency injectors for the hikari traits present in bot (including hikari.traits.GatewayBotAware).

PARAMETER DESCRIPTION
bot

The bot client to build from.

This will be used to infer the relevant Hikari clients to use.

TYPE: hikari.GatewayBotAware

event_managed

Whether or not this client is managed by the event manager.

An event managed client will be automatically started and closed based on Hikari's lifetime events.

TYPE: bool DEFAULT: True

injector

The alluka client this should use for dependency injection.

If not provided then the client will initialise its own DI client.

TYPE: typing.Optional[alluka.abc.Client] DEFAULT: None

mention_prefix

Whether or not mention prefixes should be automatically set when this client is first started.

It should be noted that this only applies to message commands.

TYPE: bool DEFAULT: False

declare_global_commands

Whether or not to automatically set global slash commands when this client is first started.

If one or more guild objects/IDs are passed here then the registered global commands will be set on the specified guild(s) at startup rather than globally.

The endpoint this uses has a strict ratelimit which, as of writing, only allows for 2 requests per minute (with that ratelimit either being per-guild if targeting a specific guild otherwise globally).

TYPE: typing.Union[hikari.SnowflakeishSequence[hikari.PartialGuild], hikari.SnowflakeishOr[hikari.PartialGuild], bool] DEFAULT: False

set_global_commands

Deprecated as of v2.1.1a1 alias of declare_global_commands.

TYPE: typing.Union[hikari.SnowflakeishOr[hikari.PartialGuild], bool] DEFAULT: False

command_ids

If provided, a mapping of top level command names to IDs of the commands to update.

This field is complementary to declare_global_commands and, while it isn't necessarily required, this will in some situations help avoid permissions which were previously set for a command from being lost after a rename.

This currently isn't supported when multiple guild IDs are passed for declare_global_commands.

TYPE: typing.Optional[collections.Mapping[str, hikari.SnowflakeishOr[hikari.PartialCommand]]] DEFAULT: None

message_ids

If provided, a mapping of message context menu command names to the IDs of existing commands to update.

TYPE: typing.Optional[collections.Mapping[str, hikari.SnowflakeishOr[hikari.PartialCommand]]] DEFAULT: None

user_ids

If provided, a mapping of user context menu command names to the IDs of existing commands to update.

TYPE: typing.Optional[collections.Mapping[str, hikari.SnowflakeishOr[hikari.PartialCommand]]] DEFAULT: None

from_rest_bot(bot, /, *, declare_global_commands=False, injector=None, set_global_commands=False, command_ids=None, message_ids=None, user_ids=None) classmethod #

Build a tanjun.Client from a hikari.traits.RESTBotAware instance.

Note

This sets type dependency injectors for the hikari traits present in bot (including hikari.traits.RESTBotAware).

PARAMETER DESCRIPTION
bot

The bot client to build from.

TYPE: hikari.RESTBotAware

declare_global_commands

Whether or not to automatically set global slash commands when this client is first started.

If one or more guild objects/IDs are passed here then the registered global commands will be set on the specified guild(s) at startup rather than globally.

The endpoint this uses has a strict ratelimit which, as of writing, only allows for 2 requests per minute (with that ratelimit either being per-guild if targeting a specific guild otherwise globally).

TYPE: typing.Union[hikari.SnowflakeishSequence[hikari.PartialGuild], hikari.SnowflakeishOr[hikari.PartialGuild], bool] DEFAULT: False

injector

The alluka client this should use for dependency injection.

If not provided then the client will initialise its own DI client.

TYPE: typing.Optional[alluka.abc.Client] DEFAULT: None

set_global_commands

Deprecated as of v2.1.1a1 alias of declare_global_commands.

TYPE: typing.Union[hikari.SnowflakeishOr[hikari.PartialGuild], bool] DEFAULT: False

command_ids

If provided, a mapping of top level command names to IDs of the existing commands to update.

This will be used for all application commands but in cases where commands have overlapping names, message_ids and user_ids will take priority over this for their relevant command type.

This field is complementary to declare_global_commands and, while it isn't necessarily required, this will in some situations help avoid permissions which were previously set for a command from being lost after a rename.

This currently isn't supported when multiple guild IDs are passed for declare_global_commands.

TYPE: typing.Optional[collections.Mapping[str, hikari.SnowflakeishOr[hikari.PartialCommand]]] DEFAULT: None

message_ids

If provided, a mapping of message context menu command names to the IDs of existing commands to update.

TYPE: typing.Optional[collections.Mapping[str, hikari.SnowflakeishOr[hikari.PartialCommand]]] DEFAULT: None

user_ids

If provided, a mapping of user context menu command names to the IDs of existing commands to update.

TYPE: typing.Optional[collections.Mapping[str, hikari.SnowflakeishOr[hikari.PartialCommand]]] DEFAULT: None

hooks() property #

Top level tanjun.abc.AnyHooks set for this client.

These are called during both message, menu and slash command execution.

interaction_accepts() property #

The types of interactions this client is executing.

is_human_only() property #

Whether this client is only executing for non-bot/webhook users messages.

menu_hooks() property #

Top level tanjun.abc.MenuHooks set for this client.

These are only called during menu command execution.

message_accepts() property #

Type of message create events this command client accepts for execution.

message_hooks() property #

Top level tanjun.abc.MessageHooks set for this client.

These are only called during message command execution.

on_autocomplete_interaction_request(interaction) async #

Execute a command autocomplete based on received REST requests.

PARAMETER DESCRIPTION
interaction

The interaction to execute autocomplete based on.

TYPE: hikari.AutocompleteInteraction

RETURNS DESCRIPTION
hikari.api.InteractionAutocompleteBuilder

The initial response to send back to Discord.

on_command_interaction_request(interaction) async #

Execute an app command based on received REST requests.

PARAMETER DESCRIPTION
interaction

The interaction to execute a command based on.

TYPE: hikari.CommandInteraction

RETURNS DESCRIPTION
hikari.api.InteractionMessageBuilder | hikari.api.InteractionDeferredBuilder

The initial response to send back to Discord.

on_gateway_autocomplete_create(interaction) async #

Execute command autocomplete based on a received gateway interaction create.

PARAMETER DESCRIPTION
interaction

The interaction to execute a command based on.

TYPE: hikari.AutocompleteInteraction

on_gateway_command_create(interaction) async #

Execute an app command based on a received gateway interaction create.

PARAMETER DESCRIPTION
interaction

The interaction to execute a command based on.

TYPE: hikari.CommandInteraction

on_interaction_create_event(event) async #

Handle a gateway interaction create event.

This will execute both application command and autocomplete interactions.

PARAMETER DESCRIPTION
event

The event to execute commands based on.

TYPE: hikari.InteractionCreateEvent

on_message_create_event(event) async #

Execute a message command based on a gateway event.

PARAMETER DESCRIPTION
event

The event to handle.

TYPE: hikari.MessageCreateEvent

open(*, register_listeners=True) async #

Start the client.

If mention_prefix was passed to tanjun.Client.init or tanjun.Client.from_gateway_bot then this function may make a fetch request to Discord if it cannot get the current user from the cache.

RAISES DESCRIPTION
RuntimeError

If the client is already active.

prefix_getter() property #

Prefix getter method set for this client.

For more information on this callback's signature see tanjun.clients.PrefixGetterSig.

prefixes() property #

Collection of the standard prefixes set for this client.

remove_check(check) #

Remove a check from the client.

PARAMETER DESCRIPTION
check

The check to remove.

TYPE: tanjun.CheckSig

RAISES DESCRIPTION
ValueError

If the check was not previously added.

remove_prefix(prefix) #

Remove a message content prefix from the client.

PARAMETER DESCRIPTION
prefix

The prefix to remove.

TYPE: str

RAISES DESCRIPTION
ValueError

If the prefix is not registered with the client.

RETURNS DESCRIPTION
Self

The client instance to enable chained calls.

set_auto_defer_after(time) #

Set when this client should automatically defer execution of commands.

Warning

If time is set to None then automatic deferrals will be disabled. This may lead to unexpected behaviour.

PARAMETER DESCRIPTION
time

The time in seconds to defer interaction command responses after.

TYPE: typing.Optional[float]

set_autocomplete_ctx_maker(maker=context.AutocompleteContext) #

Set the autocomplete context maker to use when creating contexts.

Warning

The caller must return an instance of tanjun.context.AutocompleteContext rather than just any implementation of the AutocompleteContext abc due to this client relying on implementation detail of tanjun.context.AutocompleteContext.

PARAMETER DESCRIPTION
maker

The autocomplete context maker to use.

This is a callback which should match the signature of tanjun.context.AutocompleteContext.init and return an instance of tanjun.context.AutocompleteContext.

TYPE: _AutocompleteContextMakerProto DEFAULT: context.AutocompleteContext

RETURNS DESCRIPTION
Self

This client to enable method chaining.

set_default_app_command_permissions(permissions) #

Set the default member permissions needed for this client's commands.

Warning

This may be overridden by guild staff and does not apply to admins.

PARAMETER DESCRIPTION
permissions

The default member permissions needed for this client's application commands.

This may be overridden by tanjun.abc.AppCommand.default_member_permissions and tanjun.abc.Component.default_app_cmd_permissions; if this is left as None then this config will be inherited from the parent client.

TYPE: typing.Union[int, hikari.Permissions]

RETURNS DESCRIPTION
Self

This client to enable method chaining.

set_dms_enabled_for_app_cmds(state) #

Set whether this clients's commands should be enabled in DMs.

PARAMETER DESCRIPTION
state

Whether to enable this client's commands in DMs.

This may be overridden by tanjun.abc.AppCommand.is_dm_enabled and tanjun.abc.Component.dms_enabled_for_app_cmds; if this is left as None then this config will be inherited from the parent client.

TYPE: bool

RETURNS DESCRIPTION
Self

This client to enable method chaining.

set_ephemeral_default(state) #

Set whether slash contexts spawned by this client should default to ephemeral responses.

This defaults to False if not explicitly set.

PARAMETER DESCRIPTION
state

Whether slash command contexts executed in this client should should default to ephemeral.

This will be overridden by any response calls which specify flags.

TYPE: bool

RETURNS DESCRIPTION
Self

This client to enable method chaining.

set_global_commands(*, application=None, guild=hikari.UNDEFINED, force=False) async #

Alias of [tanjun.Client.declare_global_commands][].

deprecated

Since v2.1.1a1; use [tanjun.Client.declare_global_commands][] instead.

set_hikari_trait_injectors(bot) #

Set type based dependency injection based on the hikari traits found in bot.

This is a short hand for calling [tanjun.Client.add_type_dependency][] for all the hikari trait types bot is valid for with bot.

PARAMETER DESCRIPTION
bot

The hikari client to set dependency injectors for.

TYPE: hikari.RESTAware

set_hooks(hooks) #

Set the general command execution hooks for this client.

The callbacks within this hook will be added to every slash and message command execution started by this client.

PARAMETER DESCRIPTION
hooks

The general command execution hooks to set for this client.

Passing None will remove all hooks.

TYPE: typing.Optional[tanjun.AnyHooks]

RETURNS DESCRIPTION
Self

The client instance to enable chained calls.

set_human_only(value=True) #

Set whether or not message commands execution should be limited to "human" users.

Note

This doesn't apply to interaction commands as these can only be triggered by a "human" (normal user account).

PARAMETER DESCRIPTION
value

Whether or not message commands execution should be limited to "human" users.

Passing True here will prevent message commands from being executed based on webhook and bot messages.

TYPE: bool DEFAULT: True

set_interaction_accepts(accepts) #

Set the kind of interactions this client should execute.

PARAMETER DESCRIPTION
accepts

Bitfield of the interaction types this client should execute.

TYPE: InteractionAcceptsEnum

RAISES DESCRIPTION
RuntimeError

If called while the client is running.

set_interaction_not_found(message) #

Set the response message for when an interaction command is not found.

Warning

Setting this to None may lead to unexpected behaviour (especially when the client is still set to auto-defer interactions) and should only be done if you know what you're doing.

PARAMETER DESCRIPTION
message

The message to respond with when an interaction command isn't found.

TYPE: typing.Optional[str]

set_menu_ctx_maker(maker=context.MenuContext) #

Set the autocomplete context maker to use when creating contexts.

Warning

The caller must return an instance of tanjun.context.MenuContext rather than just any implementation of the MenuContext abc due to this client relying on implementation detail of tanjun.context.MenuContext.

PARAMETER DESCRIPTION
maker

The autocomplete context maker to use.

This is a callback which should match the signature of tanjun.context.MenuContext.init and return an instance of tanjun.context.MenuContext.

TYPE: _MenuContextMakerProto DEFAULT: context.MenuContext

RETURNS DESCRIPTION
Self

This client to enable method chaining.

set_menu_hooks(hooks) #

Set the menu command execution hooks for this client.

The callbacks within this hook will be added to every menu command execution started by this client.

PARAMETER DESCRIPTION
hooks

The menu context specific command execution hooks to set for this client.

Passing None will remove the hooks.

TYPE: typing.Optional[tanjun.MenuHooks]

RETURNS DESCRIPTION
Self

The client instance to enable chained calls.

set_menu_not_found(message) #

Set the response message for when a menu command is not found.

Warning

Setting this to None may lead to unexpected behaviour (especially when the client is still set to auto-defer interactions) and should only be done if you know what you're doing.

PARAMETER DESCRIPTION
message

The message to respond with when a menu command isn't found.

TYPE: typing.Optional[str]

set_message_accepts(accepts) #

Set the kind of messages commands should be executed based on.

PARAMETER DESCRIPTION
accepts

The type of messages commands should be executed based on.

TYPE: MessageAcceptsEnum

RAISES DESCRIPTION
RuntimeError

If called while the client is running.

ValueError

If accepts is set to anything other than tanjun.clients.MessageAcceptsEnum.NONE when the client doesn't have a linked event manager.

set_message_ctx_maker(maker=context.MessageContext) #

Set the message context maker to use when creating context for a message.

Warning

The caller must return an instance of tanjun.context.MessageContext rather than just any implementation of the MessageContext abc due to this client relying on implementation detail of tanjun.context.MessageContext.

PARAMETER DESCRIPTION
maker

The message context maker to use.

This is a callback which should match the signature of tanjun.context.MessageContext.init and return an instance of tanjun.context.MessageContext.

TYPE: _MessageContextMakerProto DEFAULT: context.MessageContext

RETURNS DESCRIPTION
Self

This client to enable method chaining.

set_message_hooks(hooks) #

Set the message command execution hooks for this client.

The callbacks within this hook will be added to every message command execution started by this client.

PARAMETER DESCRIPTION
hooks

The message context specific command execution hooks to set for this client.

Passing None will remove all hooks.

TYPE: typing.Optional[tanjun.MessageHooks]

RETURNS DESCRIPTION
Self

The client instance to enable chained calls.

set_prefix_getter(getter) #

Set the callback used to retrieve message prefixes set for the relevant guild.

PARAMETER DESCRIPTION
getter

The callback which'll be used to retrieve prefixes for the guild a message context is from. If None is passed here then the callback will be unset.

This should be an async callback which one argument of type tanjun.abc.MessageContext and returns an iterable of string prefixes. Dependency injection is supported for this callback's keyword arguments.

TYPE: typing.Optional[PrefixGetterSig]

RETURNS DESCRIPTION
Self

The client instance to enable chained calls.

set_slash_ctx_maker(maker=context.SlashContext) #

Set the slash context maker to use when creating context for a slash command.

Warning

The caller must return an instance of tanjun.context.SlashContext rather than just any implementation of the SlashContext abc due to this client relying on implementation detail of tanjun.context.SlashContext.

PARAMETER DESCRIPTION
maker

The slash context maker to use.

This is a callback which should match the signature of tanjun.context.SlashContext.init and return an instance of tanjun.context.SlashContext.

TYPE: _SlashContextMakerProto DEFAULT: context.SlashContext

RETURNS DESCRIPTION
Self

This client to enable method chaining.

set_slash_hooks(hooks) #

Set the slash command execution hooks for this client.

The callbacks within this hook will be added to every slash command execution started by this client.

PARAMETER DESCRIPTION
hooks

The slash context specific command execution hooks to set for this client.

Passing None will remove the hooks.

TYPE: typing.Optional[tanjun.SlashHooks]

RETURNS DESCRIPTION
Self

The client instance to enable chained calls.

set_slash_not_found(message) #

Set the response message for when a slash command is not found.

Warning

Setting this to None may lead to unexpected behaviour (especially when the client is still set to auto-defer interactions) and should only be done if you know what you're doing.

PARAMETER DESCRIPTION
message

The message to respond with when a slash command isn't found.

TYPE: typing.Optional[str]

slash_hooks() property #

Top level tanjun.abc.SlashHooks set for this client.

These are only called during slash command execution.

with_check(check) #

Add a check to this client through a decorator call.

PARAMETER DESCRIPTION
check

The check to add. This may be either synchronous or asynchronous and must take one positional argument of type tanjun.abc.Context with dependency injection being supported for its keyword arguments.

TYPE: tanjun.abc.CheckSig

RETURNS DESCRIPTION
tanjun.abc.CheckSig

The added check.

with_prefix_getter(getter) #

Set the prefix getter callback for this client through decorator call.

Examples:

client = tanjun.Client.from_rest_bot(bot)

@client.with_prefix_getter
async def prefix_getter(ctx: tanjun.abc.MessageContext) -> collections.abc.Iterable[str]:
    raise NotImplementedError
PARAMETER DESCRIPTION
getter

The callback which'll be to retrieve prefixes for the guild a message event is from.

This should be an async callback which one argument of type tanjun.abc.MessageContext and returns an iterable of string prefixes. Dependency injection is supported for this callback's keyword arguments.

TYPE: PrefixGetterSig

RETURNS DESCRIPTION
PrefixGetterSig

The registered callback.

InteractionAcceptsEnum #

Bases: enum.IntFlag

The possible configurations for which interaction this client should execute.

ALL = AUTOCOMPLETE | COMMANDS class-attribute #

Execute all the interaction types Tanjun supports.

AUTOCOMPLETE = enum.auto() class-attribute #

Execute autocomplete interactions.

COMMANDS = enum.auto() class-attribute #

Execute command interactions.

This includes slash command and context menu calls.

NONE = 0 class-attribute #

Set the client to execute no interactions.

MessageAcceptsEnum #

Bases: str, enum.Enum

The possible configurations for which events tanjun.Client should execute commands based on.

ALL = 'ALL' class-attribute #

Set the client to execute commands based on both DM and guild message create events.

DM_ONLY = 'DM_ONLY' class-attribute #

Set the client to execute commands based only DM message create events.

GUILD_ONLY = 'GUILD_ONLY' class-attribute #

Set the client to execute commands based only guild message create events.

NONE = 'NONE' class-attribute #

Set the client to not execute commands based on message create events.

get_event_type() #

Get the base event type this mode listens to.

RETURNS DESCRIPTION
type[hikari.events.MessageCreateEvent] | None

The type object of the MessageCreateEvent class this mode will register a listener for.

This will be None if this mode disables listening to message create events.

as_loader(callback=None, /, *, standard_impl=True) #

Mark a callback as being used to load Tanjun components from a module.

Note

This is only necessary if you wish to use [tanjun.Client.load_modules][].

PARAMETER DESCRIPTION
callback

The callback used to load Tanjun components from a module.

This should take one argument of type tanjun.Client (or tanjun.abc.Client if standard_impl is False), return nothing and will be expected to initiate and add utilities such as components to the provided client.

TYPE: typing.Union[collections.Callable[[tanjun.Client], None], collections.Callable[[Client], None], None] DEFAULT: None

standard_impl

Whether this loader should only allow instances of tanjun.Client as opposed to tanjun.abc.Client.

TYPE: bool DEFAULT: True

RETURNS DESCRIPTION
collections.abc.Callable[[tanjun.abc.Client], None]]

The decorated load callback.

as_unloader(callback=None, /, *, standard_impl=True) #

Mark a callback as being used to unload a module's utilities from a client.

Note

This is the inverse of tanjun.as_loader and is only necessary if you wish to use the [tanjun.Client.unload_modules][] or [tanjun.Client.reload_modules][].

PARAMETER DESCRIPTION
callback

The callback used to unload Tanjun components from a module.

This should take one argument of type tanjun.Client (or tanjun.abc.Client if standard_impl is False), return nothing and will be expected to remove utilities such as components from the provided client.

TYPE: typing.Union[collections.Callable[[Client], None], collections.Callable[[tanjun.Client], None], None] DEFAULT: None

standard_impl

Whether this unloader should only allow instances of tanjun.Client as opposed to tanjun.abc.Client.

TYPE: bool DEFAULT: True

RETURNS DESCRIPTION
collections.abc.Callable[[tanjun.abc.Client], None]]

The decorated unload callback.

on_parser_error(ctx, error) async #

Handle message parser errors.

This is the default message parser error hook included by tanjun.Client.