Discord client
Bases: Bot
Main Discord bot client for the Werewolf game.
This class is responsible for initializing the bot, wiring core components
(registry, controller, gateways), and orchestrating the startup lifecycle
(cogs and commands; the gateway events live in the GuildEvents cog).
Source code in sources/discord_api/client.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | |
__init__(*, sync_commands=True, commands_guild_id=None, settings=None)
¶
Initialize the Discord client and core dependencies.
Sets up Discord intents, uses mentions as the text command prefix (the bot relies on slash commands), and instantiates the main application components.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sync_commands
|
bool
|
Push the slash commands to Discord at startup. Syncing is rate limited, skip it when the commands did not change. |
True
|
commands_guild_id
|
int | None
|
Sync the slash commands on this guild only, where they are available at once (development), instead of globally where they take a while to propagate. |
None
|
settings
|
GameSettings | None
|
How the games are run, the production rules by default. |
None
|
Source code in sources/discord_api/client.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | |
setup_cogs()
async
¶
Register all cogs: the gateway events and the narrator commands.
Source code in sources/discord_api/client.py
62 63 64 65 66 | |
setup_hook()
async
¶
Run the bot initialization sequence.
This method is automatically called by discord.py before the bot connects to Discord. It orchestrates the full startup process: - loads cogs (event listeners and slash commands) - syncs slash commands
No view is registered as persistent: the setup of each guild purges the lobby and posts fresh views, so no button outlives a restart.
Raises:
| Type | Description |
|---|---|
Exception
|
Re-raised if any initialization step fails. |
Source code in sources/discord_api/client.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | |
sync_commands()
async
¶
Synchronize slash commands with Discord, globally or on one guild.
Source code in sources/discord_api/client.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | |