Client¶
Bot¶
- class Bot(*, intents: IntentFlags, cache_settings: CacheSettings = <mizuki.cache.CacheSettings object>)¶
Bases:
objectRepresents 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 toCacheSettings()
- gateway: GatewayClient¶
The GatewayClient that manages the Gateway Connection.
- commands: CommandManager¶
The CommandManager used to manage Commands.
- 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.
- 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 ason_interaction_create. Defaults toNone- 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.
- 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:
objectCache Settings used to determine how cache is handles by a CacheStorage.
In the max limits of cache entries such as
CacheSettings.max_users_store,Nonerepresents infinite or no limit.- Parameters:
users (
bool, optional) – Toggle caching ofUserobjects. Defaults toTrue.messages (
bool, optional) – Toggle caching ofMessageobjects. Defaults toTrue.channels (
bool, optional) – Toggle caching ofPrivateChannel,ThreadChannelandGuildChannelobjects. Defaults toTrue.guilds (
bool, optional) – Toggle caching ofGuildobjects. Defaults toTrue.commands (
bool, optional) – Toggle caching ofApplicationCommandobjects. Defaults toTrue.cache_invalidation (
bool, optional) – Toggle if cache should be invalidated based on time. Defaults toFalse.invalidation_time (
timedelta, optional) – Determines how long a CacheEntry object can live without being invalidated. Defaults totimedelta(days=1).cleanup_interval (
timedelta, optional) – Determines how often the Cache will be cleaned up. Defaults totimedelta(hours=6).max_users_store (
int|None, optional) – Determines the max amount ofUserobjects the cache will store. Defaults toNone.max_messages_store (
int|None, optional) – Determines the max amount ofMessageobjects the cache will store. Defaults to2000.max_channels_store (
int|None, optional) – Determines the max amount ofPrivateChannel,ThreadChannelandGuildChannelobjects the cache will store. Defaults toNone.max_guilds_store (
int|None, optional) – Determines the max amount ofGuildobjects the cache will store. Defaults toNone.
- channels: bool¶
Whether
PrivateChannel,ThreadChannelandGuildChannelcaching is enabled.
- commands: bool¶
Whether
ApplicationCommandcaching is enabled.
- cache_invalidation: bool¶
Whether time-based cache invalidation is enabled, commands remain unaffected by this invalidation.
- max_channels_store: int | None¶
The max amount of
PrivateChannel,ThreadChannelandGuildChannelobjects 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_CONTENTandGUILD_MEMBERSare 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
IntentFlagsinstance with all intents enabled.
- classmethod standard() Self¶
Returns a
IntentFlagsinstance 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.