2026-03-20 17:39:45 +09:00
|
|
|
"""Discord 채널/스레드 메시지 전송 도구."""
|
|
|
|
|
from __future__ import annotations
|
2026-03-20 14:55:41 +09:00
|
|
|
|
2026-03-20 17:39:45 +09:00
|
|
|
import asyncio
|
|
|
|
|
import logging
|
|
|
|
|
import os
|
|
|
|
|
from typing import Any
|
2026-03-20 14:55:41 +09:00
|
|
|
|
2026-03-20 17:39:45 +09:00
|
|
|
from agent.utils.discord_client import get_discord_client
|
|
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def discord_reply(message: str) -> dict[str, Any]:
|
|
|
|
|
if not message.strip():
|
|
|
|
|
return {"success": False, "error": "빈 메시지는 전송할 수 없습니다."}
|
|
|
|
|
|
|
|
|
|
channel_id = os.environ.get("DISCORD_CHANNEL_ID", "")
|
|
|
|
|
if not channel_id:
|
|
|
|
|
return {"success": False, "error": "DISCORD_CHANNEL_ID가 설정되지 않았습니다."}
|
|
|
|
|
|
|
|
|
|
client = get_discord_client()
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
result = asyncio.run(
|
|
|
|
|
client.send_message(channel_id=channel_id, content=message)
|
|
|
|
|
)
|
|
|
|
|
logger.info("Sent Discord message to channel %s", channel_id)
|
|
|
|
|
return {"success": True, "message_id": result.get("id")}
|
|
|
|
|
except Exception as e:
|
|
|
|
|
logger.exception("Failed to send Discord message")
|
|
|
|
|
return {"success": False, "error": str(e)}
|