Skip to main content
Glama

read_messages

Fetch recent messages from a specified Discord channel by providing the channel ID and limit. Integrated with the MCP server for Discord functionality.

Instructions

Read recent messages from a channel

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
channel_idYesDiscord channel ID
limitNoNumber of messages to fetch (max 100)

Implementation Reference

  • Handler function for the 'read_messages' tool within the call_tool method. Fetches recent messages from a Discord channel, including reactions, and formats them into a text response.
    elif name == "read_messages": channel = await discord_client.fetch_channel(int(arguments["channel_id"])) limit = min(int(arguments.get("limit", 10)), 100) fetch_users = arguments.get("fetch_reaction_users", False) # Only fetch users if explicitly requested 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 } logger.error(f"Emoji: {emoji_str}") reaction_data.append(reaction_info) messages.append({ "id": str(message.id), "author": str(message.author), "content": message.content, "timestamp": message.created_at.isoformat(), "reactions": reaction_data # Add reactions to message dict }) # Helper function to format reactions def format_reaction(r): return f"{r['emoji']}({r['count']})" return [TextContent( type="text", text=f"Retrieved {len(messages)} messages:\n\n" + "\n".join([ f"{m['author']} ({m['timestamp']}): {m['content']}\n" + f"Reactions: {', '.join([format_reaction(r) for r in m['reactions']]) if m['reactions'] else 'No reactions'}" for m in messages ]) )]
  • Input schema definition for the 'read_messages' tool, specifying parameters for channel_id (required) and optional limit (1-100).
    Tool( name="read_messages", description="Read recent messages from a channel", 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 of the 'read_messages' tool in the list_tools handler via the Tool object returned by @app.list_tools().
    Tool( name="read_messages", description="Read recent messages from a channel", 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"] } ),

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/hanweg/mcp-discord'

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