Client

Bot

class Bot(*, intents: IntentFlags, cache_settings: CacheSettings = <mizuki.cache.CacheSettings object>)

Bases: object

Represents a Discord Bot.

Parameters:
  • intents (IntentFlags) – The IntentFlags to be passed to the GatewayClient.

  • cache_settings (CacheSettings, optional) – The CacheSettings for managing the Cache System of the Bot instance. Defaults to CacheSettings()

gateway: GatewayClient

The GatewayClient that manages the Gateway Connection.

commands: CommandManager

The CommandManager used to manage Commands.

user: User

The User object of the bot.

intents: IntentFlags

The IntentFlags to be passed to the GatewayClient.

http: HTTPClient

The HTTPClient used for the REST API.

users: UserManager

The UserManager used to managers User objects.

messages: MessageManager

The MessageManager used to manage Message objects.

channels: ChannelManager

The ChannelManager used to manage Channel objects.

guilds: GuildManager

The GuildManager used to manage Guild objects.

run(token: str) None

A synchronous method to start a event loop and run the Bot.start() method.

Parameters:

token (str) – The bot token used to authenticate with discord. Do not prefix this, the library will handle prefixing.

Raises:

ImproperToken – An improper token was passed.

async start(token: str) None

Verifies the token and connects to the gateway.

Parameters:

token (str) – The bot token used to authenticate with discord. Do not prefix this, the library will handle prefixing.

Raises:

ImproperToken – An improper token was passed.

async stop() None

Disconnects the gateway and closes the session.

listen(event: Event | None = None) CoroDecorator

This function is a decotstor.

Registers an asynchronous listener for a gateway event.

Parameters:

event (Event | None, optional) – The Gateway Event to listen to. Defaults to name of function in format such as on_interaction_create. Defaults to None

Raises:

TypeError – The decorator was applied to a synchronous function.

Examples

Registering based on the function name:

@bot.listen()
async def on_message_create(message: mizuki.Message) -> None:
    ...

Explicitly passing event name:

@bot.listen(mizuki.Event.MESSAGE_CREATE)
async def can_be_named_anything(message: mizuki.Message) -> None:
    ...
setup() CoroDecorator

This function is a decorator.

Registers a setup hook which runs once after connecting to the gateway.

Raises:

TypeError – The decorator was applied to a synchronous function.

command(*, guild_id: int, name: str, name_localizations: Localization = _MISSING, description: str, description_localizations: Localization = _MISSING, default_member_permissions: Permissions = _MISSING, nsfw: bool = False) CoroDecorator
command(*, name: str, name_localizations: Localization = _MISSING, description: str, description_localizations: Localization = _MISSING, default_member_permissions: Permissions = _MISSING, integration_types: list[ApplicationIntegrationType] = _MISSING, contexts: list[InteractionContextType] = _MISSING, nsfw: bool = False) CoroDecorator

This function is a decorator.

Registers a command callback for a slash (application) command.

Parameters:
  • name (str) – The name of the application command.

  • description (str, optional) – The description of the application command.

Raises:

TypeError – The decorator was applied to a synchronous function.

class CacheSettings(users: bool = True, messages: bool = True, channels: bool = True, guilds: bool = True, commands: bool = True, cache_invalidation: bool = False, invalidation_time: timedelta = datetime.timedelta(days=1), cleanup_interval: timedelta = datetime.timedelta(seconds=21600), max_users_store: int | None = None, max_messages_store: int | None = 2000, max_channels_store: int | None = None, max_guilds_store: int | None = None)

Bases: object

Cache Settings used to determine how cache is handles by a CacheStorage.

In the max limits of cache entries such as CacheSettings.max_users_store, None represents infinite or no limit.

