Events that fire when something occurs within a guild.

This module

Expand source code
Browse git
# -*- coding: utf-8 -*-
# cython: language_level=3
# Copyright (c) 2020 Nekokatt
# Copyright (c) 2021-present davfsa
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
"""Events that fire when something occurs within a guild."""

from __future__ import annotations

__all__: typing.List[str] = [
    "GuildEvent",
    "GuildVisibilityEvent",
    "GuildAvailableEvent",
    "GuildJoinEvent",
    "GuildUnavailableEvent",
    "GuildLeaveEvent",
    "GuildUpdateEvent",
    "BanEvent",
    "BanCreateEvent",
    "BanDeleteEvent",
    "EmojisUpdateEvent",
    "IntegrationEvent",
    "IntegrationCreateEvent",
    "IntegrationDeleteEvent",
    "IntegrationUpdateEvent",
    "PresenceUpdateEvent",
]

import abc
import typing

import attr

from hikari import intents
from hikari import traits
from hikari.events import base_events
from hikari.events import shard_events
from hikari.internal import attr_extensions

if typing.TYPE_CHECKING:
    from hikari import channels as channels_
    from hikari import emojis as emojis_
    from hikari import guilds
    from hikari import presences as presences_
    from hikari import snowflakes
    from hikari import users
    from hikari import voices
    from hikari.api import shard as gateway_shard


@base_events.requires_intents(
    intents.Intents.GUILDS, intents.Intents.GUILD_BANS, intents.Intents.GUILD_EMOJIS, intents.Intents.GUILD_PRESENCES
)
class GuildEvent(shard_events.ShardEvent, abc.ABC):
    """Event base for any guild-bound event."""

    __slots__: typing.Sequence[str] = ()

    @property
    @abc.abstractmethod
    def guild_id(self) -> snowflakes.Snowflake:
        """ID of the guild that this event relates to.

        Returns
        -------
        hikari.snowflakes.Snowflake
            The ID of the guild that relates to this event.
        """

    async def fetch_guild(self) -> guilds.RESTGuild:
        """Perform an API call to get the guild that this event relates to.

        Returns
        -------
        hikari.guilds.RESTGuild
            The guild this event occurred in.
        """
        return await self.app.rest.fetch_guild(self.guild_id)

    async def fetch_guild_preview(self) -> guilds.GuildPreview:
        """Perform an API call to get the preview of the event's guild.

        Returns
        -------
        hikari.guilds.GuildPreview
            The preview of the guild this event occurred in.
        """
        return await self.app.rest.fetch_guild_preview(self.guild_id)

    def get_guild(self) -> typing.Optional[guilds.GatewayGuild]:
        """Get the cached guild that this event relates to, if known.

        If not known, this will return `builtins.None` instead.

        Returns
        -------
        typing.Optional[hikari.guilds.GatewayGuild]
            The guild this event relates to, or `builtins.None` if not known.
        """
        if not isinstance(self.app, traits.CacheAware):
            return None

        return self.app.cache.get_available_guild(self.guild_id) or self.app.cache.get_unavailable_guild(self.guild_id)


@base_events.requires_intents(intents.Intents.GUILDS)
class GuildVisibilityEvent(GuildEvent, abc.ABC):
    """Event base for any event that changes the visibility of a guild.

    This includes when a guild becomes available after an outage, when a
    guild becomes available on startup, when a guild becomes unavailable due
    to an outage, when the user is kicked/banned/leaves a guild, or when
    the user joins a new guild.
    """

    __slots__: typing.Sequence[str] = ()


@attr_extensions.with_copy
@attr.define(kw_only=True, weakref_slot=False)
@base_events.requires_intents(intents.Intents.GUILDS)
class GuildAvailableEvent(GuildVisibilityEvent):
    """Event fired when a guild becomes available.

    This will occur on startup or after outages.

    !!! note
        Some fields like `members` and `presences` are included here but not on
        the other `GuildUpdateEvent` and `GuildUnavailableEvent` guild visibility
        event models.
    """

    shard: gateway_shard.GatewayShard = attr.field(metadata={attr_extensions.SKIP_DEEP_COPY: True})
    # <<inherited docstring from ShardEvent>>.

    guild: guilds.GatewayGuild = attr.field()
    """Guild that just became available.

    Returns
    -------
    hikari.guilds.Guild
        The guild that relates to this event.
    """

    emojis: typing.Mapping[snowflakes.Snowflake, emojis_.KnownCustomEmoji] = attr.field(repr=False)
    """Mapping of emoji IDs to the emojis in the guild.

    Returns
    -------
    typing.Mapping[hikari.snowflakes.Snowflake, hikari.emojis.KnownCustomEmoji]
        The emojis in the guild.
    """

    roles: typing.Mapping[snowflakes.Snowflake, guilds.Role] = attr.field(repr=False)
    """Mapping of role IDs to the roles in the guild.

    Returns
    -------
    typing.Mapping[hikari.snowflakes.Snowflake, hikari.guilds.Role]
        The roles in the guild.
    """

    channels: typing.Mapping[snowflakes.Snowflake, channels_.GuildChannel] = attr.field(repr=False)
    """Mapping of channel IDs to the channels in the guild.

    Returns
    -------
    typing.Mapping[hikari.snowflakes.Snowflake, hikari.channels.GuildChannel]
        The channels in the guild.
    """

    members: typing.Mapping[snowflakes.Snowflake, guilds.Member] = attr.field(repr=False)
    """Mapping of user IDs to the members in the guild.

    Returns
    -------
    typing.Mapping[hikari.snowflakes.Snowflake, hikari.guilds.Member]
        The members in the guild.
    """

    presences: typing.Mapping[snowflakes.Snowflake, presences_.MemberPresence] = attr.field(repr=False)
    """Mapping of user IDs to the presences for the guild.

    Returns
    -------
    typing.Mapping[hikari.snowflakes.Snowflake, hikari.presences.MemberPresence]
        The member presences in the guild.
    """

    voice_states: typing.Mapping[snowflakes.Snowflake, voices.VoiceState] = attr.field(repr=False)
    """Mapping of user IDs to the voice states active in this guild.

    Returns
    -------
    typing.Mapping[hikari.snowflakes.Snowflake, hikari.voices.VoiceState]
        The voice states active in the guild.
    """

    chunk_nonce: typing.Optional[str] = attr.field(repr=False, default=None)
    """Nonce used to request the member chunks for this guild.

    This will be `builtins.None` if no chunks were requested.

    !!! note
        This is a synthetic field.

    Returns
    -------
    typing.Optional[builtins.str]
        The nonce used to request the member chunks.
    """

    @property
    def app(self) -> traits.RESTAware:
        # <<inherited docstring from Event>>.
        return self.guild.app

    @property
    def guild_id(self) -> snowflakes.Snowflake:
        # <<inherited docstring from GuildEvent>>.
        return self.guild.id


@attr_extensions.with_copy
@attr.define(kw_only=True, weakref_slot=False)
@base_events.requires_intents(intents.Intents.GUILDS)
class GuildJoinEvent(GuildVisibilityEvent):
    """Event fired when the bot joins a new guild.

    !!! note
        Some fields like `members` and `presences` are included here but not on
        the other `GuildUpdateEvent` and `GuildUnavailableEvent` guild visibility
        event models.
    """

    shard: gateway_shard.GatewayShard = attr.field(metadata={attr_extensions.SKIP_DEEP_COPY: True})
    # <<inherited docstring from ShardEvent>>.

    guild: guilds.GatewayGuild = attr.field()
    """The guild the bot just joined."""

    emojis: typing.Mapping[snowflakes.Snowflake, emojis_.KnownCustomEmoji] = attr.field(repr=False)
    """Mapping of emoji IDs to the emojis in the guild."""

    roles: typing.Mapping[snowflakes.Snowflake, guilds.Role] = attr.field(repr=False)
    """Mapping of role IDs to the roles in the guild."""

    channels: typing.Mapping[snowflakes.Snowflake, channels_.GuildChannel] = attr.field(repr=False)
    """Mapping of channel IDs to the channels in the guild."""

    members: typing.Mapping[snowflakes.Snowflake, guilds.Member] = attr.field(repr=False)
    """Mapping of user IDs to the members in the guild."""

    presences: typing.Mapping[snowflakes.Snowflake, presences_.MemberPresence] = attr.field(repr=False)
    """Mapping of user IDs to the presences for the guild."""

    voice_states: typing.Mapping[snowflakes.Snowflake, voices.VoiceState] = attr.field(repr=False)
    """Mapping of user IDs to the voice states active in this guild."""

    chunk_nonce: typing.Optional[str] = attr.field(repr=False, default=None)
    """Nonce used to request the member chunks for this guild.

    This will be `builtins.None` if no chunks were requested.

    !!! note
        This is a synthetic field.
    """

    @property
    def app(self) -> traits.RESTAware:
        # <<inherited docstring from Event>>.
        return self.guild.app

    @property
    def guild_id(self) -> snowflakes.Snowflake:
        # <<inherited docstring from GuildEvent>>.
        return self.guild.id


@attr_extensions.with_copy
@attr.define(kw_only=True, weakref_slot=False)
@base_events.requires_intents(intents.Intents.GUILDS)
class GuildLeaveEvent(GuildVisibilityEvent):
    """Event fired when the bot is banned/kicked/leaves a guild.

    This will also fire if the guild was deleted.
    """

    app: traits.RESTAware = attr.field(metadata={attr_extensions.SKIP_DEEP_COPY: True})
    # <<inherited docstring from Event>>.

    shard: gateway_shard.GatewayShard = attr.field(metadata={attr_extensions.SKIP_DEEP_COPY: True})
    # <<inherited docstring from ShardEvent>>.

    guild_id: snowflakes.Snowflake = attr.field()
    # <<inherited docstring from GuildEvent>>.

    old_guild: typing.Optional[guilds.GatewayGuild] = attr.field()
    """The old guild object.

    This will be `builtins.None` if the guild missing from the cache.
    """

    if typing.TYPE_CHECKING:
        # This should always fail.
        async def fetch_guild(self) -> typing.NoReturn:
            ...


@attr_extensions.with_copy
@attr.define(kw_only=True, weakref_slot=False)
@base_events.requires_intents(intents.Intents.GUILDS)
class GuildUnavailableEvent(GuildVisibilityEvent):
    """Event fired when a guild becomes unavailable because of an outage."""

    app: traits.RESTAware = attr.field(metadata={attr_extensions.SKIP_DEEP_COPY: True})
    # <<inherited docstring from Event>>.

    shard: gateway_shard.GatewayShard = attr.field(metadata={attr_extensions.SKIP_DEEP_COPY: True})
    # <<inherited docstring from ShardEvent>>.

    guild_id: snowflakes.Snowflake = attr.field()
    # <<inherited docstring from GuildEvent>>.


