Skip to main content
Glama

read_messages

Retrieve recent messages from a Discord channel to monitor conversations, track discussions, or analyze chat history.

Instructions

Read recent messages from a channel.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
channel_idYes
limitNo

Implementation Reference

  • Core handler function that fetches recent messages from a Discord channel using channel.history(), processes reactions, and returns formatted TextContent with message details including author, content, timestamp, and reactions.
    @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) )]
  • Tool schema definition in the list_tools() function, specifying input parameters: required channel_id (string) and optional limit (number 1-100). This registers the tool with MCP server.
    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"] } ),
  • The read_messages tool is included in the core_tool_names list used by the call_tool dispatcher to route execution to CoreToolHandlers.handle_read_messages.
    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" ]

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