Skip to content

fix(discord): align tools with live API docs, add missing endpoints#5472

Open
waleedlatif1 wants to merge 5 commits into
stagingfrom
validate/discord-integration
Open

fix(discord): align tools with live API docs, add missing endpoints#5472
waleedlatif1 wants to merge 5 commits into
stagingfrom
validate/discord-integration

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • Fixed ban_member using deprecated delete_message_days field (Discord now uses delete_message_seconds)
  • Fixed get_server declaring phantom member_count/channels outputs that Discord's Guild endpoint never returns; now passes with_counts=true and uses the real approximate_member_count/approximate_presence_count fields
  • Fixed create_thread missing the type field for standalone threads, which caused Discord to silently default new threads to private
  • Fixed delete_channel discarding the deleted-channel response body Discord actually returns
  • Fixed get_pinned_messages — migrated off Discord's deprecated pins endpoint to the current one, and dropped an unused required serverId param that would fail every execution
  • Added .trim() on every URL-interpolated ID and bot token across all tool files to guard against copy-paste whitespace
  • Added 4 new tools: discord_list_channels, discord_list_roles, discord_get_pinned_messages, discord_bulk_delete_messages
  • Fixed block subBlock required flags (userId, content, messageId) so they match each operation's actual tool requirements
  • Removed 5 orphaned Discord OAuth scope descriptions (Discord auth is bot-token based, not OAuth)

Type of Change

  • Bug fix
  • New feature (new tools)

Testing

Tested manually — verified every tool against Discord's live API docs, ran bun run lint and bun run type-check clean, verified block/tool alignment and backwards compatibility (no tool ID/subBlock ID renames, no required-flag regressions for existing saved workflows).

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

- fix ban_member deprecated delete_message_days -> delete_message_seconds
- fix get_server phantom member_count/channels outputs, add with_counts support
- fix create_thread missing type field causing silent private-thread default
- fix delete_channel to return the deleted channel body
- fix get_pinned_messages to use the current (non-deprecated) pins endpoint and drop an unused required serverId param
- add .trim() on all URL-interpolated IDs and bot tokens across every tool
- add discord_list_channels, discord_list_roles, discord_get_pinned_messages, discord_bulk_delete_messages
- fix block subBlock required flags (userId, content, messageId) to match each operation's actual tool requirements
- remove orphaned Discord OAuth scope descriptions (Discord uses bot tokens, not OAuth)
@vercel

vercel Bot commented Jul 7, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Jul 7, 2026 4:04pm

Request Review

@cursor

cursor Bot commented Jul 7, 2026

Copy link
Copy Markdown

PR Summary

Medium Risk
Touches moderation and destructive actions (bulk delete, ban payload change) across many tools; changes are API-alignment fixes with backward-compatible block param IDs, but workflows relying on old ban or guild output field names could behave differently.

Overview
Brings Discord block and tools in line with the current API and expands coverage with four new operations: bulk delete messages, get pinned messages, list channels, and list roles.

API correctness fixes: ban_member now sends delete_message_seconds (block still exposes days and converts). get_server uses with_counts=true and documents approximate_member_count / approximate_presence_count instead of fields the guild endpoint does not return. Standalone create_thread sets public/private thread type so new threads are not silently private. get_pinned_messages uses the current pins endpoint with optional pagination. delete_channel returns the deleted channel in tool output.

Block UX: Operation-specific required flags and split fields (optional messageId for threads, optional userId for remove reaction, required webhook content, bulk-delete messageIds, thread visibility, category channel type). Orphaned Discord OAuth scope labels are removed from SCOPE_DESCRIPTIONS.

Hardening: .trim() on bot tokens and IDs in Discord tool URLs/headers across the integration.

Reviewed by Cursor Bugbot for commit 4fc5068. Configure here.

Comment thread apps/sim/tools/discord/create_thread.ts
@greptile-apps

greptile-apps Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR aligns the Discord integration with Discord's current v10 API by fixing several broken tools and adding four new ones. All stated fixes are correctly implemented: ban_member now sends delete_message_seconds, get_server uses ?with_counts=true and the real approximate count fields, create_thread pins the type field for standalone threads, delete_channel captures the returned channel object, and get_pinned_messages uses the new paginated pins endpoint with the correct ISO8601 before cursor.

  • Adds .trim() to every URL-interpolated ID and bot token across all 40+ tool files to guard against copy-paste whitespace.
  • Adds four new tools (discord_list_channels, discord_list_roles, discord_get_pinned_messages, discord_bulk_delete_messages) and wires them into the block, the registry, and the type union.
  • Tightens block subBlock required flags: userId is now required only for operations that need it, content is required for execute_webhook, and messageId is optional for create_thread (standalone threads are now supported).

Confidence Score: 5/5

Safe to merge — all bug fixes are verified against Discord's live API documentation and the new tools follow established patterns throughout the codebase.

Every stated fix was verified: delete_message_seconds is the current Discord API field, ?with_counts=true returns the correct approximate count fields, standalone thread type values (11/12) match Discord's channel type enum, the ISO8601 before cursor for the paginated pins endpoint is confirmed by discord-api-types, and bulk-delete correctly omits reading the 204 No Content body. The four new tools are consistent with sibling tools and correctly wired into the block and registry. No logic errors, incorrect API calls, or data-loss paths were found.

No files require special attention.

Important Files Changed