Parameters:
  • users (bool, optional) – Toggle caching of User objects. Defaults to True.

  • messages (bool, optional) – Toggle caching of Message objects. Defaults to True.

  • channels (bool, optional) – Toggle caching of PrivateChannel, ThreadChannel and GuildChannel objects. Defaults to True.

  • guilds (bool, optional) – Toggle caching of Guild objects. Defaults to True.

  • commands (bool, optional) – Toggle caching of ApplicationCommand objects. Defaults to True.

  • cache_invalidation (bool, optional) – Toggle if cache should be invalidated based on time. Defaults to False.

  • invalidation_time (timedelta, optional) – Determines how long a CacheEntry object can live without being invalidated. Defaults to timedelta(days=1).

  • cleanup_interval (timedelta, optional) – Determines how often the Cache will be cleaned up. Defaults to timedelta(hours=6).

  • max_users_store (int | None, optional) – Determines the max amount of User objects the cache will store. Defaults to None.

  • max_messages_store (int | None, optional) – Determines the max amount of Message objects the cache will store. Defaults to 2000.

  • max_channels_store (int | None, optional) – Determines the max amount of PrivateChannel, ThreadChannel and GuildChannel objects the cache will store. Defaults to None.

  • max_guilds_store (int | None, optional) – Determines the max amount of Guild objects the cache will store. Defaults to None.

users: bool

Whether User caching is enabled.

messages: bool

Whether Message caching is enabled.

channels: bool

Whether PrivateChannel, ThreadChannel and GuildChannel caching is enabled.

guilds: bool

Whether Guild caching is enabled.

commands: bool

Whether ApplicationCommand caching is enabled.

cache_invalidation: bool

Whether time-based cache invalidation is enabled, commands remain unaffected by this invalidation.

invalidation_time: timedelta

The amount of time a cach can live, before being invalidated.

cleanup_interval: timedelta

The interval at which the cleanup tasks will happen.

max_users_store: int | None

The max amount of User objects the cache will store.

max_messages_store: int | None

The max amount of Message objects the cache will store.

max_channels_store: int | None

The max amount of PrivateChannel, ThreadChannel and GuildChannel objects the cache will store.

max_guilds_store: int | None

The max amount of Guild objects the cache will store.

class IntentFlags(*values)

A bitfield of IntentFlags to be provided to Discord Gateway. These determine which events you will be sent over the gateway. Read more about it on Gateway Intents.

Note that GUILD_PRESENCES, MESSAGE_CONTENT and GUILD_MEMBERS are privileged intents and need to be enabled in the Developer Portal to use.

GUILDS = 1
GUILD_MEMBERS = 2
GUILD_MODERATION = 4
GUILD_EXPRESSIONS = 8
GUILD_INTEGRATIONS = 16
GUILD_WEBHOOKS = 32
GUILD_INVITES = 64
GUILD_VOICE_STATUS = 128
GUILD_PRESENCES = 256
GUILD_MESSAGES = 512
GUILD_MESSAGE_REACTIONS = 1024
GUILD_MESSAGE_TYPING = 2048
DIRECT_MESSAGES = 4096
DIRECT_MESSAGE_REACTIONS = 8192
DIRECT_MESSAGE_TYPING = 16384
MESSAGE_CONTENT = 32768
GUILD_SCHEDULED_EVENTS = 65536
AUTO_MODERATION_CONFIGURATION = 1048576
AUTO_MODERATION_EXECUTION = 2097152
GUILD_MESSAGE_POLLS = 16777216
DIRECT_MESSAGE_POLLS = 33554432
classmethod all() Self

Returns a IntentFlags instance with all intents enabled.

classmethod standard() Self

Returns a IntentFlags instance with only non-privileged intents enabled.

Events

class Event(*values)

The Event enum to be provided in Bot.listen().

GUILD_CREATE = 'on_guild_create'

Dispatched when a guild is created or the bot joins a guild.

GUILD_UPDATE = 'on_guild_update'

Dispatched when a guild is updated.

GUILD_DELETE = 'on_guild_delete'

Dispatched when a guild is deleted or the bot leaves a guild.

CHANNEL_CREATE = 'on_channel_create'

Dispatched when a channel is created.

CHANNEL_UPDATE = 'on_channel_update'

Dispatched when a channel is updated.

CHANNEL_DELETE = 'on_channel_delete'

Dispatched when a channel is deleted.

THREAD_CREATE = 'on_thread_create'

Dispatched when a thread is created.

THREAD_UPDATE = 'on_thread_update'

Dispatched when a thread is updated.

THREAD_DELETE = 'on_thread_delete'

Dispatched when a thread is deleted.

INTERACTION_CREATE = 'on_interaction_create'

Dispatched when an interaction is created.

READY = 'on_ready'

Dispatched when the gateway is ready to send new events.