Source code for tools.stop_music

"""Stop the active Lyria music stream and disconnect from voice."""

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 = "stop_music"
TOOL_DESCRIPTION = (
    "Stop the currently playing Lyria music stream and disconnect from the "
    "Discord voice channel. 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: """Stop the active Lyria stream and disconnect.""" 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.stop(guild_id_int)