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
droppedis set. -
is_new(bool) –Whether this is the first time the player owns this countryball.
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.
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:
-
sender(Player) –The player who gave the countryballs.
-
recipient(Player) –The player who received the countryballs.
-
ball_instances(list[BallInstance]) –The countryballs given.
-
trade(Trade) –The trade entry registered for this donation.
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.
dropped
dropped: bool
Whether this is an existing countryball dropped by a player rather than a new spawn.
BallsDexEvent
Base class for all event payloads.
Attributes:
-
event_name(ClassVar[str]) –The name passed to
bot.dispatch. Listen to it withon_<event_name>.
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.
dispatch
dispatch(bot: Client, event: BallsDexEvent)
Dispatch an event to all listeners.
Parameters:
-
bot(Client) –The bot instance.
-
event(BallsDexEvent) –The event payload to send.