@attr_extensions.with_copy
@attr.define(kw_only=True, weakref_slot=False)
@base_events.requires_intents(intents.Intents.GUILDS)
class GuildUpdateEvent(GuildEvent):
    """Event fired when an existing guild is updated."""

    shard: gateway_shard.GatewayShard = attr.field(metadata={attr_extensions.SKIP_DEEP_COPY: True})
    # <<inherited docstring from ShardEvent>>.

    old_guild: typing.Optional[guilds.GatewayGuild] = attr.field()
    """The old guild object.

    This will be `builtins.None` if the guild missing from the cache.
    """

    guild: guilds.GatewayGuild = attr.field()
    """Guild that was just updated.

    Returns
    -------
    hikari.guilds.Guild
        The guild that relates to this event.
    """

    emojis: typing.Mapping[snowflakes.Snowflake, emojis_.KnownCustomEmoji] = attr.field(repr=False)
    """Mapping of emoji IDs to the emojis in the guild.

    Returns
    -------
    typing.Mapping[hikari.snowflakes.Snowflake, hikari.emojis.KnownCustomEmoji]
        The emojis in the guild.
    """

    roles: typing.Mapping[snowflakes.Snowflake, guilds.Role] = attr.field(repr=False)
    """Mapping of role IDs to the roles in the guild.

    Returns
    -------
    typing.Mapping[hikari.snowflakes.Snowflake, hikari.guilds.Role]
        The roles in the guild.
    """

    @property
    def app(self) -> traits.RESTAware:
        # <<inherited docstring from Event>>.
        return self.guild.app

    @property
    def guild_id(self) -> snowflakes.Snowflake:
        # <<inherited docstring from GuildEvent>>.
        return self.guild.id


@base_events.requires_intents(intents.Intents.GUILD_BANS)
class BanEvent(GuildEvent, abc.ABC):
    """Event base for any guild ban or unban."""

    __slots__: typing.Sequence[str] = ()

    @property
    def app(self) -> traits.RESTAware:
        # <<inherited docstring from Event>>.
        return self.user.app

    @property
    @abc.abstractmethod
    def user(self) -> users.User:
        """User that this ban event affects.

        Returns
        -------
        hikari.users.User
            The user that this event concerns.
        """

    async def fetch_user(self) -> users.User:
        """Perform an API call to fetch the user this ban event affects.

        Returns
        -------
        hikari.users.User
            The user affected by this event.
        """
        return await self.app.rest.fetch_user(self.user)


@attr_extensions.with_copy
@attr.define(kw_only=True, weakref_slot=False)
@base_events.requires_intents(intents.Intents.GUILD_BANS)
class BanCreateEvent(BanEvent):
    """Event that is fired when a user is banned from a guild."""

    shard: gateway_shard.GatewayShard = attr.field(metadata={attr_extensions.SKIP_DEEP_COPY: True})
    # <<inherited docstring from ShardEvent>>.

    guild_id: snowflakes.Snowflake = attr.field()
    # <<inherited docstring from GuildEvent>>.

    user: users.User = attr.field()
    # <<inherited docstring from BanEvent>>.

    @property
    def user_id(self) -> snowflakes.Snowflake:
        """User ID of the user that got banned.

        Returns
        -------
        hikari.snowflakes.Snowflake
            ID of the user the event concerns.
        """
        return self.user.id

    async def fetch_ban(self) -> guilds.GuildBan:
        """Perform an API call to fetch the details about this ban.

        This will include the optionally defined audit log reason for the
        ban.

        Returns
        -------
        hikari.guilds.GuildBan
            The ban details.
        """
        return await self.app.rest.fetch_ban(self.guild_id, self.user)


@attr_extensions.with_copy
@attr.define(kw_only=True, weakref_slot=False)
@base_events.requires_intents(intents.Intents.GUILD_BANS)
class BanDeleteEvent(BanEvent):
    """Event that is fired when a user is unbanned from a guild."""

    shard: gateway_shard.GatewayShard = attr.field(metadata={attr_extensions.SKIP_DEEP_COPY: True})
    # <<inherited docstring from ShardEvent>>.

    guild_id: snowflakes.Snowflake = attr.field()
    # <<inherited docstring from GuildEvent>>.

    user: users.User = attr.field()
    # <<inherited docstring from BanEvent>>.


@attr_extensions.with_copy
@attr.define(kw_only=True, weakref_slot=False)
@base_events.requires_intents(intents.Intents.GUILD_EMOJIS)
class EmojisUpdateEvent(GuildEvent):
    """Event that is fired when the emojis in a guild are updated."""

    app: traits.RESTAware = attr.field(metadata={attr_extensions.SKIP_DEEP_COPY: True})
    # <<inherited docstring from Event>>.

    shard: gateway_shard.GatewayShard = attr.field(metadata={attr_extensions.SKIP_DEEP_COPY: True})
    # <<inherited docstring from ShardEvent>>.

    guild_id: snowflakes.Snowflake = attr.field()
    # <<inherited docstring from GuildEvent>>.

    old_emojis: typing.Optional[typing.Sequence[emojis_.KnownCustomEmoji]] = attr.field()
    """Sequence of all old emojis in this guild.

    This will be `builtins.None` if it's missing from the cache.
    """

    emojis: typing.Sequence[emojis_.KnownCustomEmoji] = attr.field()
    """Sequence of all emojis in this guild.

    Returns
    -------
    typing.Sequence[emojis_.KnownCustomEmoji]
        All emojis in the guild.
    """

    async def fetch_emojis(self) -> typing.Sequence[emojis_.KnownCustomEmoji]:
        """Perform an API call to retrieve an up-to-date view of the emojis.

        Returns
        -------
        typing.Sequence[emojis_.KnownCustomEmoji]
            All emojis in the guild.
        """
        return await self.app.rest.fetch_guild_emojis(self.guild_id)


@base_events.requires_intents(intents.Intents.GUILD_INTEGRATIONS)
class IntegrationEvent(GuildEvent, abc.ABC):
    """Event base for any integration related events."""

    __slots__: typing.Sequence[str] = ()

    @property
    @abc.abstractmethod
    def application_id(self) -> typing.Optional[snowflakes.Snowflake]:
        """ID of Discord bot application this integration is connected to.

        Returns
        -------
        typing.Optional[hikari.snowflakes.Snowflake]
            The ID of Discord bot application this integration is connected to.
        """

    @property
    @abc.abstractmethod
    def id(self) -> snowflakes.Snowflake:
        """ID of the integration.

        Returns
        -------
        hikari.snowflakes.Snowflake
            The ID of the integration.
        """

    async def fetch_integrations(self) -> typing.Sequence[guilds.Integration]:
        """Perform an API call to fetch some number of guild integrations.

        !!! warning
            The results of this are not clearly defined by Discord. The current
            behaviour appears to be that only the first 50 integrations actually
            get returned. Discord have made it clear that they are not willing
            to fix this in
            https://github.com/discord/discord-api-docs/issues/1990.

        Returns
        -------
        typing.Sequence[hikari.guilds.Integration]
            Some possibly random subset of the integrations in a guild,
            probably.
        """
        return await self.app.rest.fetch_integrations(self.guild_id)


@attr_extensions.with_copy
@attr.define(kw_only=True, weakref_slot=False)
@base_events.requires_intents(intents.Intents.GUILD_INTEGRATIONS)
class IntegrationCreateEvent(IntegrationEvent):
    """Event that is fired when an integration is created in a guild."""

    app: traits.RESTAware = attr.field(metadata={attr_extensions.SKIP_DEEP_COPY: True})
    # <<inherited docstring from Event>>.

    shard: gateway_shard.GatewayShard = attr.field(metadata={attr_extensions.SKIP_DEEP_COPY: True})
    # <<inherited docstring from ShardEvent>>.

    integration: guilds.Integration = attr.field()
    """Integration that was created."""

    @property
    def application_id(self) -> typing.Optional[snowflakes.Snowflake]:
        # <<inherited docstring from IntegrationEvent>>.
        return self.integration.application.id if self.integration.application else None

    @property
    def guild_id(self) -> snowflakes.Snowflake:
        # <<inherited docstring from ShardEvent>>.
        return self.integration.guild_id

    @property
    def id(self) -> snowflakes.Snowflake:
        # <<inherited docstring from IntegrationEvent>>
        return self.integration.id


@attr_extensions.with_copy
@attr.define(kw_only=True, weakref_slot=False)
@base_events.requires_intents(intents.Intents.GUILD_INTEGRATIONS)
class IntegrationDeleteEvent(IntegrationEvent):
    """Event that is fired when an integration is deleted in a guild."""

    app: traits.RESTAware = attr.field(metadata={attr_extensions.SKIP_DEEP_COPY: True})
    # <<inherited docstring from Event>>.

    shard: gateway_shard.GatewayShard = attr.field(metadata={attr_extensions.SKIP_DEEP_COPY: True})
    # <<inherited docstring from ShardEvent>>.

    application_id: typing.Optional[snowflakes.Snowflake] = attr.field()
    # <<inherited docstring from IntegrationEvent>>.

    guild_id: snowflakes.Snowflake = attr.field()
    # <<inherited docstring from ShardEvent>>.

    id: snowflakes.Snowflake = attr.field()
    # <<inherited docstring from IntegrationEvent>>


@attr_extensions.with_copy
@attr.define(kw_only=True, weakref_slot=False)
@base_events.requires_intents(intents.Intents.GUILD_INTEGRATIONS)
class IntegrationUpdateEvent(IntegrationEvent):
    """Event that is fired when an integration is updated in a guild."""

    app: traits.RESTAware = attr.field(metadata={attr_extensions.SKIP_DEEP_COPY: True})
    # <<inherited docstring from Event>>.

    shard: gateway_shard.GatewayShard = attr.field(metadata={attr_extensions.SKIP_DEEP_COPY: True})
    # <<inherited docstring from ShardEvent>>.

    integration: guilds.Integration = attr.field()
    """Integration that was updated."""

    @property
    def application_id(self) -> typing.Optional[snowflakes.Snowflake]:
        # <<inherited docstring from IntegrationEvent>>.
        return self.integration.application.id if self.integration.application else None

    @property
    def guild_id(self) -> snowflakes.Snowflake:
        # <<inherited docstring from GuildEvent>>.
        return self.integration.guild_id

    @property
    def id(self) -> snowflakes.Snowflake:
        # <<inherited docstring from IntegrationEvent>>
        return self.integration.id


@attr_extensions.with_copy
@attr.define(kw_only=True, weakref_slot=False)
@base_events.requires_intents(intents.Intents.GUILD_PRESENCES)
class PresenceUpdateEvent(shard_events.ShardEvent):
    """Event fired when a user in a guild updates their presence in a guild.

    Sent when a guild member changes their presence in a specific guild.

    If the user is changed (e.g. new username), then this may fire many times
    (once for every guild the bot is part of). This is a limitation of how
    Discord implements their event system, unfortunately.

    Furthermore, if the target user is a bot and the bot only updates their
    presence on specific shards, this will only fire for the corresponding
    shards that saw the presence update.
    """

    shard: gateway_shard.GatewayShard = attr.field(metadata={attr_extensions.SKIP_DEEP_COPY: True})
    # <<inherited docstring from ShardEvent>>.

    old_presence: typing.Optional[presences_.MemberPresence] = attr.field()
    """The old member presence object.

    This will be `builtins.None` if the member presence missing from the cache.
    """

    presence: presences_.MemberPresence = attr.field()
    """Member presence.

    Returns
    -------
    hikari.presences.MemberPresence
        Presence for the user in this guild.
    """

    user: typing.Optional[users.PartialUser] = attr.field()
    """User that was updated.

    This is a partial user object that only contains the fields that were
    updated on the user profile.

    Will be `builtins.None` if the user itself did not change.
    This is always the case if the user only updated their member
    representation and did not change their user profile directly.

    Returns
    -------
    typing.Optional[hikari.users.PartialUser]
        The partial user containing the updated fields.
    """

    @property
    def app(self) -> traits.RESTAware:
        # <<inherited docstring from Event>>.
        return self.presence.app

    @property
    def user_id(self) -> snowflakes.Snowflake:
        """User ID of the user that updated their presence.

        Returns
        -------
        hikari.snowflakes.Snowflake
            ID of the user the event concerns.
        """
        return self.presence.user_id

    @property
    def guild_id(self) -> snowflakes.Snowflake:
        """Guild ID that the presence was updated in.

        Returns
        -------
        hikari.snowflakes.Snowflake
            ID of the guild the event occurred in.
        """
        return self.presence.guild_id

    def get_user(self) -> typing.Optional[users.User]:
        """Get the full cached user, if it is available.

        Returns
        -------
        typing.Optional[hikari.users.User]
            The full cached user, or `builtins.None` if not cached.
        """
        if not isinstance(self.app, traits.CacheAware):
            return None

        return self.app.cache.get_user(self.user_id)

    async def fetch_user(self) -> users.User:
        """Perform an API call to fetch the user this event concerns.

        Returns
        -------
        hikari.users.User
            The user affected by this event.
        """
        return await self.app.rest.fetch_user(self.user_id)

