Skip to content

Client

Client #

Client(
    app: RESTTraits | GatewayTraits,
    model: Any = None,
    *,
    tracked_guilds: Sequence[Snowflakeish] | None = None,
    default_guild: Snowflakeish | None = None,
    update_commands: bool = True,
    allow_unknown_interactions: bool = False,
    command_hooks: list[CommandHookCallbackT] | None = None,
    command_after_hooks: list[CommandHookCallbackT]
    | None = None,
    event_hooks: list[EventHookCallbackT[hk_Event]]
    | None = None,
    event_after_hooks: list[EventHookCallbackT[hk_Event]]
    | None = None
)

The client object is a wrapper around your bot that lets you use Crescent's features.

Example#
import hikari
import crescent

bot = hikari.GatewayBot("your token")
client = crescent.Client(bot)

# Crescent's features can be used.
@client.include
@crescent.command
async def ping(ctx: crescent.Context):
    await ctx.respong("Pong")

bot.run()
PARAMETER DESCRIPTION
app

The hikari bot instance.

TYPE: RESTTraits | GatewayTraits

model

An object to store global data. This object can be accessed with the Plugin.model property.

Example#
# In bot.py
bot = hikari.GatewayBot("your token")
client = crescent.Client(bot, "I am a model")

client.plugins.load("plugin")

# In plugin.py
plugin = crescent.Plugin()

@plugin.on_load
def on_load():
    # Print the model object that was set earlier to the console.
    print(plugin.model)  # prints "I am a model"

If no model is set, the model will default to None.

TYPE: Any DEFAULT: None

tracked_guilds

The guilds to compare posted commands to. Commands will not be automatically removed from guilds that aren't in this list. This should be kept to as little guilds as possible to prevent rate limits.

TYPE: Sequence[Snowflakeish] | None DEFAULT: None

default_guild

The guild to post application commands to by default. If this is None, slash commands will be posted globally.

TYPE: Snowflakeish | None DEFAULT: None

update_commands

If True or not specified, update commands when the bot starts. Only works for gateway-based bots.

TYPE: bool DEFAULT: True

command_hooks

List of hooks to run before all commands.

TYPE: list[CommandHookCallbackT] | None DEFAULT: None

command_after_hooks

List of hooks to run after all commands.

TYPE: list[CommandHookCallbackT] | None DEFAULT: None

commands property #

commands: CommandHandler

Return the command handler object. This object lets you access command information that is not normally accessible. See CommandHandler for more information.

plugins property #

plugins: PluginManager

Return the plugin manager object. This object lets you load and unload plugins. See PluginManager for more information.

include #

include(
    obj: INCLUDABLE | None = None,
) -> INCLUDABLE | Callable[[INCLUDABLE], INCLUDABLE]

Register an includable object, such as an event or command handler.

Example#
client = crescent.Client(...)

@client.include
@crescent.command
async def ping(ctx: crescent.Context):
    await ctx.respong("Pong")

on_crescent_autocomplete_error async #

on_crescent_autocomplete_error(
    exc: Exception,
    ctx: AutocompleteContext,
    option: AutocompleteInteractionOption,
    was_handled: bool,
) -> None

This function is run when there is an error in an autocomplete handler that is not caught with any error handlers. You can inherit from this class and override this function to change default error handling.

on_crescent_command_error async #

on_crescent_command_error(
    exc: Exception, ctx: Context, was_handled: bool
) -> None

This function is run when there is an error in a crescent command that is not caught with any error handlers. You can inherit from this class and override this function to change default error handling.

on_crescent_event_error async #

on_crescent_event_error(
    exc: Exception, event: hk_Event, was_handled: bool
) -> None

This function is run when there is an error in a crescent event that is not caught with any error handlers. You can inherit from this class and override this function to change default error handling.

GatewayTraits #

Bases: EventManagerAware, RESTAware, Protocol

The traits crescent requires for a gateway-based bot.

RESTTraits #

Bases: InteractionServerAware, RESTAware, Protocol

The base traits crescents requires for a REST-based bot.