Skip to main content
Glama
users.ts•1.63 kB
import { z } from 'zod'; import type { ToolHandler } from '../tool-types.js'; import { Routes, type APIUser } from 'discord-api-types/v10'; import { REST } from '@discordjs/rest'; import { DiscordClient } from '../discord.js'; export function getUserTool(dc: DiscordClient): ToolHandler { const input = z.object({ user_id: z.string() }); return { name: 'discord_get_user', description: 'Get a user by ID.', inputSchema: input, async *handler({ input }: { input: any }){ const rest = (dc as any)['rest'] as REST; const user = await rest.get(Routes.user((input as any).user_id)) as APIUser; yield { content: [{ type: 'text', text: JSON.stringify(user) }] }; } }; } export function dmUserTool(dc: DiscordClient): ToolHandler { const input = z.object({ user_id: z.string(), content: z.string().max(4000), confirm: z.boolean().default(true) }); return { name: 'discord_dm_user', description: 'Send a DM to a user (human-in-the-loop by default).', inputSchema: input, async *handler({ input }: { input: any }){ const { user_id, content, confirm } = input as any; const rest = (dc as any)['rest'] as REST; if (confirm) { yield { content: [{ type: 'text', text: `Preview DM -> ${user_id}\n---\n${content}\n(Resend with {confirm:false})` }] }; return; } const dm = await rest.post(Routes.userChannels(), { body: { recipient_id: user_id } }) as any; const msg = await rest.post(Routes.channelMessages(dm.id), { body: { content } }); yield { content: [{ type: 'text', text: JSON.stringify(msg) }] }; } }; }

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

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