Classes

dataclass BanCreateEvent

class BanCreateEvent (
    *,
    shard: gateway_shard.GatewayShard,
    guild_id: snowflakes.Snowflake,
    user: users.User,
): ...

Event that is fired when a user is banned from a guild.

This requires one of the following combinations of intents in order to be dispatched:

Method generated by attrs for class BanCreateEvent.

Expand source code
Browse git
class BanCreateEvent(BanEvent):
    """Event that is fired when a user is banned from a guild."""

    shard: gateway_shard.GatewayShard = attr.field(metadata={attr_extensions.SKIP_DEEP_COPY: True})
    # <<inherited docstring from ShardEvent>>.

    guild_id: snowflakes.Snowflake = attr.field()
    # <<inherited docstring from GuildEvent>>.

    user: users.User = attr.field()
    # <<inherited docstring from BanEvent>>.

    @property
    def user_id(self) -> snowflakes.Snowflake:
        """User ID of the user that got banned.

        Returns
        -------
        hikari.snowflakes.Snowflake
            ID of the user the event concerns.
        """
        return self.user.id

    async def fetch_ban(self) -> guilds.GuildBan:
        """Perform an API call to fetch the details about this ban.

        This will include the optionally defined audit log reason for the
        ban.

        Returns
        -------
        hikari.guilds.GuildBan
            The ban details.
        """
        return await self.app.rest.fetch_ban(self.guild_id, self.user)
Method resolution order
dataclass BanCreateEvent
That's this class!
abstract class BanEvent

Event base for any guild ban or unban …

abstract class GuildEvent

Event base for any guild-bound event …

abstract class ShardEvent

Base class for any event that was shard-specific.

abstract class Event

Base event type that all Hikari events should subclass.

extern class abc.ABC

Helper class that provides a standard way to create an ABC using inheritance.

Variables and properties
property appRESTAware

App instance for this application.

Returns

RESTAware
The REST-aware app trait.
property guild_idsnowflakes.Snowflake

ID of the guild that this event relates to.

Returns

Snowflake
The ID of the guild that relates to this event.
property shardgateway_shard.GatewayShard

Shard that received this event.

Returns

GatewayShard
The shard that triggered the event.
property userusers.User

User that this ban event affects.

Returns

User
The user that this event concerns.
property user_idsnowflakes.Snowflake

User ID of the user that got banned.

Returns

Snowflake
ID of the user the event concerns.
Methods
async def fetch_ban() -> guilds.GuildBan: ...

Perform an API call to fetch the details about this ban.

This will include the optionally defined audit log reason for the ban.

Returns

GuildBan
The ban details.
Expand source code
Browse git
async def fetch_ban(self) -> guilds.GuildBan:
    """Perform an API call to fetch the details about this ban.

    This will include the optionally defined audit log reason for the
    ban.

    Returns
    -------
    hikari.guilds.GuildBan
        The ban details.
    """
    return await self.app.rest.fetch_ban(self.guild_id, self.user)
async def fetch_guild() -> guilds.RESTGuild: ...

Inherited from: BanEvent.fetch_guild

Perform an API call to get the guild that this event relates to.

Returns

RESTGuild
The guild this event occurred in.
async def fetch_guild_preview() -> guilds.GuildPreview: ...

Inherited from: BanEvent.fetch_guild_preview

Perform an API call to get the preview of the event's guild.

Returns

GuildPreview
The preview of the guild this event occurred in.
async def fetch_user() -> users.User: ...

Inherited from: BanEvent.fetch_user

Perform an API call to fetch the user this ban event affects.

Returns

User
The user affected by this event.
def get_guild() -> Optional[guilds.GatewayGuild]: ...

Inherited from: BanEvent.get_guild

Get the cached guild that this event relates to, if known.

If not known, this will return None instead.

Returns

Optional[GatewayGuild]
The guild this event relates to, or None if not known.
def bitmask() -> int: ...

Inherited from: BanEvent.bitmask

Bitmask for this event.

def dispatches() -> Sequence[Type[Event]]: ...

Inherited from: BanEvent.dispatches

Sequence of the event classes this event is dispatched as.

dataclass BanDeleteEvent

class BanDeleteEvent (
    *,
    shard: gateway_shard.GatewayShard,
    guild_id: snowflakes.Snowflake,
    user: users.User,
): ...

Event that is fired when a user is unbanned from a guild.

This requires one of the following combinations of intents in order to be dispatched:

Method generated by attrs for class BanDeleteEvent.

Expand source code
Browse git
class BanDeleteEvent(BanEvent):
    """Event that is fired when a user is unbanned from a guild."""

    shard: gateway_shard.GatewayShard = attr.field(metadata={attr_extensions.SKIP_DEEP_COPY: True})
    # <<inherited docstring from ShardEvent>>.

    guild_id: snowflakes.Snowflake = attr.field()
    # <<inherited docstring from GuildEvent>>.

    user: users.User = attr.field()
    # <<inherited docstring from BanEvent>>.
Method resolution order
dataclass BanDeleteEvent
That's this class!
abstract class BanEvent

Event base for any guild ban or unban …

abstract class GuildEvent

Event base for any guild-bound event …

abstract class ShardEvent

Base class for any event that was shard-specific.

abstract class Event

Base event type that all Hikari events should subclass.

extern class abc.ABC

Helper class that provides a standard way to create an ABC using inheritance.

Variables and properties
property appRESTAware

App instance for this application.

Returns

RESTAware
The REST-aware app trait.
property guild_idsnowflakes.Snowflake

ID of the guild that this event relates to.

Returns

Snowflake
The ID of the guild that relates to this event.
property shardgateway_shard.GatewayShard

Shard that received this event.

Returns

GatewayShard
The shard that triggered the event.
property userusers.User

User that this ban event affects.

Returns

User
The user that this event concerns.
Methods
async def fetch_guild() -> guilds.RESTGuild: ...

Inherited from: BanEvent.fetch_guild

Perform an API call to get the guild that this event relates to.

Returns

RESTGuild
The guild this event occurred in.
async def fetch_guild_preview() -> guilds.GuildPreview: ...

Inherited from: BanEvent.fetch_guild_preview

Perform an API call to get the preview of the event's guild.

Returns

GuildPreview
The preview of the guild this event occurred in.
async def fetch_user() -> users.User: ...

Inherited from: BanEvent.fetch_user

Perform an API call to fetch the user this ban event affects.

Returns

User
The user affected by this event.
def get_guild() -> Optional[guilds.GatewayGuild]: ...

Inherited from: BanEvent.get_guild

Get the cached guild that this event relates to, if known.

If not known, this will return None instead.

Returns

Optional[GatewayGuild]
The guild this event relates to, or None if not known.
def bitmask() -> int: ...

Inherited from: BanEvent.bitmask

Bitmask for this event.

def dispatches() -> Sequence[Type[Event]]: ...

Inherited from: BanEvent.dispatches

Sequence of the event classes this event is dispatched as.

class BanEvent

class BanEvent: ...

Event base for any guild ban or unban.

This requires one of the following combinations of intents in order to be dispatched:

Expand source code
Browse git
class BanEvent(GuildEvent, abc.ABC):
    """Event base for any guild ban or unban."""

    __slots__: typing.Sequence[str] = ()

    @property
    def app(self) -> traits.RESTAware:
        # <<inherited docstring from Event>>.
        return self.user.app

    @property
    @abc.abstractmethod
    def user(self) -> users.User:
        """User that this ban event affects.

        Returns
        -------
        hikari.users.User
            The user that this event concerns.
        """

    async def fetch_user(self) -> users.User:
        """Perform an API call to fetch the user this ban event affects.

        Returns
        -------
        hikari.users.User
            The user affected by this event.
        """
        return await self.app.rest.fetch_user(self.user)
Subclasses
dataclass BanCreateEvent

Event that is fired when a user is banned from a guild …

dataclass BanDeleteEvent

Event that is fired when a user is unbanned from a guild …

Method resolution order
abstract class BanEvent
That's this class!
abstract class GuildEvent

Event base for any guild-bound event …

abstract class ShardEvent

Base class for any event that was shard-specific.

abstract class Event

Base event type that all Hikari events should subclass.

extern class abc.ABC

Helper class that provides a standard way to create an ABC using inheritance.

Variables and properties
property appRESTAware

App instance for this application.

Returns

RESTAware
The REST-aware app trait.
abstract property guild_idsnowflakes.Snowflake

ID of the guild that this event relates to.

Returns

Snowflake
The ID of the guild that relates to this event.
abstract property shardgateway_shard.GatewayShard

Shard that received this event.

Returns

GatewayShard
The shard that triggered the event.
abstract property userusers.User

User that this ban event affects.

Returns

User
The user that this event concerns.
Methods
async def fetch_guild() -> guilds.RESTGuild: ...

Inherited from: GuildEvent.fetch_guild

Perform an API call to get the guild that this event relates to.

Returns

RESTGuild
The guild this event occurred in.
async def fetch_guild_preview() -> guilds.GuildPreview: ...

Inherited from: GuildEvent.fetch_guild_preview

Perform an API call to get the preview of the event's guild.

Returns

GuildPreview
The preview of the guild this event occurred in.
async def fetch_user() -> users.User: ...

Perform an API call to fetch the user this ban event affects.

Returns

User
The user affected by this event.
Expand source code
Browse git
async def fetch_user(self) -> users.User:
    """Perform an API call to fetch the user this ban event affects.

    Returns
    -------
    hikari.users.User
        The user affected by this event.
    """
    return await self.app.rest.fetch_user(self.user)
def get_guild() -> Optional[guilds.GatewayGuild]: ...

Inherited from: GuildEvent.get_guild

Get the cached guild that this event relates to, if known.

If not known, this will return None instead.

Returns

Optional[GatewayGuild]
The guild this event relates to, or None if not known.
def bitmask() -> int: ...

Inherited from: GuildEvent.bitmask

Bitmask for this event.

def dispatches() -> Sequence[Type[Event]]: ...

Inherited from: GuildEvent.dispatches

Sequence of the event classes this event is dispatched as.

dataclass EmojisUpdateEvent

class EmojisUpdateEvent (
    *,
    app: traits.RESTAware,
    shard: gateway_shard.GatewayShard,
    guild_id: snowflakes.Snowflake,
    old_emojis: Optional[Sequence[emojis_.KnownCustomEmoji]],
    emojis: Sequence[emojis_.KnownCustomEmoji],
): ...

Event that is fired when the emojis in a guild are updated.

This requires one of the following combinations of intents in order to be dispatched:

Method generated by attrs for class EmojisUpdateEvent.