Filename Overview
apps/sim/blocks/blocks/discord.ts Wires all four new tools into the block, fixes subBlock required flags (userId, content, messageId), adds threadVisibility dropdown, splits the messageId subBlock so create_thread is optional while pin/unpin remain required.
apps/sim/tools/discord/bulk_delete_messages.ts New tool; correctly validates 2-100 message IDs, maps to POST /channels/{id}/messages/bulk-delete, and skips reading the 204 No Content response body.
apps/sim/tools/discord/get_pinned_messages.ts New tool using the current paginated pins endpoint; before cursor correctly uses ISO8601 timestamp (confirmed against Discord live API docs), and items[].message mapping matches the APIMessagePin wrapper shape.
apps/sim/tools/discord/create_thread.ts Adds type field (11=PUBLIC_THREAD, 12=PRIVATE_THREAD) for standalone threads, preventing silent Discord default to private; message-sourced threads are unaffected.
apps/sim/tools/discord/ban_member.ts Correctly migrates from deprecated delete_message_days to delete_message_seconds (0-604800); block converts UI-entered days to seconds with x86400 before dispatch.
apps/sim/tools/discord/get_server.ts Fixes phantom member_count/channels outputs by passing ?with_counts=true and mapping to the real approximate_member_count/approximate_presence_count fields.
apps/sim/tools/discord/delete_channel.ts Now reads and returns the deleted-channel response body that Discord sends back, fixing the previously discarded data.
apps/sim/tools/discord/list_channels.ts New tool for GET /guilds/{id}/channels; clean implementation consistent with sibling tools.
apps/sim/tools/discord/list_roles.ts New tool for GET /guilds/{id}/roles; clean implementation consistent with sibling tools.
apps/sim/tools/discord/types.ts Adds four new param/response interfaces, exports DiscordMessage for use in get_pinned_messages, and fixes DiscordGuild to match actual Discord API fields.
apps/sim/lib/oauth/utils.ts Removes 5 orphaned Discord OAuth scope descriptions that were irrelevant since Discord auth is bot-token based.
apps/sim/tools/registry.ts Registers the four new Discord tools; no issues.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Discord Block UI] --> B{Operation}
    B --> D[discord_bulk_delete_messages]
    B --> E[discord_get_pinned_messages]
    B --> F[discord_list_channels]
    B --> G[discord_list_roles]
    B --> H[discord_create_thread]
    B --> I[discord_ban_member]
    B --> J[discord_get_server]
    B --> K[discord_delete_channel]
    D --> D1[Block: CSV to array. Tool: validates 2-100 IDs. POST returns 204 No Content]
    E --> E1[GET /channels/id/messages/pins with limit and before=ISO8601. Returns items message plus pinned_at]
    F --> F1[GET /guilds/id/channels. Returns channel array]
    G --> G1[GET /guilds/id/roles. Returns role array]
    H --> H1[No messageId means standalone thread. type=11 PUBLIC or type=12 PRIVATE. isPublic param controls type]
    I --> I1[delete_message_days UI times 86400 equals delete_message_seconds API]
    J --> J1[with_counts=true. approximate_member_count. approximate_presence_count]
    K --> K1[DELETE reads body. Returns deleted channel object]
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
    A[Discord Block UI] --> B{Operation}
    B --> D[discord_bulk_delete_messages]
    B --> E[discord_get_pinned_messages]
    B --> F[discord_list_channels]
    B --> G[discord_list_roles]
    B --> H[discord_create_thread]
    B --> I[discord_ban_member]
    B --> J[discord_get_server]
    B --> K[discord_delete_channel]
    D --> D1[Block: CSV to array. Tool: validates 2-100 IDs. POST returns 204 No Content]
    E --> E1[GET /channels/id/messages/pins with limit and before=ISO8601. Returns items message plus pinned_at]
    F --> F1[GET /guilds/id/channels. Returns channel array]
    G --> G1[GET /guilds/id/roles. Returns role array]
    H --> H1[No messageId means standalone thread. type=11 PUBLIC or type=12 PRIVATE. isPublic param controls type]
    I --> I1[delete_message_days UI times 86400 equals delete_message_seconds API]
    J --> J1[with_counts=true. approximate_member_count. approximate_presence_count]
    K --> K1[DELETE reads body. Returns deleted channel object]
Loading

Reviews (5): Last reviewed commit: "fix(discord): validate 2-100 message cou..." | Re-trigger Greptile

Comment thread apps/sim/tools/discord/get_pinned_messages.ts
Comment thread apps/sim/tools/discord/bulk_delete_messages.ts
Cursor Bugbot found that a whitespace-only messageId was treated as
present (truthy), routing to the message-thread URL and trimming to
an empty path segment instead of creating a standalone thread.
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile review

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cursor review

Comment thread apps/sim/tools/discord/remove_reaction.ts
Comment thread apps/sim/tools/discord/get_pinned_messages.ts
- remove_reaction: whitespace-only userId no longer breaks the /@me
  fallback (Cursor Bugbot)
- get_pinned_messages: add limit/before query params so pins beyond
  the first page (max 50) can be retrieved (Cursor Bugbot)
- export DiscordMessage type and properly type pinned-message mapping
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile review

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cursor review

Comment thread apps/sim/blocks/blocks/discord.ts
The limit subBlock is shared between discord_get_messages (max 100)
and discord_get_pinned_messages (max 50 per Discord's API), so a
value carried over from the messages operation could exceed the pins
endpoint's max and trigger a 400. Clamp at both the block dispatcher
and the tool's request builder.
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile review

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cursor review

Comment thread apps/sim/tools/discord/bulk_delete_messages.ts
Discord's bulk-delete endpoint requires 2-100 message IDs; forwarding
an out-of-range count produced an opaque Discord API error instead of
a clear preflight message.
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile review

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cursor review

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 4fc5068. Configure here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant