summaryrefslogtreecommitdiff
path: root/external_plugins
diff options
context:
space:
mode:
authorEdouard Oger <eoger@anthropic.com>2026-11-17 13:14:13 -0800
committerEdouard Oger <eoger@anthropic.com>2026-11-17 13:14:13 -0800
commitd761ce2e989c211d27edffa303e5c2a3aae8f976 (patch)
treed7558c5d0a82c571d9684e6057b46a84b652a4e5 /external_plugins
parentfd30cee3ecd5a8ee772733c5d20c0f2bae2da2f0 (diff)
feat(discord): add list_emojis tool
Diffstat (limited to 'external_plugins')
-rw-r--r--external_plugins/discord/.claude-plugin/plugin.json2
-rw-r--r--external_plugins/discord/README.md1
-rw-r--r--external_plugins/discord/server.ts59
3 files changed, 60 insertions, 2 deletions
diff --git a/external_plugins/discord/.claude-plugin/plugin.json b/external_plugins/discord/.claude-plugin/plugin.json
index 6418b1ec..0bae2cbc 100644
--- a/external_plugins/discord/.claude-plugin/plugin.json
+++ b/external_plugins/discord/.claude-plugin/plugin.json
@@ -1,7 +1,7 @@
{
"name": "discord",
"description": "Discord channel for Claude Code \u2014 messaging bridge with built-in access control. Manage pairing, allowlists, and policy via /discord:access.",
- "version": "0.0.4",
+ "version": "0.0.6",
"keywords": [
"discord",
"messaging",
diff --git a/external_plugins/discord/README.md b/external_plugins/discord/README.md
index ad04f6fa..f53029af 100644
--- a/external_plugins/discord/README.md
+++ b/external_plugins/discord/README.md
@@ -93,6 +93,7 @@ Quick reference: IDs are Discord **snowflakes** (numeric — enable Developer Mo
| --- | --- |
| `reply` | Send to a channel. Takes `chat_id` + `text`, optionally `reply_to` (message ID) for native threading and `files` (absolute paths) for attachments — max 10 files, 25MB each. Auto-chunks; files attach to the first chunk. Returns the sent message ID(s). |
| `react` | Add an emoji reaction to any message by ID. Unicode emoji work directly; custom emoji need `<:name:id>` form. |
+| `list_emojis` | List the custom emoji the bot can use in a chat, in the `<:name:id>` form `react` and `reply` need. A server channel lists that server's emoji; a DM lists those of servers with an opted-in channel. The application's own emoji (Developer Portal → Emojis) are always included. Optional `query` filters by name; capped at 200 per call. |
| `edit_message` | Edit a message the bot previously sent. Useful for "working…" → result progress updates. Only works on the bot's own messages. |
| `fetch_messages` | Pull recent history from a channel (oldest-first). Capped at 100 per call. Each line includes the message ID so the model can `reply_to` it; messages with attachments are marked `+Natt`. Discord's search API isn't exposed to bots, so this is the only lookback. |
| `download_attachment` | Download all attachments from a specific message by ID to `~/.claude/channels/discord/inbox/`. Returns file paths + metadata. Use when `fetch_messages` shows a message has attachments. |
diff --git a/external_plugins/discord/server.ts b/external_plugins/discord/server.ts
index 0595fc7e..4c2bc31a 100644
--- a/external_plugins/discord/server.ts
+++ b/external_plugins/discord/server.ts
@@ -27,6 +27,7 @@ import {
ActionRowBuilder,
type Message,
type Attachment,
+ type Emoji,
type Interaction,
} from 'discord.js'
import { randomBytes } from 'crypto'
@@ -131,6 +132,7 @@ function defaultAccess(): Access {
const MAX_CHUNK_LIMIT = 2000
const MAX_ATTACHMENT_BYTES = 25 * 1024 * 1024
+const MAX_EMOJIS_LISTED = 200
// reply's files param takes any path. .env is ~60 bytes and ships as an
// upload. Claude can already Read+paste file contents, so this isn't a new
@@ -543,7 +545,7 @@ mcp.setRequestHandler(ListToolsRequestSchema, async () => ({
},
{
name: 'react',
- description: 'Add an emoji reaction to a Discord message. Unicode emoji work directly; custom emoji need the <:name:id> form.',
+ description: 'Add an emoji reaction to a Discord message. Unicode emoji work directly; custom emoji need the <:name:id> form from list_emojis.',
inputSchema: {
type: 'object',
properties: {
@@ -555,6 +557,19 @@ mcp.setRequestHandler(ListToolsRequestSchema, async () => ({
},
},
{
+ name: 'list_emojis',
+ description:
+ "List the custom emoji the bot can use in a chat, ready to paste into react or reply (<:name:id>, or <a:name:id> when animated). A server channel lists that server's emoji; a DM lists those of servers with an opted-in channel. The bot application's own emoji are always included. Unicode emoji aren't listed.",
+ inputSchema: {
+ type: 'object',
+ properties: {
+ chat_id: { type: 'string' },
+ query: { type: 'string', description: 'Only emoji whose name contains this text (case-insensitive).' },
+ },
+ required: ['chat_id'],
+ },
+ },
+ {
name: 'edit_message',
description: 'Edit a message the bot previously sent. Useful for interim progress updates. Edits don\'t trigger push notifications — send a new reply when a long task completes so the user\'s device pings.',
inputSchema: {
@@ -683,6 +698,48 @@ mcp.setRequestHandler(CallToolRequestSchema, async req => {
await msg.react(args.emoji as string)
return { content: [{ type: 'text', text: 'reacted' }] }
}
+ case 'list_emojis': {
+ const ch = await fetchAllowedChannel(args.chat_id as string)
+ // A DM has no server. Use the servers with an opted-in channel, not
+ // every server the bot happens to be in.
+ const channels = ch.type === ChannelType.DM
+ ? await Promise.all(Object.keys(loadAccess().groups).map(id => client.channels.fetch(id).catch(() => null)))
+ : [ch]
+ const guilds = new Set(channels.flatMap(c => (c && 'guild' in c ? [c.guild] : [])))
+
+ const emojis: Emoji[] = []
+ const failed: string[] = []
+ for (const guild of guilds) {
+ try {
+ const myRoles = guild.members.me?.roles.cache
+ for (const e of (await guild.emojis.fetch()).values()) {
+ // Skip emoji the server lost with its boosts, and ones limited to roles the bot lacks.
+ if (e.available === false) continue
+ if (e.roles.cache.size > 0 && !e.roles.cache.some(r => myRoles?.has(r.id) ?? false)) continue
+ emojis.push(e)
+ }
+ } catch (err) {
+ failed.push(`server ${guild.id} (${(err as Error).message})`)
+ }
+ }
+ try {
+ if (!client.application) throw new Error('bot not connected yet')
+ emojis.push(...(await client.application.emojis.fetch()).values())
+ } catch (err) {
+ failed.push(`the application (${(err as Error).message})`)
+ }
+ if (failed.length === guilds.size + 1) throw new Error(`could not fetch emoji of ${failed.join(', ')}`)
+
+ const query = ((args.query as string | undefined) ?? '').replaceAll(':', '').toLowerCase()
+ const matches = emojis.filter(e => e.name?.toLowerCase().includes(query))
+ const lines = matches.slice(0, MAX_EMOJIS_LISTED).map(e => `<${e.animated ? 'a' : ''}:${e.name}:${e.id}>`)
+ if (matches.length === 0) lines.push(query ? `(no custom emoji match "${query}")` : '(no custom emoji found)')
+ if (matches.length > MAX_EMOJIS_LISTED) {
+ lines.push(`(showing ${MAX_EMOJIS_LISTED} of ${matches.length} — pass query to narrow)`)
+ }
+ if (failed.length > 0) lines.push(`(partial list — could not fetch emoji of ${failed.join(', ')})`)
+ return { content: [{ type: 'text', text: lines.join('\n') }] }
+ }
case 'edit_message': {
const ch = await fetchAllowedChannel(args.chat_id as string)
const msg = await ch.messages.fetch(args.message_id as string)