Expand source code
Browse git
class EmojisUpdateEvent(GuildEvent):
    """Event that is fired when the emojis in a guild are updated."""

    app: traits.RESTAware = attr.field(metadata={attr_extensions.SKIP_DEEP_COPY: True})
    # <<inherited docstring from Event>>.

    shard: gateway_shard.GatewayShard = attr.field(metadata={attr_extensions.SKIP_DEEP_COPY: True})
    # <<inherited docstring from ShardEvent>>.

    guild_id: snowflakes.Snowflake = attr.field()
    # <<inherited docstring from GuildEvent>>.

    old_emojis: typing.Optional[typing.Sequence[emojis_.KnownCustomEmoji]] = attr.field()
    """Sequence of all old emojis in this guild.

    This will be `builtins.None` if it's missing from the cache.
    """

    emojis: typing.Sequence[emojis_.KnownCustomEmoji] = attr.field()
    """Sequence of all emojis in this guild.

    Returns
    -------
    typing.Sequence[emojis_.KnownCustomEmoji]
        All emojis in the guild.
    """

    async def fetch_emojis(self) -> typing.Sequence[emojis_.KnownCustomEmoji]:
        """Perform an API call to retrieve an up-to-date view of the emojis.

        Returns
        -------
        typing.Sequence[emojis_.KnownCustomEmoji]
            All emojis in the guild.
        """
        return await self.app.rest.fetch_guild_emojis(self.guild_id)
Method resolution order
dataclass EmojisUpdateEvent
That's this class!
abstract class GuildEvent

Event base for any guild-bound event …

abstract class ShardEvent

Base class for any event that was shard-specific.

abstract class Event

Base event type that all Hikari events should subclass.

extern class abc.ABC

Helper class that provides a standard way to create an ABC using inheritance.

Variables and properties
property apptraits.RESTAware

App instance for this application.

Returns

RESTAware
The REST-aware app trait.
property emojisSequence[emojis_.KnownCustomEmoji]

Sequence of all emojis in this guild.

Returns

Sequence[emojis_.KnownCustomEmoji]
All emojis in the guild.
property guild_idsnowflakes.Snowflake

ID of the guild that this event relates to.

Returns

Snowflake
The ID of the guild that relates to this event.
property old_emojisOptional[Sequence[emojis_.KnownCustomEmoji]]

Sequence of all old emojis in this guild.

This will be None if it's missing from the cache.

property shardgateway_shard.GatewayShard

Shard that received this event.

Returns

GatewayShard
The shard that triggered the event.
Methods
async def fetch_emojis() -> Sequence[emojis_.KnownCustomEmoji]: ...

Perform an API call to retrieve an up-to-date view of the emojis.

Returns

Sequence[emojis_.KnownCustomEmoji]
All emojis in the guild.
Expand source code
Browse git
async def fetch_emojis(self) -> typing.Sequence[emojis_.KnownCustomEmoji]:
    """Perform an API call to retrieve an up-to-date view of the emojis.

    Returns
    -------
    typing.Sequence[emojis_.KnownCustomEmoji]
        All emojis in the guild.
    """
    return await self.app.rest.fetch_guild_emojis(self.guild_id)
async def fetch_guild() -> guilds.RESTGuild: ...

Inherited from: GuildEvent.fetch_guild

Perform an API call to get the guild that this event relates to.

Returns

RESTGuild
The guild this event occurred in.
async def fetch_guild_preview() -> guilds.GuildPreview: ...

Inherited from: GuildEvent.fetch_guild_preview

Perform an API call to get the preview of the event's guild.

Returns

GuildPreview
The preview of the guild this event occurred in.
def get_guild() -> Optional[guilds.GatewayGuild]: ...

Inherited from: GuildEvent.get_guild

Get the cached guild that this event relates to, if known.

If not known, this will return None instead.

Returns

Optional[GatewayGuild]
The guild this event relates to, or None if not known.
def bitmask() -> int: ...

Inherited from: GuildEvent.bitmask

Bitmask for this event.

def dispatches() -> Sequence[Type[Event]]: ...

Inherited from: GuildEvent.dispatches

Sequence of the event classes this event is dispatched as.

dataclass GuildAvailableEvent

class GuildAvailableEvent (
    *,
    shard: gateway_shard.GatewayShard,
    guild: guilds.GatewayGuild,
    emojis: Mapping[snowflakes.Snowflakeemojis_.KnownCustomEmoji],
    roles: Mapping[snowflakes.Snowflakeguilds.Role],
    channels: Mapping[snowflakes.Snowflakechannels_.GuildChannel],
    members: Mapping[snowflakes.Snowflakeguilds.Member],
    presences: Mapping[snowflakes.Snowflakepresences_.MemberPresence],
    voice_states: Mapping[snowflakes.Snowflakevoices.VoiceState],
    chunk_nonce: Optional[str] = None,
): ...

Event fired when a guild becomes available.

This will occur on startup or after outages.

Note

Some fields like members and presences are included here but not on the other GuildUpdateEvent and GuildUnavailableEvent guild visibility event models.

This requires one of the following combinations of intents in order to be dispatched:

Method generated by attrs for class GuildAvailableEvent.

Expand source code
Browse git
class GuildAvailableEvent(GuildVisibilityEvent):
    """Event fired when a guild becomes available.

    This will occur on startup or after outages.

    !!! note
        Some fields like `members` and `presences` are included here but not on
        the other `GuildUpdateEvent` and `GuildUnavailableEvent` guild visibility
        event models.
    """

    shard: gateway_shard.GatewayShard = attr.field(metadata={attr_extensions.SKIP_DEEP_COPY: True})
    # <<inherited docstring from ShardEvent>>.

    guild: guilds.GatewayGuild = attr.field()
    """Guild that just became available.

    Returns
    -------
    hikari.guilds.Guild
        The guild that relates to this event.
    """

    emojis: typing.Mapping[snowflakes.Snowflake, emojis_.KnownCustomEmoji] = attr.field(repr=False)
    """Mapping of emoji IDs to the emojis in the guild.

    Returns
    -------
    typing.Mapping[hikari.snowflakes.Snowflake, hikari.emojis.KnownCustomEmoji]
        The emojis in the guild.
    """

    roles: typing.Mapping[snowflakes.Snowflake, guilds.Role] = attr.field(repr=False)
    """Mapping of role IDs to the roles in the guild.

    Returns
    -------
    typing.Mapping[hikari.snowflakes.Snowflake, hikari.guilds.Role]
        The roles in the guild.
    """

    channels: typing.Mapping[snowflakes.Snowflake, channels_.GuildChannel] = attr.field(repr=False)
    """Mapping of channel IDs to the channels in the guild.

    Returns
    -------
    typing.Mapping[hikari.snowflakes.Snowflake, hikari.channels.GuildChannel]
        The channels in the guild.
    """

    members: typing.Mapping[snowflakes.Snowflake, guilds.Member] = attr.field(repr=False)
    """Mapping of user IDs to the members in the guild.

    Returns
    -------
    typing.Mapping[hikari.snowflakes.Snowflake, hikari.guilds.Member]
        The members in the guild.
    """

    presences: typing.Mapping[snowflakes.Snowflake, presences_.MemberPresence] = attr.field(repr=False)
    """Mapping of user IDs to the presences for the guild.

    Returns
    -------
    typing.Mapping[hikari.snowflakes.Snowflake, hikari.presences.MemberPresence]
        The member presences in the guild.
    """

    voice_states: typing.Mapping[snowflakes.Snowflake, voices.VoiceState] = attr.field(repr=False)
    """Mapping of user IDs to the voice states active in this guild.

    Returns
    -------
    typing.Mapping[hikari.snowflakes.Snowflake, hikari.voices.VoiceState]
        The voice states active in the guild.
    """

    chunk_nonce: typing.Optional[str] = attr.field(repr=False, default=None)
    """Nonce used to request the member chunks for this guild.

    This will be `builtins.None` if no chunks were requested.

    !!! note
        This is a synthetic field.

    Returns
    -------
    typing.Optional[builtins.str]
        The nonce used to request the member chunks.
    """

    @property
    def app(self) -> traits.RESTAware:
        # <<inherited docstring from Event>>.
        return self.guild.app

    @property
    def guild_id(self) -> snowflakes.Snowflake:
        # <<inherited docstring from GuildEvent>>.
        return self.guild.id
Method resolution order
dataclass GuildAvailableEvent
That's this class!
abstract class GuildVisibilityEvent

Event base for any event that changes the visibility of a guild …

abstract class GuildEvent

Event base for any guild-bound event …

abstract class ShardEvent

Base class for any event that was shard-specific.

abstract class Event

Base event type that all Hikari events should subclass.

extern class abc.ABC

Helper class that provides a standard way to create an ABC using inheritance.

Variables and properties
property appRESTAware

App instance for this application.

Returns

RESTAware
The REST-aware app trait.
property channelsMapping[snowflakes.Snowflake, channels_.GuildChannel]

Mapping of channel IDs to the channels in the guild.

Returns

Mapping[Snowflake, GuildChannel]
The channels in the guild.
property chunk_nonceOptional[str]

Nonce used to request the member chunks for this guild.

This will be None if no chunks were requested.

Note

This is a synthetic field.

Returns

Optional[str]
The nonce used to request the member chunks.
property emojisMapping[snowflakes.Snowflake, emojis_.KnownCustomEmoji]

Mapping of emoji IDs to the emojis in the guild.

Returns

Mapping[Snowflake, KnownCustomEmoji]
The emojis in the guild.
property guildguilds.GatewayGuild

Guild that just became available.

Returns

Guild
The guild that relates to this event.
property guild_idsnowflakes.Snowflake

ID of the guild that this event relates to.

Returns

Snowflake
The ID of the guild that relates to this event.
property membersMapping[snowflakes.Snowflake, guilds.Member]

Mapping of user IDs to the members in the guild.

Returns

Mapping[Snowflake, Member]
The members in the guild.
property presencesMapping[snowflakes.Snowflake, presences_.MemberPresence]

Mapping of user IDs to the presences for the guild.

Returns

Mapping[Snowflake, MemberPresence]
The member presences in the guild.
property rolesMapping[snowflakes.Snowflake, guilds.Role]

Mapping of role IDs to the roles in the guild.

Returns

Mapping[Snowflake, Role]
The roles in the guild.
property shardgateway_shard.GatewayShard

Shard that received this event.

Returns

GatewayShard
The shard that triggered the event.
property voice_statesMapping[snowflakes.Snowflake, voices.VoiceState]

Mapping of user IDs to the voice states active in this guild.

Returns

Mapping[Snowflake, VoiceState]
The voice states active in the guild.
Methods
async def fetch_guild() -> guilds.RESTGuild: ...

Inherited from: GuildVisibilityEvent.fetch_guild

Perform an API call to get the guild that this event relates to.

Returns

RESTGuild
The guild this event occurred in.
async def fetch_guild_preview() -> guilds.GuildPreview: ...

Inherited from: GuildVisibilityEvent.fetch_guild_preview

Perform an API call to get the preview of the event's guild.

Returns

GuildPreview
The preview of the guild this event occurred in.
def get_guild() -> Optional[guilds.GatewayGuild]: ...

Inherited from: GuildVisibilityEvent.get_guild

Get the cached guild that this event relates to, if known.

If not known, this will return None instead.

Returns

Optional[GatewayGuild]
The guild this event relates to, or None if not known.
def bitmask() -> int: ...

Inherited from: GuildVisibilityEvent.bitmask

Bitmask for this event.

def dispatches() -> Sequence[Type[Event]]: ...

Inherited from: GuildVisibilityEvent.dispatches

Sequence of the event classes this event is dispatched as.

class GuildEvent

class GuildEvent: ...

Event base for any guild-bound event.

This requires one of the following combinations of intents in order to be dispatched:

