Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
141 changes: 133 additions & 8 deletions apps/sim/blocks/blocks/discord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ export const DiscordBlock: BlockConfig<DiscordResponse> = {
{ label: 'Get User Information', id: 'discord_get_user' },
{ label: 'Edit Message', id: 'discord_edit_message' },
{ label: 'Delete Message', id: 'discord_delete_message' },
{ label: 'Bulk Delete Messages', id: 'discord_bulk_delete_messages' },
{ label: 'Add Reaction', id: 'discord_add_reaction' },
{ label: 'Remove Reaction', id: 'discord_remove_reaction' },
{ label: 'Pin Message', id: 'discord_pin_message' },
{ label: 'Unpin Message', id: 'discord_unpin_message' },
{ label: 'Get Pinned Messages', id: 'discord_get_pinned_messages' },
{ label: 'Create Thread', id: 'discord_create_thread' },
{ label: 'Join Thread', id: 'discord_join_thread' },
{ label: 'Leave Thread', id: 'discord_leave_thread' },
Expand All @@ -41,11 +43,13 @@ export const DiscordBlock: BlockConfig<DiscordResponse> = {
{ label: 'Update Channel', id: 'discord_update_channel' },
{ label: 'Delete Channel', id: 'discord_delete_channel' },
{ label: 'Get Channel', id: 'discord_get_channel' },
{ label: 'List Channels', id: 'discord_list_channels' },
{ label: 'Create Role', id: 'discord_create_role' },
{ label: 'Update Role', id: 'discord_update_role' },
{ label: 'Delete Role', id: 'discord_delete_role' },
{ label: 'Assign Role', id: 'discord_assign_role' },
{ label: 'Remove Role', id: 'discord_remove_role' },
{ label: 'List Roles', id: 'discord_list_roles' },
{ label: 'Kick Member', id: 'discord_kick_member' },
{ label: 'Ban Member', id: 'discord_ban_member' },
{ label: 'Unban Member', id: 'discord_unban_member' },
Expand Down Expand Up @@ -92,10 +96,12 @@ export const DiscordBlock: BlockConfig<DiscordResponse> = {
'discord_get_messages',
'discord_edit_message',
'discord_delete_message',
'discord_bulk_delete_messages',
'discord_add_reaction',
'discord_remove_reaction',
'discord_pin_message',
'discord_unpin_message',
'discord_get_pinned_messages',
'discord_create_thread',
'discord_update_channel',
'discord_delete_channel',
Expand All @@ -121,10 +127,35 @@ export const DiscordBlock: BlockConfig<DiscordResponse> = {
'discord_remove_reaction',
'discord_pin_message',
'discord_unpin_message',
'discord_create_thread',
],
},
},
// Message ID (optional) - for creating a thread from an existing message
{
id: 'messageId',
title: 'Message ID',
type: 'short-input',
placeholder: 'Enter message ID (leave empty for a standalone thread)',
condition: {
field: 'operation',
value: ['discord_create_thread'],
},
},
// Message IDs - for bulk delete
{
id: 'messageIds',
title: 'Message IDs',
type: 'long-input',
placeholder: 'Comma-separated message IDs to delete (2-100)',
required: true,
condition: { field: 'operation', value: 'discord_bulk_delete_messages' },
wandConfig: {
enabled: true,
prompt:
'Generate a comma-separated list of Discord message IDs (2-100 numeric snowflake IDs) based on the context: {context}. Return ONLY the comma-separated list - no explanations, no extra text.',
placeholder: 'Describe which messages to delete',
},
},
// Content - for send/edit message
{
id: 'content',
Expand All @@ -133,32 +164,44 @@ export const DiscordBlock: BlockConfig<DiscordResponse> = {
placeholder: 'Enter message content...',
condition: {
field: 'operation',
value: ['discord_send_message', 'discord_edit_message', 'discord_execute_webhook'],
value: ['discord_send_message', 'discord_edit_message'],
},
},
// Content (required) - for executing a webhook
{
id: 'content',
title: 'Message Content',
type: 'long-input',
placeholder: 'Enter message content...',
required: true,
condition: {
field: 'operation',
value: ['discord_execute_webhook'],
},
},
// Emoji - for reaction operations
{
id: 'emoji',
title: 'Emoji',
type: 'short-input',
placeholder: 'Enter emoji (e.g., 👍 or custom:123456789)',
placeholder: 'Enter emoji (e.g., 👍 or emoji_name:123456789012345678 for custom emoji)',
required: true,
condition: {
field: 'operation',
value: ['discord_add_reaction', 'discord_remove_reaction'],
},
},
// User ID - for user/member operations
// User ID (required) - for user/member operations
{
id: 'userId',
title: 'User ID',
type: 'short-input',
placeholder: 'Enter Discord user ID',
required: true,
condition: {
field: 'operation',
value: [
'discord_get_user',
'discord_remove_reaction',
'discord_assign_role',
'discord_remove_role',
'discord_kick_member',
Expand All @@ -169,6 +212,17 @@ export const DiscordBlock: BlockConfig<DiscordResponse> = {
],
},
},
// User ID (optional) - to remove a specific user's reaction
{
id: 'userId',
title: 'User ID',
type: 'short-input',
placeholder: 'Enter Discord user ID (leave empty to remove your own reaction)',
condition: {
field: 'operation',
value: ['discord_remove_reaction'],
},
},
// Thread ID - for thread operations
{
id: 'threadId',
Expand Down Expand Up @@ -329,6 +383,24 @@ export const DiscordBlock: BlockConfig<DiscordResponse> = {
placeholder: 'Number of messages (default: 10, max: 100)',
condition: { field: 'operation', value: 'discord_get_messages' },
},
// Limit (for get pinned messages)
{
id: 'limit',
title: 'Pin Limit',
type: 'short-input',
placeholder: 'Number of pins per page (default: 50, max: 50)',
mode: 'advanced',
condition: { field: 'operation', value: 'discord_get_pinned_messages' },
},
// Before (pagination cursor for get pinned messages)
{
id: 'before',
title: 'Before',
type: 'short-input',
placeholder: 'Return pins before this ISO8601 timestamp (for paging)',
mode: 'advanced',
condition: { field: 'operation', value: 'discord_get_pinned_messages' },
},
// Auto Archive Duration (for threads)
{
id: 'autoArchiveDuration',
Expand All @@ -346,6 +418,22 @@ export const DiscordBlock: BlockConfig<DiscordResponse> = {
value: ['discord_create_thread'],
},
},
// Thread Visibility (for create_thread, standalone threads only)
{
id: 'threadVisibility',
title: 'Thread Visibility',
type: 'dropdown',
options: [
{ label: 'Public - visible to everyone in the channel', id: 'public' },
{ label: 'Private - invite-only', id: 'private' },
],
value: () => 'public',
mode: 'advanced',
condition: {
field: 'operation',
value: ['discord_create_thread'],
},
},
// Channel Type (for create_channel)
{
id: 'channelType',
Expand All @@ -354,6 +442,7 @@ export const DiscordBlock: BlockConfig<DiscordResponse> = {
options: [
{ label: 'Text Channel', id: '0' },
{ label: 'Voice Channel', id: '2' },
{ label: 'Category', id: '4' },
{ label: 'Announcement Channel', id: '5' },
{ label: 'Stage Channel', id: '13' },
{ label: 'Forum Channel', id: '15' },
Expand Down Expand Up @@ -537,10 +626,12 @@ export const DiscordBlock: BlockConfig<DiscordResponse> = {
'discord_get_user',
'discord_edit_message',
'discord_delete_message',
'discord_bulk_delete_messages',
'discord_add_reaction',
'discord_remove_reaction',
'discord_pin_message',
'discord_unpin_message',
'discord_get_pinned_messages',
'discord_create_thread',
'discord_join_thread',
'discord_leave_thread',
Expand All @@ -549,11 +640,13 @@ export const DiscordBlock: BlockConfig<DiscordResponse> = {
'discord_update_channel',
'discord_delete_channel',
'discord_get_channel',
'discord_list_channels',
'discord_create_role',
'discord_update_role',
'discord_delete_role',
'discord_assign_role',
'discord_remove_role',
'discord_list_roles',
'discord_kick_member',
'discord_ban_member',
'discord_unban_member',
Expand Down Expand Up @@ -612,14 +705,30 @@ export const DiscordBlock: BlockConfig<DiscordResponse> = {
channelId: params.channelId,
messageId: params.messageId,
}
case 'discord_bulk_delete_messages':
return {
...commonParams,
channelId: params.channelId,
messageIds: String(params.messageIds || '')
.split(',')
.map((id: string) => id.trim())
.filter(Boolean),
}
case 'discord_get_pinned_messages':
return {
...commonParams,
channelId: params.channelId,
...(params.limit && { limit: Math.min(Math.max(1, Number(params.limit)), 50) }),
...(params.before?.trim() && { before: params.before.trim() }),
Comment thread
waleedlatif1 marked this conversation as resolved.
}
case 'discord_add_reaction':
case 'discord_remove_reaction':
return {
...commonParams,
channelId: params.channelId,
messageId: params.messageId,
emoji: params.emoji,
...(params.userId && { userId: params.userId }),
...(params.userId?.trim() && { userId: params.userId.trim() }),
}
case 'discord_pin_message':
case 'discord_unpin_message':
Expand All @@ -633,10 +742,13 @@ export const DiscordBlock: BlockConfig<DiscordResponse> = {
...commonParams,
channelId: params.channelId,
name: params.name,
...(params.messageId && { messageId: params.messageId }),
...(params.messageId?.trim() && { messageId: params.messageId.trim() }),
...(params.autoArchiveDuration && {
autoArchiveDuration: Number(params.autoArchiveDuration),
}),
...(params.threadVisibility !== undefined && {
isPublic: params.threadVisibility !== 'private',
}),
}
case 'discord_join_thread':
case 'discord_leave_thread':
Expand Down Expand Up @@ -665,6 +777,8 @@ export const DiscordBlock: BlockConfig<DiscordResponse> = {
case 'discord_delete_channel':
case 'discord_get_channel':
return { ...commonParams, channelId: params.channelId }
case 'discord_list_channels':
return commonParams
case 'discord_create_role':
return {
...commonParams,
Expand Down Expand Up @@ -695,6 +809,8 @@ export const DiscordBlock: BlockConfig<DiscordResponse> = {
userId: params.userId,
roleId: params.roleId,
}
case 'discord_list_roles':
return commonParams
case 'discord_kick_member':
case 'discord_unban_member':
return {
Expand All @@ -708,7 +824,7 @@ export const DiscordBlock: BlockConfig<DiscordResponse> = {
userId: params.userId,
...(params.reason && { reason: params.reason }),
...(params.deleteMessageDays && {
deleteMessageDays: Number(params.deleteMessageDays),
deleteMessageSeconds: Number(params.deleteMessageDays) * 86400,
}),
}
case 'discord_get_member':
Expand Down Expand Up @@ -761,6 +877,10 @@ export const DiscordBlock: BlockConfig<DiscordResponse> = {
serverId: { type: 'string', description: 'Discord server identifier' },
channelId: { type: 'string', description: 'Discord channel identifier' },
messageId: { type: 'string', description: 'Discord message identifier' },
messageIds: {
type: 'string',
description: 'Comma-separated message IDs to bulk delete (2-100)',
},
threadId: { type: 'string', description: 'Discord thread identifier' },
userId: { type: 'string', description: 'Discord user identifier' },
roleId: { type: 'string', description: 'Discord role identifier' },
Expand All @@ -777,7 +897,12 @@ export const DiscordBlock: BlockConfig<DiscordResponse> = {
archived: { type: 'string', description: 'Archive status (true/false)' },
files: { type: 'array', description: 'Files to attach (canonical param)' },
limit: { type: 'number', description: 'Message limit' },
before: { type: 'string', description: 'Return pins before this ISO8601 timestamp' },
autoArchiveDuration: { type: 'number', description: 'Thread auto-archive duration in minutes' },
threadVisibility: {
type: 'string',
description: 'Visibility for a new standalone thread (public/private)',
},
channelType: { type: 'number', description: 'Discord channel type (0=text, 2=voice, etc.)' },
parentId: { type: 'string', description: 'Parent category ID for channel' },
hoist: { type: 'boolean', description: 'Whether to display role members separately' },
Expand Down
7 changes: 0 additions & 7 deletions apps/sim/lib/oauth/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,13 +242,6 @@ export const SCOPE_DESCRIPTIONS: Record<string, string> = {
'GroupMember.ReadWrite.All': 'Read and write all group memberships',
'Directory.Read.All': 'Read directory data',

// Discord scopes
identify: 'Read Discord user',
bot: 'Read Discord bot',
'messages.read': 'Read Discord messages',
guilds: 'Read Discord guilds',
'guilds.members.read': 'Read Discord guild members',

// Reddit scopes
identity: 'Access Reddit identity',
submit: 'Submit posts and comments',
Expand Down
4 changes: 2 additions & 2 deletions apps/sim/tools/discord/add_reaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ export const discordAddReactionTool: ToolConfig<
request: {
url: (params: DiscordAddReactionParams) => {
const encodedEmoji = encodeURIComponent(params.emoji)
return `https://discord.com/api/v10/channels/${params.channelId}/messages/${params.messageId}/reactions/${encodedEmoji}/@me`
return `https://discord.com/api/v10/channels/${params.channelId.trim()}/messages/${params.messageId.trim()}/reactions/${encodedEmoji}/@me`
},
method: 'PUT',
headers: (params) => ({
Authorization: `Bot ${params.botToken}`,
Authorization: `Bot ${params.botToken.trim()}`,
}),
},

Expand Down
4 changes: 2 additions & 2 deletions apps/sim/tools/discord/archive_thread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ export const discordArchiveThreadTool: ToolConfig<

request: {
url: (params: DiscordArchiveThreadParams) => {
return `https://discord.com/api/v10/channels/${params.threadId}`
return `https://discord.com/api/v10/channels/${params.threadId.trim()}`
},
method: 'PATCH',
headers: (params) => ({
'Content-Type': 'application/json',
Authorization: `Bot ${params.botToken}`,
Authorization: `Bot ${params.botToken.trim()}`,
}),
body: (params: DiscordArchiveThreadParams) => {
return {
Expand Down
4 changes: 2 additions & 2 deletions apps/sim/tools/discord/assign_role.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ export const discordAssignRoleTool: ToolConfig<DiscordAssignRoleParams, DiscordA

request: {
url: (params: DiscordAssignRoleParams) => {
return `https://discord.com/api/v10/guilds/${params.serverId}/members/${params.userId}/roles/${params.roleId}`
return `https://discord.com/api/v10/guilds/${params.serverId.trim()}/members/${params.userId.trim()}/roles/${params.roleId.trim()}`
},
method: 'PUT',
headers: (params) => ({
Authorization: `Bot ${params.botToken}`,
Authorization: `Bot ${params.botToken.trim()}`,
}),
},

Expand Down
Loading
Loading