Skip to content

Commit ad9497a

Browse files
committed
fix(discord): guard against whitespace-only messageId in create_thread
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.
1 parent 6917caf commit ad9497a

2 files changed

Lines changed: 5 additions & 4 deletions

File tree

apps/sim/blocks/blocks/discord.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ export const DiscordBlock: BlockConfig<DiscordResponse> = {
719719
...commonParams,
720720
channelId: params.channelId,
721721
name: params.name,
722-
...(params.messageId && { messageId: params.messageId }),
722+
...(params.messageId?.trim() && { messageId: params.messageId.trim() }),
723723
...(params.autoArchiveDuration && {
724724
autoArchiveDuration: Number(params.autoArchiveDuration),
725725
}),

apps/sim/tools/discord/create_thread.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@ export const discordCreateThreadTool: ToolConfig<
5959

6060
request: {
6161
url: (params: DiscordCreateThreadParams) => {
62-
if (params.messageId) {
63-
return `https://discord.com/api/v10/channels/${params.channelId.trim()}/messages/${params.messageId.trim()}/threads`
62+
const messageId = params.messageId?.trim()
63+
if (messageId) {
64+
return `https://discord.com/api/v10/channels/${params.channelId.trim()}/messages/${messageId}/threads`
6465
}
6566
return `https://discord.com/api/v10/channels/${params.channelId.trim()}/threads`
6667
},
@@ -78,7 +79,7 @@ export const discordCreateThreadTool: ToolConfig<
7879
}
7980
// Standalone threads (no source message) default to PRIVATE_THREAD per the Discord API
8081
// unless `type` is explicitly set, so pin it to PUBLIC_THREAD (11) unless the caller opts out.
81-
if (!params.messageId) {
82+
if (!params.messageId?.trim()) {
8283
body.type = params.isPublic === false ? 12 : 11
8384
}
8485
return body

0 commit comments

Comments
 (0)