Expand source code
Browse git
class GuildEvent(shard_events.ShardEvent, abc.ABC):
    """Event base for any guild-bound event."""

    __slots__: typing.Sequence[str] = ()

    @property
    @abc.abstractmethod
    def guild_id(self) -> snowflakes.Snowflake:
        """ID of the guild that this event relates to.

        Returns
        -------
        hikari.snowflakes.Snowflake
            The ID of the guild that relates to this event.
        """

    async def fetch_guild(self) -> guilds.RESTGuild:
        """Perform an API call to get the guild that this event relates to.

        Returns
        -------
        hikari.guilds.RESTGuild
            The guild this event occurred in.
        """
        return await self.app.rest.fetch_guild(self.guild_id)

    async def fetch_guild_preview(self) -> guilds.GuildPreview:
        """Perform an API call to get the preview of the event's guild.

        Returns
        -------
        hikari.guilds.GuildPreview
            The preview of the guild this event occurred in.
        """
        return await self.app.rest.fetch_guild_preview(self.guild_id)

    def get_guild(self) -> typing.Optional[guilds.GatewayGuild]:
        """Get the cached guild that this event relates to, if known.

        If not known, this will return `builtins.None` instead.

        Returns
        -------
        typing.Optional[hikari.guilds.GatewayGuild]
            The guild this event relates to, or `builtins.None` if not known.
        """
        if not isinstance(self.app, traits.CacheAware):
            return None

        return self.app.cache.get_available_guild(self.guild_id) or self.app.cache.get_unavailable_guild(self.guild_id)
Subclasses
abstract class BanEvent

Event base for any guild ban or unban …

dataclass EmojisUpdateEvent

Event that is fired when the emojis in a guild are updated …

dataclass GuildUpdateEvent

Event fired when an existing guild is updated …

abstract class GuildVisibilityEvent

Event base for any event that changes the visibility of a guild …

abstract trait class IntegrationEvent

Event base for any integration related events …

Method resolution order
abstract class GuildEvent
That's this class!
abstract class ShardEvent

Base class for any event that was shard-specific.

abstract class Event

Base event type that all Hikari events should subclass.

extern class abc.ABC

Helper class that provides a standard way to create an ABC using inheritance.

Variables and properties
abstract property appRESTAware

App instance for this application.

Returns

RESTAware
The REST-aware app trait.
abstract property guild_idsnowflakes.Snowflake

ID of the guild that this event relates to.

Returns

Snowflake
The ID of the guild that relates to this event.
abstract property shardgateway_shard.GatewayShard

Shard that received this event.

Returns

GatewayShard
The shard that triggered the event.
Methods
async def fetch_guild() -> guilds.RESTGuild: ...

Perform an API call to get the guild that this event relates to.

Returns

RESTGuild
The guild this event occurred in.
Expand source code
Browse git
async def fetch_guild(self) -> guilds.RESTGuild:
    """Perform an API call to get the guild that this event relates to.

    Returns
    -------
    hikari.guilds.RESTGuild
        The guild this event occurred in.
    """
    return await self.app.rest.fetch_guild(self.guild_id)
async def fetch_guild_preview() -> guilds.GuildPreview: ...

Perform an API call to get the preview of the event's guild.

Returns

GuildPreview
The preview of the guild this event occurred in.
Expand source code
Browse git
async def fetch_guild_preview(self) -> guilds.GuildPreview:
    """Perform an API call to get the preview of the event's guild.

    Returns
    -------
    hikari.guilds.GuildPreview
        The preview of the guild this event occurred in.
    """
    return await self.app.rest.fetch_guild_preview(self.guild_id)
def get_guild() -> Optional[guilds.GatewayGuild]: ...

Get the cached guild that this event relates to, if known.

If not known, this will return None instead.

Returns

Optional[GatewayGuild]
The guild this event relates to, or None if not known.
Expand source code
Browse git
def get_guild(self) -> typing.Optional[guilds.GatewayGuild]:
    """Get the cached guild that this event relates to, if known.

    If not known, this will return `builtins.None` instead.

    Returns
    -------
    typing.Optional[hikari.guilds.GatewayGuild]
        The guild this event relates to, or `builtins.None` if not known.
    """
    if not isinstance(self.app, traits.CacheAware):
        return None

    return self.app.cache.get_available_guild(self.guild_id) or self.app.cache.get_unavailable_guild(self.guild_id)
def bitmask() -> int: ...

Inherited from: ShardEvent.bitmask

Bitmask for this event.

def dispatches() -> Sequence[Type[Event]]: ...

Inherited from: ShardEvent.dispatches

Sequence of the event classes this event is dispatched as.

dataclass GuildJoinEvent

class GuildJoinEvent (
    *,
    shard: gateway_shard.GatewayShard,
    guild: guilds.GatewayGuild,
    emojis: Mapping[snowflakes.Snowflakeemojis_.KnownCustomEmoji],
    roles: Mapping[snowflakes.Snowflakeguilds.Role],
    channels: Mapping[snowflakes.Snowflakechannels_.GuildChannel],
    members: Mapping[snowflakes.Snowflakeguilds.Member],
    presences: Mapping[snowflakes.Snowflakepresences_.MemberPresence],
    voice_states: Mapping[snowflakes.Snowflakevoices.VoiceState],
    chunk_nonce: Optional[str] = None,
): ...

Event fired when the bot joins a new guild.

Note

Some fields like members and presences are included here but not on the other GuildUpdateEvent and GuildUnavailableEvent guild visibility event models.

This requires one of the following combinations of intents in order to be dispatched:

Method generated by attrs for class GuildJoinEvent.

Expand source code
Browse git
class GuildJoinEvent(GuildVisibilityEvent):
    """Event fired when the bot joins a new guild.

    !!! note
        Some fields like `members` and `presences` are included here but not on
        the other `GuildUpdateEvent` and `GuildUnavailableEvent` guild visibility
        event models.
    """

    shard: gateway_shard.GatewayShard = attr.field(metadata={attr_extensions.SKIP_DEEP_COPY: True})
    # <<inherited docstring from ShardEvent>>.

    guild: guilds.GatewayGuild = attr.field()
    """The guild the bot just joined."""

    emojis: typing.Mapping[snowflakes.Snowflake, emojis_.KnownCustomEmoji] = attr.field(repr=False)
    """Mapping of emoji IDs to the emojis in the guild."""

    roles: typing.Mapping[snowflakes.Snowflake, guilds.Role] = attr.field(repr=False)
    """Mapping of role IDs to the roles in the guild."""

    channels: typing.Mapping[snowflakes.Snowflake, channels_.GuildChannel] = attr.field(repr=False)
    """Mapping of channel IDs to the channels in the guild."""

    members: typing.Mapping[snowflakes.Snowflake, guilds.Member] = attr.field(repr=False)
    """Mapping of user IDs to the members in the guild."""

    presences: typing.Mapping[snowflakes.Snowflake, presences_.MemberPresence] = attr.field(repr=False)
    """Mapping of user IDs to the presences for the guild."""

    voice_states: typing.Mapping[snowflakes.Snowflake, voices.VoiceState] = attr.field(repr=False)
    """Mapping of user IDs to the voice states active in this guild."""

    chunk_nonce: typing.Optional[str] = attr.field(repr=False, default=None)
    """Nonce used to request the member chunks for this guild.

    This will be `builtins.None` if no chunks were requested.

    !!! note
        This is a synthetic field.
    """

    @property
    def app(self) -> traits.RESTAware:
        # <<inherited docstring from Event>>.
        return self.guild.app

    @property
    def guild_id(self) -> snowflakes.Snowflake:
        # <<inherited docstring from GuildEvent>>.
        return self.guild.id
Method resolution order
dataclass GuildJoinEvent
That's this class!
abstract class GuildVisibilityEvent

Event base for any event that changes the visibility of a guild …

abstract class GuildEvent

Event base for any guild-bound event …

abstract class ShardEvent

Base class for any event that was shard-specific.

abstract class Event

Base event type that all Hikari events should subclass.

extern class abc.ABC

Helper class that provides a standard way to create an ABC using inheritance.

Variables and properties
property appRESTAware

App instance for this application.

Returns

RESTAware
The REST-aware app trait.
property channelsMapping[snowflakes.Snowflake, channels_.GuildChannel]

Mapping of channel IDs to the channels in the guild.

property chunk_nonceOptional[str]

Nonce used to request the member chunks for this guild.

This will be None if no chunks were requested.

Note

This is a synthetic field.

property emojisMapping[snowflakes.Snowflake, emojis_.KnownCustomEmoji]

Mapping of emoji IDs to the emojis in the guild.

property guildguilds.GatewayGuild

The guild the bot just joined.

property guild_idsnowflakes.Snowflake

ID of the guild that this event relates to.

Returns

Snowflake
The ID of the guild that relates to this event.
property membersMapping[snowflakes.Snowflake, guilds.Member]

Mapping of user IDs to the members in the guild.

property presencesMapping[snowflakes.Snowflake, presences_.MemberPresence]

Mapping of user IDs to the presences for the guild.

property rolesMapping[snowflakes.Snowflake, guilds.Role]

Mapping of role IDs to the roles in the guild.

property shardgateway_shard.GatewayShard

Shard that received this event.

Returns

GatewayShard
The shard that triggered the event.
property voice_statesMapping[snowflakes.Snowflake, voices.VoiceState]

Mapping of user IDs to the voice states active in this guild.

Methods
async def fetch_guild() -> guilds.RESTGuild: ...

Inherited from: GuildVisibilityEvent.fetch_guild

Perform an API call to get the guild that this event relates to.

Returns

RESTGuild
The guild this event occurred in.
async def fetch_guild_preview() -> guilds.GuildPreview: ...

Inherited from: GuildVisibilityEvent.fetch_guild_preview

Perform an API call to get the preview of the event's guild.

Returns

GuildPreview
The preview of the guild this event occurred in.
def get_guild() -> Optional[guilds.GatewayGuild]: ...

Inherited from: GuildVisibilityEvent.get_guild

Get the cached guild that this event relates to, if known.

If not known, this will return None instead.

Returns

Optional[GatewayGuild]
The guild this event relates to, or None if not known.
def bitmask() -> int: ...

Inherited from: GuildVisibilityEvent.bitmask

Bitmask for this event.

def dispatches() -> Sequence[Type[Event]]: ...

Inherited from: GuildVisibilityEvent.dispatches

Sequence of the event classes this event is dispatched as.

dataclass GuildLeaveEvent

class GuildLeaveEvent (
    *,
    app: traits.RESTAware,
    shard: gateway_shard.GatewayShard,
    guild_id: snowflakes.Snowflake,
    old_guild: Optional[guilds.GatewayGuild],
): ...

Event fired when the bot is banned/kicked/leaves a guild.

This will also fire if the guild was deleted.

This requires one of the following combinations of intents in order to be dispatched:

Method generated by attrs for class GuildLeaveEvent.

Expand source code
Browse git
class GuildLeaveEvent(GuildVisibilityEvent):
    """Event fired when the bot is banned/kicked/leaves a guild.

    This will also fire if the guild was deleted.
    """

    app: traits.RESTAware = attr.field(metadata={attr_extensions.SKIP_DEEP_COPY: True})
    # <<inherited docstring from Event>>.

    shard: gateway_shard.GatewayShard = attr.field(metadata={attr_extensions.SKIP_DEEP_COPY: True})
    # <<inherited docstring from ShardEvent>>.

    guild_id: snowflakes.Snowflake = attr.field()
    # <<inherited docstring from GuildEvent>>.

    old_guild: typing.Optional[guilds.GatewayGuild] = attr.field()
    """The old guild object.

    This will be `builtins.None` if the guild missing from the cache.
    """

    if typing.TYPE_CHECKING:
        # This should always fail.
        async def fetch_guild(self) -> typing.NoReturn:
            ...
