Skip to main content
Glama

discord_read_dms

Retrieve recent direct messages from any Discord user by providing their user ID. Specify the number of messages to fetch (up to 100) for quick access to conversation history.

Instructions

Read the last N messages from a DM conversation with a user.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
user_idYesThe Discord user ID.
limitNo1–100, default 20.

Implementation Reference

  • The handler function for discord_read_dms. Fetches the DM channel, retrieves up to 'limit' messages (1-100, default 20), sorts them chronologically, and returns them as a JSON string with id, author, content, embed count, and timestamp.
    case "discord_read_dms": {
      const user = await discord.users.fetch(validateId(args.user_id, "user_id"));
      const dm = await user.createDM();
      const limit = Math.min(Math.max(Number(args.limit ?? 20), 1), 100);
      const messages = await dm.messages.fetch({ limit });
      const result = [...messages.values()]
        .sort((a, b) => a.createdTimestamp - b.createdTimestamp)
        .map((m) => ({
          id: m.id,
          author: m.author.username,
          content: m.content,
          embeds: m.embeds.length,
          timestamp: m.createdAt.toISOString(),
        }));
      return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
    }
  • The input schema definition for discord_read_dms: requires user_id (string), optional limit (number, 1-100, default 20).
    {
      name: "discord_read_dms",
      description:
        "Read the last N messages from a DM conversation with a user.",
      inputSchema: {
        type: "object",
        properties: {
          ...userIdProp,
          limit: { type: "number", description: "1–100, default 20." },
        },
        required: ["user_id"],
      },
    },
  • The dm module is imported and added to the modules array, registering all DM tools (including discord_read_dms) with the tool registry.
    import dm from "./dm.js";
    
    const modules: ToolModule[] = [
      discovery,
      messages,
      channels,
      permissions,
      members,
      roles,
      moderation,
      screening,
      stats,
      forums,
      webhooks,
      scheduledEvents,
      invites,
      dm,
  • The validateId helper used to validate the user_id argument in the discord_read_dms handler.
    export function validateId(value: unknown, label: string): string {
      const id = String(value ?? "");
      if (!/^\d{17,20}$/.test(id)) throw new Error(`Invalid ${label}: "${id}". Must be a Discord snowflake ID (17-20 digits).`);
      return id;
    }
  • The surrounding handle() function that dispatches tool names via switch statement, where discord_read_dms is one case.
    async function handle(
      name: string,
      args: Record<string, unknown>
    ): Promise<ToolResult | null> {
      switch (name) {
        case "discord_send_dm": {
          const user = await discord.users.fetch(validateId(args.user_id, "user_id"));
          const sent = await user.send(args.content as string);
          return { content: [{ type: "text", text: `✅ DM sent to ${user.username} (message id: ${sent.id}).` }] };
        }
    
        case "discord_send_dm_embed": {
          const user = await discord.users.fetch(validateId(args.user_id, "user_id"));
          const embed = buildEmbed(args);
          const sent = await user.send({
            content: (args.content as string) || undefined,
            embeds: [embed],
          });
          return { content: [{ type: "text", text: `✅ DM embed sent to ${user.username} (message id: ${sent.id}).` }] };
        }
    
        case "discord_edit_dm": {
          const user = await discord.users.fetch(validateId(args.user_id, "user_id"));
          const dm = await user.createDM();
          const msgId = validateId(args.message_id, "message_id");
          const msg = await dm.messages.fetch(msgId);
          if (msg.author.id !== discord.user?.id) throw new Error("Can only edit messages sent by the bot.");
          await msg.edit(args.content as string);
          return { content: [{ type: "text", text: `✅ DM message ${msgId} edited for ${user.username}.` }] };
        }
    
        case "discord_edit_dm_embed": {
          const user = await discord.users.fetch(validateId(args.user_id, "user_id"));
          const dm = await user.createDM();
          const msgId = validateId(args.message_id, "message_id");
          const msg = await dm.messages.fetch(msgId);
          if (msg.author.id !== discord.user?.id) throw new Error("Can only edit embeds sent by the bot.");
          const embed = buildEmbed(args);
          await msg.edit({
            content: (args.content as string) || undefined,
            embeds: [embed],
          });
          return { content: [{ type: "text", text: `✅ DM embed edited on message ${msgId} for ${user.username}.` }] };
        }
    
        case "discord_delete_dm": {
          const user = await discord.users.fetch(validateId(args.user_id, "user_id"));
          const dm = await user.createDM();
          const msgId = validateId(args.message_id, "message_id");
          const msg = await dm.messages.fetch(msgId);
          if (msg.author.id !== discord.user?.id) throw new Error("Can only delete messages sent by the bot.");
          await msg.delete();
          return { content: [{ type: "text", text: `✅ DM message ${msgId} deleted for ${user.username}.` }] };
        }
    
        case "discord_read_dms": {
          const user = await discord.users.fetch(validateId(args.user_id, "user_id"));
          const dm = await user.createDM();
          const limit = Math.min(Math.max(Number(args.limit ?? 20), 1), 100);
          const messages = await dm.messages.fetch({ limit });
          const result = [...messages.values()]
            .sort((a, b) => a.createdTimestamp - b.createdTimestamp)
            .map((m) => ({
              id: m.id,
              author: m.author.username,
              content: m.content,
              embeds: m.embeds.length,
              timestamp: m.createdAt.toISOString(),
            }));
          return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
        }
    
        case "discord_reply_dm": {
          const user = await discord.users.fetch(validateId(args.user_id, "user_id"));
          const dm = await user.createDM();
          const msgId = validateId(args.message_id, "message_id");
          const target = await dm.messages.fetch(msgId);
          const sent = await target.reply(args.content as string);
          return { content: [{ type: "text", text: `✅ DM reply sent to ${user.username} (message id: ${sent.id}).` }] };
        }
    
        default:
          return null;
      }
    }
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Without annotations, the description only states the basic action, omitting details like whether messages are marked as read, rate limits, or authentication needs, which are important for a read operation.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, clear sentence with no redundant words, efficiently conveying the tool's purpose.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's simplicity (2 params, read-only), the description is mostly complete, but it could mention the output format (list of messages) or any side effects.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, so baseline is 3. The description adds no extra meaning beyond the schema's parameter descriptions, only reiterating the limit concept.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description uses a specific verb ('Read') and resource ('last N messages from a DM conversation'), clearly distinguishing it from sibling tools like send, delete, or edit.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides clear context for reading DMs, and the sibling list implies alternative actions, but it does not explicitly state when not to use or mention prerequisites.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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

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