PokeGambler: bot.py

The Main Module which serves as the brain of the code.

class PokeGambler[source]

PokeGambler: A Discord Bot using pokemon themed cards for gambling. Subclass of discord.Client which serves as the base for PokeGambler bot.

Parameters
  • error_log_path (str) – Path to the error log file.

  • assets_path (str) – Path to the assets folder.

logger

The CustomLogger for PokeGambler.

dealer

The CardGambler for Gamble matches.

topgg

topgg.client.DBLClient for handling votes and stats.

Tip

Check out PokeGambler’s Top.gg page.

slasher

The SlashHandler for handling slash commands.

ctx_cmds

The ContextHandler for handling context commands.

autocompleter

The AutocompleteHandler for handling command option autocomplete.

async on_message()[source]

Called when a discord.Message is created and sent.

Note

This requires discord.Intents.messages to be enabled.

Parameters

message (discord.Message) – The message which triggered the event.

async on_interaction()[source]
Called when an interaction happened.
This currently happens due to slash command invocations or components being used.
Parameters

interaction (discord.Interaction) – The interaction data.

run()[source]

A blocking call that abstracts away the event loop initialisation from you.

If you want more control over the event loop then this function should not be used. Use discord.Client.start() coroutine or discord.Client.connect() + discord.Client.login().

Roughly Equivalent to:

try:
    loop.run_until_complete(start(*args, **kwargs))
except KeyboardInterrupt:
    loop.run_until_complete(close())
    # cancel all tasks lingering
finally:
    loop.close()

Warning

This function must be the last function to call due to the fact that it is blocking. That means that registration of events or anything being called after this function call will not execute until it returns.

async on_guild_join()[source]

Called when a discord.Guild is either created by the PokeGambler or when PokeGambler joins a guild.

Note

This requires discord.Intents.guilds to be enabled.

Parameters

guild (discord.Guild) – The guild which added PokeGambler.

async on_guild_remove()[source]

Called when a discord.Guild is removed from the PokeGambler.

This happens through, but not limited to, these circumstances:

  • The client got banned.

  • The client got kicked.

  • The client left the guild.

  • The client or the guild owner deleted the guild.

In order for this event to be invoked, PokeGambler must have been part of the guild to begin with. (i.e. it is part of PokeGambler.guilds)

Note

This requires discord.Intents.guilds to be enabled.

Parameters

guild (discord.Guild) – The guild which was removed from PokeGambler.

async on_ready()[source]

Called when the client is done preparing the data received from Discord. Usually after login is successful and the PokeGambler.guilds and co. are filled up.

Warning

This function is not guaranteed to be the first event called. Likewise, this function is not guaranteed to only be called once. This library implements reconnection logic and thus will end up calling this event whenever a RESUME request fails.

async slash_sync()[source]

Synchronizes the slash commands.

load_commands()[source]

Hot Module Import for Commands.

Parameters
  • module_type (str) – The module type to load.

  • reload_module (bool) – Whether the module is preloaded.

Returns

The loaded module.

Return type

Commands