Method resolution order
dataclass GuildLeaveEvent
That's this class!
abstract class GuildVisibilityEvent

Event base for any event that changes the visibility of a guild …

abstract class GuildEvent

Event base for any guild-bound event …

abstract class ShardEvent

Base class for any event that was shard-specific.

abstract class Event

Base event type that all Hikari events should subclass.

extern class abc.ABC

Helper class that provides a standard way to create an ABC using inheritance.

Variables and properties
property apptraits.RESTAware

App instance for this application.

Returns

RESTAware
The REST-aware app trait.
property guild_idsnowflakes.Snowflake

ID of the guild that this event relates to.

Returns

Snowflake
The ID of the guild that relates to this event.
property old_guildOptional[guilds.GatewayGuild]

The old guild object.

This will be None if the guild missing from the cache.

property shardgateway_shard.GatewayShard

Shard that received this event.

Returns

GatewayShard
The shard that triggered the event.
Methods
async def fetch_guild() -> guilds.RESTGuild: ...

Inherited from: GuildVisibilityEvent.fetch_guild

Perform an API call to get the guild that this event relates to.

Returns

RESTGuild
The guild this event occurred in.
async def fetch_guild_preview() -> guilds.GuildPreview: ...

Inherited from: GuildVisibilityEvent.fetch_guild_preview

Perform an API call to get the preview of the event's guild.

Returns

GuildPreview
The preview of the guild this event occurred in.
def get_guild() -> Optional[guilds.GatewayGuild]: ...

Inherited from: GuildVisibilityEvent.get_guild

Get the cached guild that this event relates to, if known.

If not known, this will return None instead.

Returns

Optional[GatewayGuild]
The guild this event relates to, or None if not known.
def bitmask() -> int: ...

Inherited from: GuildVisibilityEvent.bitmask

Bitmask for this event.

def dispatches() -> Sequence[Type[Event]]: ...

Inherited from: GuildVisibilityEvent.dispatches

Sequence of the event classes this event is dispatched as.

dataclass GuildUnavailableEvent

class GuildUnavailableEvent (
    *,
    app: traits.RESTAware,
    shard: gateway_shard.GatewayShard,
    guild_id: snowflakes.Snowflake,
): ...

Event fired when a guild becomes unavailable because of an outage.

This requires one of the following combinations of intents in order to be dispatched:

Method generated by attrs for class GuildUnavailableEvent.

Expand source code
Browse git
class GuildUnavailableEvent(GuildVisibilityEvent):
    """Event fired when a guild becomes unavailable because of an outage."""

    app: traits.RESTAware = attr.field(metadata={attr_extensions.SKIP_DEEP_COPY: True})
    # <<inherited docstring from Event>>.

    shard: gateway_shard.GatewayShard = attr.field(metadata={attr_extensions.SKIP_DEEP_COPY: True})
    # <<inherited docstring from ShardEvent>>.

    guild_id: snowflakes.Snowflake = attr.field()
    # <<inherited docstring from GuildEvent>>.
Method resolution order
dataclass GuildUnavailableEvent
That's this class!
abstract class GuildVisibilityEvent

Event base for any event that changes the visibility of a guild …

abstract class GuildEvent

Event base for any guild-bound event …

abstract class ShardEvent

Base class for any event that was shard-specific.

abstract class Event

Base event type that all Hikari events should subclass.

extern class abc.ABC

Helper class that provides a standard way to create an ABC using inheritance.

Variables and properties
property apptraits.RESTAware

App instance for this application.

Returns

RESTAware
The REST-aware app trait.
property guild_idsnowflakes.Snowflake

ID of the guild that this event relates to.

Returns

Snowflake
The ID of the guild that relates to this event.
property shardgateway_shard.GatewayShard

Shard that received this event.

Returns

GatewayShard
The shard that triggered the event.
Methods
async def fetch_guild() -> guilds.RESTGuild: ...

Inherited from: GuildVisibilityEvent.fetch_guild

Perform an API call to get the guild that this event relates to.

Returns

RESTGuild
The guild this event occurred in.
async def fetch_guild_preview() -> guilds.GuildPreview: ...

Inherited from: GuildVisibilityEvent.fetch_guild_preview

Perform an API call to get the preview of the event's guild.

Returns

GuildPreview
The preview of the guild this event occurred in.
def get_guild() -> Optional[guilds.GatewayGuild]: ...

Inherited from: GuildVisibilityEvent.get_guild

Get the cached guild that this event relates to, if known.

If not known, this will return None instead.

Returns

Optional[GatewayGuild]
The guild this event relates to, or None if not known.
def bitmask() -> int: ...

Inherited from: GuildVisibilityEvent.bitmask

Bitmask for this event.

def dispatches() -> Sequence[Type[Event]]: ...

Inherited from: GuildVisibilityEvent.dispatches

Sequence of the event classes this event is dispatched as.

dataclass GuildUpdateEvent

class GuildUpdateEvent (
    *,
    shard: gateway_shard.GatewayShard,
    old_guild: Optional[guilds.GatewayGuild],
    guild: guilds.GatewayGuild,
    emojis: Mapping[snowflakes.Snowflakeemojis_.KnownCustomEmoji],
    roles: Mapping[snowflakes.Snowflakeguilds.Role],
): ...

Event fired when an existing guild is updated.

This requires one of the following combinations of intents in order to be dispatched:

Method generated by attrs for class GuildUpdateEvent.

Expand source code
Browse git
class GuildUpdateEvent(GuildEvent):
    """Event fired when an existing guild is updated."""

    shard: gateway_shard.GatewayShard = attr.field(metadata={attr_extensions.SKIP_DEEP_COPY: True})
    # <<inherited docstring from ShardEvent>>.

    old_guild: typing.Optional[guilds.GatewayGuild] = attr.field()
    """The old guild object.

    This will be `builtins.None` if the guild missing from the cache.
    """

    guild: guilds.GatewayGuild = attr.field()
    """Guild that was just updated.

    Returns
    -------
    hikari.guilds.Guild
        The guild that relates to this event.
    """

    emojis: typing.Mapping[snowflakes.Snowflake, emojis_.KnownCustomEmoji] = attr.field(repr=False)
    """Mapping of emoji IDs to the emojis in the guild.

    Returns
    -------
    typing.Mapping[hikari.snowflakes.Snowflake, hikari.emojis.KnownCustomEmoji]
        The emojis in the guild.
    """

    roles: typing.Mapping[snowflakes.Snowflake, guilds.Role] = attr.field(repr=False)
    """Mapping of role IDs to the roles in the guild.

    Returns
    -------
    typing.Mapping[hikari.snowflakes.Snowflake, hikari.guilds.Role]
        The roles in the guild.
    """

    @property
    def app(self) -> traits.RESTAware:
        # <<inherited docstring from Event>>.
        return self.guild.app

    @property
    def guild_id(self) -> snowflakes.Snowflake:
        # <<inherited docstring from GuildEvent>>.
        return self.guild.id
Method resolution order
dataclass GuildUpdateEvent
That's this class!
abstract class GuildEvent

Event base for any guild-bound event …

abstract class ShardEvent

Base class for any event that was shard-specific.

abstract class Event

Base event type that all Hikari events should subclass.

extern class abc.ABC

Helper class that provides a standard way to create an ABC using inheritance.

Variables and properties
property appRESTAware

App instance for this application.

Returns

RESTAware
The REST-aware app trait.
property emojisMapping[snowflakes.Snowflake, emojis_.KnownCustomEmoji]

Mapping of emoji IDs to the emojis in the guild.

Returns

Mapping[Snowflake, KnownCustomEmoji]
The emojis in the guild.
property guildguilds.GatewayGuild

Guild that was just updated.

Returns

Guild
The guild that relates to this event.
property guild_idsnowflakes.Snowflake

ID of the guild that this event relates to.

Returns

Snowflake
The ID of the guild that relates to this event.
property old_guildOptional[guilds.GatewayGuild]

The old guild object.

This will be None if the guild missing from the cache.

property rolesMapping[snowflakes.Snowflake, guilds.Role]

Mapping of role IDs to the roles in the guild.

Returns

Mapping[Snowflake, Role]
The roles in the guild.
property shardgateway_shard.GatewayShard

Shard that received this event.

Returns

GatewayShard
The shard that triggered the event.
Methods
async def fetch_guild() -> guilds.RESTGuild: ...

Inherited from: GuildEvent.fetch_guild

Perform an API call to get the guild that this event relates to.

Returns

RESTGuild
The guild this event occurred in.
async def fetch_guild_preview() -> guilds.GuildPreview: ...

Inherited from: GuildEvent.fetch_guild_preview

Perform an API call to get the preview of the event's guild.

Returns

GuildPreview
The preview of the guild this event occurred in.
def get_guild() -> Optional[guilds.GatewayGuild]: ...

Inherited from: GuildEvent.get_guild

Get the cached guild that this event relates to, if known.

If not known, this will return None instead.

Returns

Optional[GatewayGuild]
The guild this event relates to, or None if not known.
def bitmask() -> int: ...

Inherited from: GuildEvent.bitmask

Bitmask for this event.

def dispatches() -> Sequence[Type[Event]]: ...

Inherited from: GuildEvent.dispatches

Sequence of the event classes this event is dispatched as.

class GuildVisibilityEvent

class GuildVisibilityEvent: ...

Event base for any event that changes the visibility of a guild.

This includes when a guild becomes available after an outage, when a guild becomes available on startup, when a guild becomes unavailable due to an outage, when the user is kicked/banned/leaves a guild, or when the user joins a new guild.

This requires one of the following combinations of intents in order to be dispatched:

Expand source code
Browse git
class GuildVisibilityEvent(GuildEvent, abc.ABC):
    """Event base for any event that changes the visibility of a guild.

    This includes when a guild becomes available after an outage, when a
    guild becomes available on startup, when a guild becomes unavailable due
    to an outage, when the user is kicked/banned/leaves a guild, or when
    the user joins a new guild.
    """

    __slots__: typing.Sequence[str] = ()
Subclasses
dataclass GuildAvailableEvent

Event fired when a guild becomes available …

dataclass GuildJoinEvent

Event fired when the bot joins a new guild …

dataclass GuildLeaveEvent

Event fired when the bot is banned/kicked/leaves a guild …

dataclass GuildUnavailableEvent

Event fired when a guild becomes unavailable because of an outage …

Method resolution order
abstract class GuildVisibilityEvent
That's this class!
abstract class GuildEvent

Event base for any guild-bound event …

abstract class ShardEvent

Base class for any event that was shard-specific.

abstract class Event

Base event type that all Hikari events should subclass.

extern class abc.ABC

Helper class that provides a standard way to create an ABC using inheritance.

Variables and properties
abstract property appRESTAware

App instance for this application.

Returns

RESTAware
The REST-aware app trait.
abstract property guild_idsnowflakes.Snowflake

ID of the guild that this event relates to.

Returns

Snowflake
The ID of the guild that relates to this event.
abstract property shardgateway_shard.GatewayShard

Shard that received this event.

Returns

GatewayShard
The shard that triggered the event.
Methods
async def fetch_guild() -> guilds.RESTGuild: ...

Inherited from: GuildEvent.fetch_guild

Perform an API call to get the guild that this event relates to.

Returns

