discord_search_messages
Search Discord channel messages by keyword to find specific conversations or information within recent message history.
Instructions
Search messages in a channel by keyword (scans up to last 100 messages).
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| channel_id | Yes | ||
| keyword | Yes | ||
| limit | No | Max messages to scan (default 100). |
Implementation Reference
- src/tools/messages.ts:407-418 (handler)The handler implementation for the `discord_search_messages` tool, which fetches recent messages from a channel and filters them by a provided keyword.
case "discord_search_messages": { const channel = await getTextChannel(args.channel_id as string); const limit = Math.min(Math.max(Number(args.limit ?? 100), 1), 100); const messages = await channel.messages.fetch({ limit }); const keyword = (args.keyword as string).toLowerCase(); const matches = [...messages.values()] .filter((m) => m.content.toLowerCase().includes(keyword)) .sort((a, b) => a.createdTimestamp - b.createdTimestamp) .map((m) => ({ id: m.id, author: m.author.tag, content: m.content, timestamp: m.createdAt.toISOString() })); return { content: [{ type: "text", text: matches.length > 0 ? JSON.stringify(matches, null, 2) : `No messages found containing "${args.keyword}" in the last ${limit} messages.` }] }; } - src/tools/messages.ts:254-266 (schema)The schema definition for the `discord_search_messages` tool.
{ name: "discord_search_messages", description: "Search messages in a channel by keyword (scans up to last 100 messages).", inputSchema: { type: "object", properties: { channel_id: { type: "string" }, keyword: { type: "string" }, limit: { type: "number", description: "Max messages to scan (default 100)." }, }, required: ["channel_id", "keyword"], }, },