Source code for tools.pause_music

"""Pause the active Lyria music stream in a Discord voice channel."""

from __future__ import annotations

import logging
from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from tool_context import ToolContext

logger = logging.getLogger(__name__)

TOOL_NAME = "pause_music"
TOOL_DESCRIPTION = (
    "Pause the currently playing Lyria music stream in a Discord voice channel. "
    "Use resume_music to resume. Requires active music session."
)
TOOL_PARAMETERS = {
    "type": "object",
    "properties": {
        "guild_id": {"type": "string", "description": "Discord server (guild) ID."},
    },
    "required": ["guild_id"],
}


[docs] async def run( guild_id: str, ctx: "ToolContext | None" = None, ) -> str: """Pause the active Lyria stream.""" if ctx is None or not hasattr(ctx, "adapter") or ctx.adapter is None: return "Error: Discord adapter (ctx.adapter) is required." from tools._discord_helpers import get_discord_client client = get_discord_client(ctx) if isinstance(client, str): return client lyria = ctx.adapter.lyria_service try: guild_id_int = int(guild_id) except (ValueError, TypeError): return "Error: Invalid guild_id." return await lyria.pause(guild_id_int)