RESTGuild
The guild this event occurred in.
async def fetch_guild_preview() -> guilds.GuildPreview: ...

Inherited from: GuildEvent.fetch_guild_preview

Perform an API call to get the preview of the event's guild.

Returns

GuildPreview
The preview of the guild this event occurred in.
def get_guild() -> Optional[guilds.GatewayGuild]: ...

Inherited from: GuildEvent.get_guild

Get the cached guild that this event relates to, if known.

If not known, this will return None instead.

Returns

Optional[GatewayGuild]
The guild this event relates to, or None if not known.
def bitmask() -> int: ...

Inherited from: GuildEvent.bitmask

Bitmask for this event.

def dispatches() -> Sequence[Type[Event]]: ...

Inherited from: GuildEvent.dispatches

Sequence of the event classes this event is dispatched as.

dataclass IntegrationCreateEvent

class IntegrationCreateEvent (
    *,
    app: traits.RESTAware,
    shard: gateway_shard.GatewayShard,
    integration: guilds.Integration,
): ...

Event that is fired when an integration is created in a guild.

This requires one of the following combinations of intents in order to be dispatched:

Method generated by attrs for class IntegrationCreateEvent.

Expand source code
Browse git
class IntegrationCreateEvent(IntegrationEvent):
    """Event that is fired when an integration is created in a guild."""

    app: traits.RESTAware = attr.field(metadata={attr_extensions.SKIP_DEEP_COPY: True})
    # <<inherited docstring from Event>>.

    shard: gateway_shard.GatewayShard = attr.field(metadata={attr_extensions.SKIP_DEEP_COPY: True})
    # <<inherited docstring from ShardEvent>>.

    integration: guilds.Integration = attr.field()
    """Integration that was created."""

    @property
    def application_id(self) -> typing.Optional[snowflakes.Snowflake]:
        # <<inherited docstring from IntegrationEvent>>.
        return self.integration.application.id if self.integration.application else None

    @property
    def guild_id(self) -> snowflakes.Snowflake:
        # <<inherited docstring from ShardEvent>>.
        return self.integration.guild_id

    @property
    def id(self) -> snowflakes.Snowflake:
        # <<inherited docstring from IntegrationEvent>>
        return self.integration.id
Method resolution order
dataclass IntegrationCreateEvent
That's this class!
abstract trait class IntegrationEvent

Event base for any integration related events …

abstract class GuildEvent

Event base for any guild-bound event …

abstract class ShardEvent

Base class for any event that was shard-specific.

abstract class Event

Base event type that all Hikari events should subclass.

extern class abc.ABC

Helper class that provides a standard way to create an ABC using inheritance.

Variables and properties
property apptraits.RESTAware

App instance for this application.

Returns

RESTAware
The REST-aware app trait.
property application_idOptional[snowflakes.Snowflake]

ID of Discord bot application this integration is connected to.

Returns

Optional[Snowflake]
The ID of Discord bot application this integration is connected to.
property guild_idsnowflakes.Snowflake

ID of the guild that this event relates to.

Returns

Snowflake
The ID of the guild that relates to this event.
property idsnowflakes.Snowflake

ID of the integration.

Returns

Snowflake
The ID of the integration.
property integrationguilds.Integration

Integration that was created.

property shardgateway_shard.GatewayShard

Shard that received this event.

Returns

GatewayShard
The shard that triggered the event.
Methods
async def fetch_guild() -> guilds.RESTGuild: ...

Inherited from: IntegrationEvent.fetch_guild

Perform an API call to get the guild that this event relates to.

Returns

RESTGuild
The guild this event occurred in.
async def fetch_guild_preview() -> guilds.GuildPreview: ...

Inherited from: IntegrationEvent.fetch_guild_preview

Perform an API call to get the preview of the event's guild.

Returns

GuildPreview
The preview of the guild this event occurred in.
async def fetch_integrations() -> Sequence[guilds.Integration]: ...

Inherited from: IntegrationEvent.fetch_integrations

Perform an API call to fetch some number of guild integrations.

Warning

The results of this are not clearly defined by Discord. The current behaviour appears to be that only the first 50 integrations actually get returned. Discord have made it clear that they are not willing to fix this in https://github.com/discord/discord-api-docs/issues/1990.

Returns

Sequence[Integration]
Some possibly random subset of the integrations in a guild, probably.
def get_guild() -> Optional[guilds.GatewayGuild]: ...

Inherited from: IntegrationEvent.get_guild

Get the cached guild that this event relates to, if known.

If not known, this will return None instead.

Returns

Optional[GatewayGuild]
The guild this event relates to, or None if not known.
def bitmask() -> int: ...

Inherited from: IntegrationEvent.bitmask

Bitmask for this event.

def dispatches() -> Sequence[Type[Event]]: ...

Inherited from: IntegrationEvent.dispatches

Sequence of the event classes this event is dispatched as.

dataclass IntegrationDeleteEvent

class IntegrationDeleteEvent (
    *,
    app: traits.RESTAware,
    shard: gateway_shard.GatewayShard,
    application_id: Optional[snowflakes.Snowflake],
    guild_id: snowflakes.Snowflake,
    id: snowflakes.Snowflake,
): ...

Event that is fired when an integration is deleted in a guild.

This requires one of the following combinations of intents in order to be dispatched:

Method generated by attrs for class IntegrationDeleteEvent.

Expand source code
Browse git
class IntegrationDeleteEvent(IntegrationEvent):
    """Event that is fired when an integration is deleted in a guild."""

    app: traits.RESTAware = attr.field(metadata={attr_extensions.SKIP_DEEP_COPY: True})
    # <<inherited docstring from Event>>.

    shard: gateway_shard.GatewayShard = attr.field(metadata={attr_extensions.SKIP_DEEP_COPY: True})
    # <<inherited docstring from ShardEvent>>.

    application_id: typing.Optional[snowflakes.Snowflake] = attr.field()
    # <<inherited docstring from IntegrationEvent>>.

    guild_id: snowflakes.Snowflake = attr.field()
    # <<inherited docstring from ShardEvent>>.

    id: snowflakes.Snowflake = attr.field()
    # <<inherited docstring from IntegrationEvent>>
Method resolution order
dataclass IntegrationDeleteEvent
That's this class!
abstract trait class IntegrationEvent

Event base for any integration related events …

abstract class GuildEvent

Event base for any guild-bound event …

abstract class ShardEvent

Base class for any event that was shard-specific.

abstract class Event

Base event type that all Hikari events should subclass.

extern class abc.ABC

Helper class that provides a standard way to create an ABC using inheritance.

Variables and properties
property apptraits.RESTAware

App instance for this application.

Returns

RESTAware
The REST-aware app trait.
property application_idOptional[snowflakes.Snowflake]

ID of Discord bot application this integration is connected to.

Returns

Optional[Snowflake]
The ID of Discord bot application this integration is connected to.
property guild_idsnowflakes.Snowflake

ID of the guild that this event relates to.

Returns

Snowflake
The ID of the guild that relates to this event.
property idsnowflakes.Snowflake

ID of the integration.

Returns

Snowflake
The ID of the integration.
property shardgateway_shard.GatewayShard

Shard that received this event.

Returns

GatewayShard
The shard that triggered the event.
Methods
async def fetch_guild() -> guilds.RESTGuild: ...

Inherited from: IntegrationEvent.fetch_guild

Perform an API call to get the guild that this event relates to.

Returns

RESTGuild
The guild this event occurred in.
async def fetch_guild_preview() -> guilds.GuildPreview: ...

Inherited from: IntegrationEvent.fetch_guild_preview

Perform an API call to get the preview of the event's guild.

Returns

GuildPreview
The preview of the guild this event occurred in.
async def fetch_integrations() -> Sequence[guilds.Integration]: ...

Inherited from: IntegrationEvent.fetch_integrations

Perform an API call to fetch some number of guild integrations.

Warning

The results of this are not clearly defined by Discord. The current behaviour appears to be that only the first 50 integrations actually get returned. Discord have made it clear that they are not willing to fix this in https://github.com/discord/discord-api-docs/issues/1990.

Returns

Sequence[Integration]
Some possibly random subset of the integrations in a guild, probably.
def get_guild() -> Optional[guilds.GatewayGuild]: ...

Inherited from: IntegrationEvent.get_guild

Get the cached guild that this event relates to, if known.

If not known, this will return None instead.

Returns

Optional[GatewayGuild]
The guild this event relates to, or None if not known.
def bitmask() -> int: ...

Inherited from: IntegrationEvent.bitmask

Bitmask for this event.

def dispatches() -> Sequence[Type[Event]]: ...

Inherited from: IntegrationEvent.dispatches

Sequence of the event classes this event is dispatched as.

class IntegrationEvent

class IntegrationEvent: ...

Event base for any integration related events.

This requires one of the following combinations of intents in order to be dispatched:

Expand source code
Browse git
class IntegrationEvent(GuildEvent, abc.ABC):
    """Event base for any integration related events."""

    __slots__: typing.Sequence[str] = ()

    @property
    @abc.abstractmethod
    def application_id(self) -> typing.Optional[snowflakes.Snowflake]:
        """ID of Discord bot application this integration is connected to.

        Returns
        -------
        typing.Optional[hikari.snowflakes.Snowflake]
            The ID of Discord bot application this integration is connected to.
        """

    @property
    @abc.abstractmethod
    def id(self) -> snowflakes.Snowflake:
        """ID of the integration.

        Returns
        -------
        hikari.snowflakes.Snowflake
            The ID of the integration.
        """

    async def fetch_integrations(self) -> typing.Sequence[guilds.Integration]:
        """Perform an API call to fetch some number of guild integrations.

        !!! warning
            The results of this are not clearly defined by Discord. The current
            behaviour appears to be that only the first 50 integrations actually
            get returned. Discord have made it clear that they are not willing
            to fix this in
            https://github.com/discord/discord-api-docs/issues/1990.

        Returns
        -------
        typing.Sequence[hikari.guilds.Integration]
            Some possibly random subset of the integrations in a guild,
            probably.
        """
        return await self.app.rest.fetch_integrations(self.guild_id)
Subclasses
dataclass IntegrationCreateEvent

Event that is fired when an integration is created in a guild …

dataclass IntegrationDeleteEvent

Event that is fired when an integration is deleted in a guild …

dataclass IntegrationUpdateEvent

Event that is fired when an integration is updated in a guild …

Method resolution order
abstract trait class IntegrationEvent
That's this class!
abstract class GuildEvent

Event base for any guild-bound event …

abstract class ShardEvent

Base class for any event that was shard-specific.

abstract class Event

Base event type that all Hikari events should subclass.

extern class abc.ABC

Helper class that provides a standard way to create an ABC using inheritance.

Variables and properties
abstract property appRESTAware

App instance for this application.

Returns

RESTAware
The REST-aware app trait.
abstract property application_idOptional[snowflakes.Snowflake]

ID of Discord bot application this integration is connected to.

Returns

Optional[Snowflake]
The ID of Discord bot application this integration is connected to.
abstract property guild_idsnowflakes.Snowflake

ID of the guild that this event relates to.

Returns

Snowflake
The ID of the guild that relates to this event.
abstract property idsnowflakes.Snowflake

ID of the integration.

Returns

Snowflake
The ID of the integration.
abstract property shardgateway_shard.GatewayShard

Shard that received this event.

Returns

GatewayShard
The shard that triggered the event.
Methods
async def fetch_guild() -> guilds.RESTGuild: ...

Inherited from: GuildEvent.fetch_guild

Perform an API call to get the guild that this event relates to.

Returns

RESTGuild
The guild this event occurred in.
async def fetch_guild_preview() -> guilds.GuildPreview: ...

