Skip to main content
Glama
wowjinxy
by wowjinxy

read_messages

Retrieve recent messages from a Discord channel to monitor conversations, review discussions, or gather information for analysis.

Instructions

Read recent messages from a channel.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
channel_idYes
limitNo

Implementation Reference

  • The main handler function for the 'read_messages' tool. Fetches recent messages from the specified Discord channel, processes reactions, formats the output with author, timestamp, content, and reactions, and returns as TextContent.
    @staticmethod
    async def handle_read_messages(discord_client, arguments: Dict[str, Any]) -> List[TextContent]:
        """Read recent messages from a channel"""
        channel = await discord_client.fetch_channel(int(arguments["channel_id"]))
        limit = min(int(arguments.get("limit", 10)), 100)
        
        messages = []
        async for message in channel.history(limit=limit):
            reaction_data = []
            for reaction in message.reactions:
                emoji_str = str(reaction.emoji.name) if hasattr(reaction.emoji, 'name') and reaction.emoji.name else str(reaction.emoji.id) if hasattr(reaction.emoji, 'id') else str(reaction.emoji)
                reaction_info = {
                    "emoji": emoji_str,
                    "count": reaction.count
                }
                reaction_data.append(reaction_info)
            
            messages.append({
                "id": str(message.id),
                "author": str(message.author),
                "content": message.content,
                "timestamp": message.created_at.strftime('%Y-%m-%d %H:%M:%S'),
                "reactions": reaction_data
            })
        
        def format_reaction(r):
            return f"{r['emoji']}({r['count']})"
        
        formatted_messages = []
        for m in messages:
            reactions_str = ', '.join([format_reaction(r) for r in m['reactions']]) if m['reactions'] else 'No reactions'
            formatted_messages.append(
                f"**{m['author']}** ({m['timestamp']}): {m['content']}\n"
                f"   Reactions: {reactions_str}"
            )
        
        return [TextContent(
            type="text",
            text=f"**Recent messages from #{channel.name}** ({len(messages)} messages):\n\n" + 
                 "\n\n".join(formatted_messages)
        )]
  • JSON schema defining the input parameters for the 'read_messages' tool: required 'channel_id' (string) and optional 'limit' (number, 1-100). This is part of the tool registration in list_tools().
    Tool(
        name="read_messages",
        description="Read recent messages from a channel with reactions",
        inputSchema={
            "type": "object",
            "properties": {
                "channel_id": {
                    "type": "string",
                    "description": "Discord channel ID"
                },
                "limit": {
                    "type": "number",
                    "description": "Number of messages to fetch (max 100)",
                    "minimum": 1,
                    "maximum": 100
                }
            },
            "required": ["channel_id"]
        }
    ),
  • Registration and routing logic for core tools including 'read_messages'. Checks if the tool name is in core_tool_names and dynamically calls the corresponding handler method on CoreToolHandlers.
    core_tool_names = [
        "get_server_info", "list_servers", "get_channels", "list_members",
        "get_user_info", "send_message", "read_messages", "add_reaction",
        "add_multiple_reactions", "remove_reaction", "moderate_message",
        "create_text_channel", "delete_channel", "add_role", "remove_role"
    ]
    
    if name in core_tool_names:
        handler_method = f"handle_{name}"
        if hasattr(CoreToolHandlers, handler_method):
            return await getattr(CoreToolHandlers, handler_method)(discord_client, arguments)

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/wowjinxy/mcp-discord'

If you have feedback or need assistance with the MCP directory API, please join our Discord server