platforms.discord module

Discord platform adapter using discord.py.

Wraps a discord.Client and converts Discord events into IncomingMessage instances for the shared MessageProcessor.

class platforms.discord.DiscordPlatform(message_handler, *, token, config=None, media_cache=None, message_update_handler=None, message_delete_handler=None, reaction_update_handler=None)[source]

Bases: PlatformAdapter

Platform adapter for Discord via discord.py.

Parameters:
  • message_handler (Callable[[IncomingMessage, PlatformAdapter], Awaitable[None]]) – Async callback that receives IncomingMessage instances.

  • token (str) – Discord bot token.

  • config (Config | None)

  • media_cache (MediaCache | None)

  • message_update_handler (MessageUpdateHandler | None)

  • message_delete_handler (MessageDeleteHandler | None)

  • reaction_update_handler (ReactionUpdateHandler | None)

__init__(message_handler, *, token, config=None, media_cache=None, message_update_handler=None, message_delete_handler=None, reaction_update_handler=None)[source]

Initialize the instance.

Parameters:
Return type:

None

property lyria_service

Lyria RealTime music service for voice channel playback.

property name: str

Name.

Returns:

Result string.

Return type:

str

property is_running: bool

Check whether is running.

Returns:

True on success, False otherwise.

Return type:

bool

property client: discord.Client | None

Return the underlying discord.Client, or None.

property bot_identity: dict[str, str]

Return the bot’s own identity on this platform.

Returns a dict with at minimum platform and user_id. Adapters should override to provide display_name and mention where available. The default returns an empty user_id (safe to call before login completes).

async start()[source]

Start.

Return type:

None

async stop()[source]

Stop.

Return type:

None

async send(channel_id, text)[source]

Send.

Parameters:
  • channel_id (str) – Discord/Matrix channel identifier.

  • text (str) – Text content.

Returns:

Result string.

Return type:

str

async send_file(channel_id, data, filename, mimetype='application/octet-stream')[source]

Send file.

Parameters:
  • channel_id (str) – Discord/Matrix channel identifier.

  • data (bytes) – Input data payload.

  • filename (str) – The filename value.

  • mimetype (str) – The mimetype value.

Returns:

The CDN URL of the first attachment, or None on failure.

Return type:

str | None

async edit_message(channel_id, message_id, new_text)[source]

Edit an existing bot message in channel_id.

Return type:

bool

Parameters:
  • channel_id (str)

  • message_id (str)

  • new_text (str)

async send_with_buttons(channel_id, text, view=None)[source]

Send a message with a discord.ui.View of interactive buttons.

Used by the GameGirl Color system to attach choice buttons to game turn responses.

Return type:

str

Parameters:
async start_typing(channel_id)[source]

Start typing.

Parameters:

channel_id (str) – Discord/Matrix channel identifier.

Return type:

None

async stop_typing(channel_id)[source]

Stop typing.

Parameters:

channel_id (str) – Discord/Matrix channel identifier.

Return type:

None

async get_guild_members(guild_id)[source]

Return a cached list of all guild members with roles.

Results are cached per guild for _MEMBER_CACHE_TTL seconds (6 hours). Each member dict contains id, name, nickname, top_role, roles, and bot.

Parameters:

guild_id (str) – Discord guild (server) snowflake ID.

Return type:

list[dict[str, str]]

Returns:

List of member dicts, or empty list on failure.

async list_servers_and_channels()[source]

Return all Discord guilds and their channels.

Return type:

list[dict[str, Any]]

async get_channel_webhooks(channel_id)[source]

Retrieve the channel webhooks.

Parameters:

channel_id (str) – Discord/Matrix channel identifier.

Returns:

The result.

Return type:

list[dict[str, Any]]

async fetch_history(channel_id, limit=100)[source]

Fetch history.

Parameters:
  • channel_id (str) – Discord/Matrix channel identifier.

  • limit (int) – Maximum number of items.

Returns:

The result.

Return type:

list[HistoricalMessage]