Inherited from: GuildEvent.fetch_guild_preview

Perform an API call to get the preview of the event's guild.

Returns

GuildPreview
The preview of the guild this event occurred in.
async def fetch_integrations() -> Sequence[guilds.Integration]: ...

Perform an API call to fetch some number of guild integrations.

Warning

The results of this are not clearly defined by Discord. The current behaviour appears to be that only the first 50 integrations actually get returned. Discord have made it clear that they are not willing to fix this in https://github.com/discord/discord-api-docs/issues/1990.

Returns

Sequence[Integration]
Some possibly random subset of the integrations in a guild, probably.
Expand source code
Browse git
async def fetch_integrations(self) -> typing.Sequence[guilds.Integration]:
    """Perform an API call to fetch some number of guild integrations.

    !!! warning
        The results of this are not clearly defined by Discord. The current
        behaviour appears to be that only the first 50 integrations actually
        get returned. Discord have made it clear that they are not willing
        to fix this in
        https://github.com/discord/discord-api-docs/issues/1990.

    Returns
    -------
    typing.Sequence[hikari.guilds.Integration]
        Some possibly random subset of the integrations in a guild,
        probably.
    """
    return await self.app.rest.fetch_integrations(self.guild_id)
def get_guild() -> Optional[guilds.GatewayGuild]: ...

Inherited from: GuildEvent.get_guild

Get the cached guild that this event relates to, if known.

If not known, this will return None instead.

Returns

Optional[GatewayGuild]
The guild this event relates to, or None if not known.
def bitmask() -> int: ...

Inherited from: GuildEvent.bitmask

Bitmask for this event.

def dispatches() -> Sequence[Type[Event]]: ...

Inherited from: GuildEvent.dispatches

Sequence of the event classes this event is dispatched as.

dataclass IntegrationUpdateEvent

class IntegrationUpdateEvent (
    *,
    app: traits.RESTAware,
    shard: gateway_shard.GatewayShard,
    integration: guilds.Integration,
): ...

Event that is fired when an integration is updated in a guild.

This requires one of the following combinations of intents in order to be dispatched:

Method generated by attrs for class IntegrationUpdateEvent.

Expand source code
Browse git
class IntegrationUpdateEvent(IntegrationEvent):
    """Event that is fired when an integration is updated in a guild."""

    app: traits.RESTAware = attr.field(metadata={attr_extensions.SKIP_DEEP_COPY: True})
    # <<inherited docstring from Event>>.

    shard: gateway_shard.GatewayShard = attr.field(metadata={attr_extensions.SKIP_DEEP_COPY: True})
    # <<inherited docstring from ShardEvent>>.

    integration: guilds.Integration = attr.field()
    """Integration that was updated."""

    @property
    def application_id(self) -> typing.Optional[snowflakes.Snowflake]:
        # <<inherited docstring from IntegrationEvent>>.
        return self.integration.application.id if self.integration.application else None

    @property
    def guild_id(self) -> snowflakes.Snowflake:
        # <<inherited docstring from GuildEvent>>.
        return self.integration.guild_id

    @property
    def id(self) -> snowflakes.Snowflake:
        # <<inherited docstring from IntegrationEvent>>
        return self.integration.id
Method resolution order
dataclass IntegrationUpdateEvent
That's this class!
abstract trait class IntegrationEvent

Event base for any integration related events …

abstract class GuildEvent

Event base for any guild-bound event …

abstract class ShardEvent

Base class for any event that was shard-specific.

abstract class Event

Base event type that all Hikari events should subclass.

extern class abc.ABC

Helper class that provides a standard way to create an ABC using inheritance.

Variables and properties
property apptraits.RESTAware

App instance for this application.

Returns

RESTAware
The REST-aware app trait.
property application_idOptional[snowflakes.Snowflake]

ID of Discord bot application this integration is connected to.

Returns

Optional[Snowflake]
The ID of Discord bot application this integration is connected to.
property guild_idsnowflakes.Snowflake

ID of the guild that this event relates to.

Returns

Snowflake
The ID of the guild that relates to this event.
property idsnowflakes.Snowflake

ID of the integration.

Returns

Snowflake
The ID of the integration.
property integrationguilds.Integration

Integration that was updated.

property shardgateway_shard.GatewayShard

Shard that received this event.

Returns

GatewayShard
The shard that triggered the event.
Methods
async def fetch_guild() -> guilds.RESTGuild: ...

Inherited from: IntegrationEvent.fetch_guild

Perform an API call to get the guild that this event relates to.

Returns

RESTGuild
The guild this event occurred in.
async def fetch_guild_preview() -> guilds.GuildPreview: ...

Inherited from: IntegrationEvent.fetch_guild_preview

Perform an API call to get the preview of the event's guild.

Returns

GuildPreview
The preview of the guild this event occurred in.
async def fetch_integrations() -> Sequence[guilds.Integration]: ...

Inherited from: IntegrationEvent.fetch_integrations

Perform an API call to fetch some number of guild integrations.

Warning

The results of this are not clearly defined by Discord. The current behaviour appears to be that only the first 50 integrations actually get returned. Discord have made it clear that they are not willing to fix this in https://github.com/discord/discord-api-docs/issues/1990.

Returns

Sequence[Integration]
Some possibly random subset of the integrations in a guild, probably.
def get_guild() -> Optional[guilds.GatewayGuild]: ...

Inherited from: IntegrationEvent.get_guild

Get the cached guild that this event relates to, if known.

If not known, this will return None instead.

Returns

Optional[GatewayGuild]
The guild this event relates to, or None if not known.
def bitmask() -> int: ...

Inherited from: IntegrationEvent.bitmask

Bitmask for this event.

def dispatches() -> Sequence[Type[Event]]: ...

Inherited from: IntegrationEvent.dispatches

Sequence of the event classes this event is dispatched as.

dataclass PresenceUpdateEvent

class PresenceUpdateEvent (
    *,
    shard: gateway_shard.GatewayShard,
    old_presence: Optional[presences_.MemberPresence],
    presence: presences_.MemberPresence,
    user: Optional[users.PartialUser],
): ...

Event fired when a user in a guild updates their presence in a guild.

Sent when a guild member changes their presence in a specific guild.

If the user is changed (e.g. new username), then this may fire many times (once for every guild the bot is part of). This is a limitation of how Discord implements their event system, unfortunately.

Furthermore, if the target user is a bot and the bot only updates their presence on specific shards, this will only fire for the corresponding shards that saw the presence update.

This requires one of the following combinations of intents in order to be dispatched:

Method generated by attrs for class PresenceUpdateEvent.

Expand source code
Browse git
class PresenceUpdateEvent(shard_events.ShardEvent):
    """Event fired when a user in a guild updates their presence in a guild.

    Sent when a guild member changes their presence in a specific guild.

    If the user is changed (e.g. new username), then this may fire many times
    (once for every guild the bot is part of). This is a limitation of how
    Discord implements their event system, unfortunately.

    Furthermore, if the target user is a bot and the bot only updates their
    presence on specific shards, this will only fire for the corresponding
    shards that saw the presence update.
    """

    shard: gateway_shard.GatewayShard = attr.field(metadata={attr_extensions.SKIP_DEEP_COPY: True})
    # <<inherited docstring from ShardEvent>>.

    old_presence: typing.Optional[presences_.MemberPresence] = attr.field()
    """The old member presence object.

    This will be `builtins.None` if the member presence missing from the cache.
    """

    presence: presences_.MemberPresence = attr.field()
    """Member presence.

    Returns
    -------
    hikari.presences.MemberPresence
        Presence for the user in this guild.
    """

    user: typing.Optional[users.PartialUser] = attr.field()
    """User that was updated.

    This is a partial user object that only contains the fields that were
    updated on the user profile.

    Will be `builtins.None` if the user itself did not change.
    This is always the case if the user only updated their member
    representation and did not change their user profile directly.

    Returns
    -------
    typing.Optional[hikari.users.PartialUser]
        The partial user containing the updated fields.
    """

    @property
    def app(self) -> traits.RESTAware:
        # <<inherited docstring from Event>>.
        return self.presence.app

    @property
    def user_id(self) -> snowflakes.Snowflake:
        """User ID of the user that updated their presence.

        Returns
        -------
        hikari.snowflakes.Snowflake
            ID of the user the event concerns.
        """
        return self.presence.user_id

    @property
    def guild_id(self) -> snowflakes.Snowflake:
        """Guild ID that the presence was updated in.

        Returns
        -------
        hikari.snowflakes.Snowflake
            ID of the guild the event occurred in.
        """
        return self.presence.guild_id

    def get_user(self) -> typing.Optional[users.User]:
        """Get the full cached user, if it is available.

        Returns
        -------
        typing.Optional[hikari.users.User]
            The full cached user, or `builtins.None` if not cached.
        """
        if not isinstance(self.app, traits.CacheAware):
            return None

        return self.app.cache.get_user(self.user_id)

    async def fetch_user(self) -> users.User:
        """Perform an API call to fetch the user this event concerns.

        Returns
        -------
        hikari.users.User
            The user affected by this event.
        """
        return await self.app.rest.fetch_user(self.user_id)
Method resolution order
dataclass PresenceUpdateEvent
That's this class!
abstract class ShardEvent

Base class for any event that was shard-specific.

abstract class Event

Base event type that all Hikari events should subclass.

extern class abc.ABC

Helper class that provides a standard way to create an ABC using inheritance.

Variables and properties
property appRESTAware

App instance for this application.

Returns

RESTAware
The REST-aware app trait.
property guild_idsnowflakes.Snowflake

Guild ID that the presence was updated in.

Returns

Snowflake
ID of the guild the event occurred in.
property old_presenceOptional[presences_.MemberPresence]

The old member presence object.

This will be None if the member presence missing from the cache.

property presencepresences_.MemberPresence

Member presence.

Returns

MemberPresence
Presence for the user in this guild.
property shardgateway_shard.GatewayShard

Shard that received this event.

Returns

GatewayShard
The shard that triggered the event.
property userOptional[users.PartialUser]

User that was updated.

This is a partial user object that only contains the fields that were updated on the user profile.

Will be None if the user itself did not change. This is always the case if the user only updated their member representation and did not change their user profile directly.

Returns

Optional[PartialUser]
The partial user containing the updated fields.
property user_idsnowflakes.Snowflake

User ID of the user that updated their presence.

Returns

Snowflake
ID of the user the event concerns.
Methods
async def fetch_user() -> users.User: ...

Perform an API call to fetch the user this event concerns.

Returns

User
The user affected by this event.
Expand source code
Browse git
async def fetch_user(self) -> users.User:
    """Perform an API call to fetch the user this event concerns.

    Returns
    -------
    hikari.users.User
        The user affected by this event.
    """
    return await self.app.rest.fetch_user(self.user_id)
def get_user() -> Optional[users.User]: ...

Get the full cached user, if it is available.

Returns

Optional[User]
The full cached user, or None if not cached.
Expand source code
Browse git
def get_user(self) -> typing.Optional[users.User]:
    """Get the full cached user, if it is available.

    Returns
    -------
    typing.Optional[hikari.users.User]
        The full cached user, or `builtins.None` if not cached.
    """
    if not isinstance(self.app, traits.CacheAware):
        return None

    return self.app.cache.get_user(self.user_id)
def bitmask() -> int: ...

Inherited from: ShardEvent.bitmask

Bitmask for this event.

def dispatches() -> Sequence[Type[Event]]: ...

Inherited from: ShardEvent.dispatches

Sequence of the event classes this event is dispatched as.