Skip to content

Events

ballsdex.core.events

__all__

__all__ = ('BallsDexEvent', 'BallSpawnedEvent', 'BallCaughtEvent', 'TradeCompletedEvent', 'BallGivenEvent', 'dispatch')

BallCaughtEvent

BallCaughtEvent(view: BallSpawnView, user: User | Member, player: Player, guild: Guild | None, ball_instance: BallInstance, is_new: bool)

Bases: BallsDexEvent

A spawned countryball was caught.

Listener: on_ballsdex_ball_caught(event)

Attributes:

  • view (BallSpawnView) –

    The view of the spawn that was caught.

  • user (User | Member) –

    The user who caught the countryball.

  • player (Player) –

    The player who caught the countryball.

  • guild (Guild | None) –

    The guild the countryball was caught in.

  • ball_instance (BallInstance) –

    The countryball now owned by the player. This is a new instance, unless dropped is set.

  • is_new (bool) –

    Whether this is the first time the player owns this countryball.

ball_instance

ball_instance: BallInstance

dropped

dropped: bool

Whether this was an existing countryball dropped by a player. The ownership was transferred to the catcher, unless the owner caught it back.

event_name

event_name = 'ballsdex_ball_caught'

guild

guild: Guild | None

is_new

is_new: bool

player

player: Player

user

user: User | Member

view

view: BallSpawnView

BallGivenEvent

BallGivenEvent(sender: Player, recipient: Player, ball_instances: list[BallInstance], trade: Trade)

Bases: BallsDexEvent

One or more countryballs were given by a player to another, with /balls give, /balls bulk_give or an accepted donation request.

Listener: on_ballsdex_ball_given(event)

Attributes:

ball_instances

ball_instances: list[BallInstance]

event_name

event_name = 'ballsdex_ball_given'

recipient

recipient: Player

sender

sender: Player

trade

trade: Trade

BallSpawnedEvent

BallSpawnedEvent(view: BallSpawnView, channel: TextChannel)

Bases: BallsDexEvent

A countryball was spawned in a channel. This includes natural spawns, admin spawns and dropped countryballs.

Listener: on_ballsdex_ball_spawned(event)

Attributes:

  • view (BallSpawnView) –

    The view attached to the spawn message.

  • channel (TextChannel) –

    The channel the countryball was spawned in.

ball

ball: Ball

The countryball that spawned.

channel

channel: TextChannel

dropped

dropped: bool

Whether this is an existing countryball dropped by a player rather than a new spawn.

event_name

event_name = 'ballsdex_ball_spawned'

message

message: Message

The spawn message.

view

view: BallSpawnView

BallsDexEvent

Base class for all event payloads.

Attributes:

event_name

event_name: str

TradeCompletedEvent

TradeCompletedEvent(trade: Trade, trader1: TradingUser, trader2: TradingUser)

Bases: BallsDexEvent

A trade between two players was confirmed and saved.

The countryballs exchanged can be fetched with TradeObject.objects.filter(trade=event.trade).

Listener: on_ballsdex_trade_completed(event)

Attributes:

  • trade (Trade) –

    The trade entry that was saved.

  • trader1 (TradingUser) –

    The user who started the trade.

  • trader2 (TradingUser) –

    The other user of the trade.

event_name

event_name = 'ballsdex_trade_completed'

trade

trade: Trade

trader1

trader1: TradingUser

trader2

trader2: TradingUser

dispatch

dispatch(bot: Client, event: BallsDexEvent)

Dispatch an event to all listeners.

Parameters:

Source code in ballsdex/core/events.py
def dispatch(bot: discord.Client, event: BallsDexEvent):
    """
    Dispatch an event to all listeners.

    Parameters
    ----------
    bot: discord.Client
        The bot instance.
    event: BallsDexEvent
        The event payload to send.
    """
    bot.dispatch(event.event_name, event)