Skip to content

Commit a6712fb

Browse files
committed
fix(discord): clamp shared limit subBlock to 1-50 for pinned messages
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.
1 parent 74d6625 commit a6712fb

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

apps/sim/blocks/blocks/discord.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ export const DiscordBlock: BlockConfig<DiscordResponse> = {
718718
return {
719719
...commonParams,
720720
channelId: params.channelId,
721-
...(params.limit && { limit: Number(params.limit) }),
721+
...(params.limit && { limit: Math.min(Math.max(1, Number(params.limit)), 50) }),
722722
...(params.before?.trim() && { before: params.before.trim() }),
723723
}
724724
case 'discord_add_reaction':

apps/sim/tools/discord/get_pinned_messages.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export const discordGetPinnedMessagesTool: ToolConfig<
4646
request: {
4747
url: (params: DiscordGetPinnedMessagesParams) => {
4848
const query = new URLSearchParams()
49-
if (params.limit) query.set('limit', String(params.limit))
49+
if (params.limit) query.set('limit', String(Math.min(Math.max(1, Number(params.limit)), 50)))
5050
if (params.before) query.set('before', params.before)
5151
const queryString = query.toString()
5252
return `https://discord.com/api/v10/channels/${params.channelId.trim()}/messages/pins${queryString ? `?${queryString}` : ''}`

0 commit comments

Comments
 (0)