AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents
TypeScript ai-agentai-agent-toolsai-agentsai-agents-frameworkmcpmcp-servermcp-toolsmcpsn8n-alternativeno-code-automationworkflowworkflow-automationworkflows
feat(discord): step form (#15531)
Talal Jaberc8ebc4d3067d
diff --git a/bun.lock b/bun.lockindex 7a7ceaab3ac..b9b3210018c 100644--- a/bun.lock+++ b/bun.lock@@ -2622,7 +2622,7 @@},"packages/pieces/community/discord": {"name": "@activepieces/piece-discord",- "version": "0.6.0",+ "version": "0.7.0","dependencies": {"@activepieces/core-piece-types": "workspace:*","@activepieces/core-utils": "workspace:*",diff --git a/packages/pieces/community/discord/package.json b/packages/pieces/community/discord/package.jsonindex f28f8ebef69..60e2e9a4d63 100644--- a/packages/pieces/community/discord/package.json+++ b/packages/pieces/community/discord/package.json@@ -1,6 +1,6 @@{"name": "@activepieces/piece-discord",- "version": "0.6.0",+ "version": "0.7.0","main": "./dist/src/index.js","types": "./dist/src/index.d.ts","scripts": {diff --git a/packages/pieces/community/discord/src/index.ts b/packages/pieces/community/discord/src/index.tsindex 63670e18526..fb286d9e6eb 100644--- a/packages/pieces/community/discord/src/index.ts+++ b/packages/pieces/community/discord/src/index.ts@@ -66,18 +66,10 @@ import { discordRevokeInvite } from './lib/actions/ai-revoke-invite';import { discordCreateDm } from './lib/actions/ai-create-dm';import { discordGetUser } from './lib/actions/ai-get-user';-const markdown = `-To obtain a token, follow these steps:-1. Go to https://discord.com/developers/applications-2. Click on Application (or create one if you don't have one)-3. Click on Bot-4. Copy the token-`;-export const discord = createPiece({displayName: 'Discord',description: 'Instant messaging and VoIP social platform',- minimumSupportedRelease: '0.87.0',+ minimumSupportedRelease: '0.88.2',logoUrl: 'https://cdn.activepieces.com/pieces/discord.png',categories: [PieceCategory.COMMUNICATION],auth: discordAuth,diff --git a/packages/pieces/community/discord/src/lib/actions/add-role-to-member.ts b/packages/pieces/community/discord/src/lib/actions/add-role-to-member.tsindex 5bfd11a2484..286403ab5a7 100644--- a/packages/pieces/community/discord/src/lib/actions/add-role-to-member.ts+++ b/packages/pieces/community/discord/src/lib/actions/add-role-to-member.ts@@ -12,23 +12,25 @@ export const discordAddRoleToMember = createAction({auth: discordAuth,name: 'add_role_to_member',classification: 'WRITE',- description: 'Add Guild Member Role',+ description: 'Give a member of a server a role.',audience: 'human',aiMetadata: { description: 'Assigns a role to a guild member, identified by guild ID, user ID, and role ID. Use to grant permissions or tag a user. Requires the bot to have Manage Roles and a higher role than the target; idempotent, since re-adding an already-assigned role leaves the member unchanged.', idempotent: true },- displayName: 'Add role to member',+ displayName: 'Add Role to Member',outputSchema: discordSuccessActionOutputSchema,props: {guild_id: discordCommon.guilds,user_id: Property.ShortText({displayName: 'User ID',- description: 'The user id of the member',+ description:+ 'Right-click the member and choose Copy User ID in Developer Mode.',+ placeholder: '123456789012345678',required: true,}),role_id: discordCommon.roles,},async run(configValue) {- const request: HttpRequest<any> = {+ const request: HttpRequest = {method: HttpMethod.PUT,url: `https://discord.com/api/v9/guilds/${configValue.propsValue.guild_id}/members/${configValue.propsValue.user_id}/roles/${configValue.propsValue.role_id}`,headers: {diff --git a/packages/pieces/community/discord/src/lib/actions/ban-a-guild-member.ts b/packages/pieces/community/discord/src/lib/actions/ban-a-guild-member.tsindex db89d497c88..5f08ddc23bf 100644--- a/packages/pieces/community/discord/src/lib/actions/ban-a-guild-member.ts+++ b/packages/pieces/community/discord/src/lib/actions/ban-a-guild-member.ts@@ -12,37 +12,40 @@ export const discordBanGuildMember = createAction({auth: discordAuth,name: 'ban_guild_member',classification: 'DESTRUCTIVE',- description: 'Bans a guild member',+ description: 'Ban a user from a server so they cannot rejoin.',audience: 'both',aiMetadata: { description: 'Bans a user from a guild, identified by guild ID and user ID, with an optional audit-log reason; this removes them and blocks rejoining until unbanned. Use to permanently remove a disruptive user. Requires the bot to have Ban Members permission; idempotent, since re-banning an already-banned user yields the same end state.', idempotent: true },outputSchema: discordSuccessActionOutputSchema,- displayName: 'Ban guild member',+ displayName: 'Ban Member',props: {guild_id: discordCommon.guilds,user_id: Property.ShortText({displayName: 'User ID',- description: 'The user id of the member',+ description:+ 'Right-click the member and choose Copy User ID in Developer Mode.',+ placeholder: '123456789012345678',required: true,}),ban_reason: Property.ShortText({- displayName: 'Ban Reason',- description: 'The reason for banning the member',+ displayName: 'Reason',+ description: 'Recorded in the server audit log.',required: false,+ advanced: true,}),},async run(configValue) {- const request: HttpRequest<any> = {+ const reason = configValue.propsValue.ban_reason;++ const request: HttpRequest = {method: HttpMethod.PUT,url: `https://discord.com/api/v9/guilds/${configValue.propsValue.guild_id}/bans/${configValue.propsValue.user_id}`,headers: {authorization: `Bot ${configValue.auth.secret_text}`,'Content-Type': 'application/json',- 'X-Audit-Log-Reason': `${configValue.propsValue.ban_reason}`,- },- body: {- reason: `${configValue.propsValue.ban_reason}`,+ ...(reason ? { 'X-Audit-Log-Reason': reason } : {}),},+ body: reason ? { reason } : undefined,};const res = await httpClient.sendRequest<never>(request);diff --git a/packages/pieces/community/discord/src/lib/actions/create-channel.ts b/packages/pieces/community/discord/src/lib/actions/create-channel.tsindex a6a6bab507f..b796457618a 100644--- a/packages/pieces/community/discord/src/lib/actions/create-channel.ts+++ b/packages/pieces/community/discord/src/lib/actions/create-channel.ts@@ -12,22 +12,24 @@ export const discordCreateChannel = createAction({auth: discordAuth,name: 'create_channel',classification: 'WRITE',- description: 'create a channel',+ description: 'Create a text channel in a server.',audience: 'human',aiMetadata: { description: 'Creates a new channel in a guild with the given name and optional topic, identified by guild ID. Use to provision a channel before posting to it. Requires the bot to have Manage Channels permission; not idempotent, since each call creates a separate channel even with the same name.', idempotent: false },- displayName: 'Create channel',+ displayName: 'Create Channel',outputSchema: discordCreateChannelActionOutputSchema,props: {guild_id: discordCommon.guilds,name: Property.ShortText({displayName: 'Name',- description: 'The name of the new channel',+ description: 'Discord lowercases the name and turns spaces into dashes.',+ placeholder: 'project-updates',required: true,}),topic: Property.LongText({displayName: 'Topic',- description: 'The topic of the new channel',+ description: 'Shown at the top of the channel.',required: false,+ advanced: true,}),},diff --git a/packages/pieces/community/discord/src/lib/actions/create-guild-role.ts b/packages/pieces/community/discord/src/lib/actions/create-guild-role.tsindex 0eef423a3f1..910a5e1d150 100644--- a/packages/pieces/community/discord/src/lib/actions/create-guild-role.ts+++ b/packages/pieces/community/discord/src/lib/actions/create-guild-role.ts@@ -12,52 +12,59 @@ export const discordCreateGuildRole = createAction({auth: discordAuth,name: 'createGuildRole',classification: 'WRITE',- displayName: 'Create guild role',- description: 'Creates a new role on the specified guild',+ displayName: 'Create Role',+ description: 'Create a role in a server.',audience: 'human',aiMetadata: { description: 'Creates a new role in a guild with the given name and optional color, hoist, and mentionable settings, identified by guild ID. Use to provision a role before assigning it to members. Requires the bot to have Manage Roles permission; not idempotent, since each call creates a separate role even with the same name.', idempotent: false },outputSchema: discordRoleActionOutputSchema,props: {guild_id: discordCommon.guilds,role_name: Property.ShortText({- displayName: 'Role Name',- description: 'The name of the role',+ displayName: 'Name',+ placeholder: 'Moderators',required: true,}),role_color: Property.ShortText({- displayName: 'Role Color',- description: `The RGB color of the role (may be better to set manually on the server)`,+ displayName: 'Color',+ description: 'Hex like #5865F2 or a decimal RGB number.',+ placeholder: '#5865F2',required: false,+ advanced: true,}),display_separated: Property.Checkbox({- displayName: 'Display Separated',- description:- 'Whether the role should be displayed separately in the sidebar',+ displayName: 'Show Separately',+ description: 'Lists members with this role in their own sidebar group.',required: false,+ advanced: true,}),role_mentionable: Property.Checkbox({displayName: 'Mentionable',- description: 'Whether the role can be mentioned by other users',+ description: 'Lets anyone @mention this role.',required: false,+ advanced: true,}),creation_reason: Property.ShortText({- displayName: 'Creation Reason',- description: 'The reason for creating the role',+ displayName: 'Reason',+ description: 'Recorded in the server audit log.',required: false,+ advanced: true,}),},async run(configValue) {+ const reason = configValue.propsValue.creation_reason;+ const color = toColorInteger({ color: configValue.propsValue.role_color });+const request: HttpRequest = {url: `https://discord.com/api/v9/guilds/${configValue.propsValue.guild_id}/roles`,method: HttpMethod.POST,headers: {authorization: `Bot ${configValue.auth.secret_text}`,'Content-Type': 'application/json',- 'X-Audit-Log-Reason': `${configValue.propsValue.creation_reason}`,+ ...(reason ? { 'X-Audit-Log-Reason': reason } : {}),},body: {name: configValue.propsValue.role_name,- color: configValue.propsValue.role_color,+ ...(color === undefined ? {} : { color }),hoist: configValue.propsValue.display_separated,mentionable: configValue.propsValue.role_mentionable,},@@ -74,3 +81,31 @@ export const discordCreateGuildRole = createAction({};},});++function toColorInteger({+ color,+}: {+ color: string | undefined;+}): number | undefined {+ const trimmed = color?.trim();+ if (!trimmed) {+ return undefined;+ }++ if (/^\d+$/.test(trimmed)) {+ const decimal = Number(trimmed);+ if (decimal > MAX_COLOR_VALUE) {+ throw new Error(`Color must be between 0 and ${MAX_COLOR_VALUE}, received "${trimmed}".`);+ }+ return decimal;+ }++ const hex = trimmed.startsWith('#') ? trimmed.slice(1) : trimmed;+ if (/^[0-9a-fA-F]{6}$/.test(hex)) {+ return parseInt(hex, 16);+ }++ throw new Error(`Color must be a hex value like #5865F2 or a decimal RGB number, received "${trimmed}".`);+}++const MAX_COLOR_VALUE = 0xffffff;diff --git a/packages/pieces/community/discord/src/lib/actions/delete-channel.ts b/packages/pieces/community/discord/src/lib/actions/delete-channel.tsindex b412fe0fa61..29d9b593c03 100644--- a/packages/pieces/community/discord/src/lib/actions/delete-channel.ts+++ b/packages/pieces/community/discord/src/lib/actions/delete-channel.ts@@ -12,11 +12,11 @@ export const discordDeleteChannel = createAction({auth: discordAuth,name: 'delete_channel',classification: 'DESTRUCTIVE',- description: 'delete a channel',+ description: 'Permanently delete a channel and all of its messages.',audience: 'human',aiMetadata: { description: 'Permanently deletes a channel, identified by channel ID. Use to remove a channel and its messages; this is destructive and cannot be undone. Requires the bot to have Manage Channels permission; idempotent in end state, since deleting an already-removed channel leaves it gone.', idempotent: true },outputSchema: discordGetChannelActionOutputSchema,- displayName: 'Delete channel',+ displayName: 'Delete Channel',props: {channel_id: discordCommon.channel,},@@ -34,13 +34,28 @@ export const discordDeleteChannel = createAction({try {const res = await httpClient.sendRequest<never>(request);return res.body;- } catch (error: any) {- // Discord returns 404 (Unknown Channel, 10003) when the channel is- // already gone. Treat that as success so the action is idempotent.- if (error?.response?.status === 404) {+ } catch (error) {+ if (isResponseWithStatus(error) && error.response.status === 404) {return { success: true, alreadyAbsent: true };}throw error;}},});++function isResponseWithStatus(error: unknown): error is ResponseWithStatus {+ return (+ typeof error === 'object' &&+ error !== null &&+ 'response' in error &&+ typeof error.response === 'object' &&+ error.response !== null &&+ 'status' in error.response+ );+}++interface ResponseWithStatus {+ response: {+ status: number;+ };+}diff --git a/packages/pieces/community/discord/src/lib/actions/delete-guild-role.ts b/packages/pieces/community/discord/src/lib/actions/delete-guild-role.tsindex 98dcb05840a..0a6c248f817 100644--- a/packages/pieces/community/discord/src/lib/actions/delete-guild-role.ts+++ b/packages/pieces/community/discord/src/lib/actions/delete-guild-role.ts@@ -12,8 +12,8 @@ export const discordDeleteGuildRole = createAction({auth: discordAuth,name: 'deleteGuildRole',classification: 'DESTRUCTIVE',- displayName: 'Delete guild role',- description: 'Deletes the specified role from the specified guild',+ displayName: 'Delete Role',+ description: 'Delete a role from a server.',audience: 'human',aiMetadata: { description: 'Permanently deletes a role from a guild, identified by guild ID and role ID, with an optional audit-log reason; the role is removed from all members. Use to remove an unwanted role. Requires the bot to have Manage Roles permission; idempotent in end state, since deleting an already-removed role leaves it gone.', idempotent: true },outputSchema: discordSuccessWithAlreadyAbsentActionOutputSchema,@@ -21,19 +21,22 @@ export const discordDeleteGuildRole = createAction({guild_id: discordCommon.guilds,role_id: discordCommon.roles,deletion_reason: Property.ShortText({- displayName: 'Deletion reason',- description: 'The reason for deleting the role',+ displayName: 'Reason',+ description: 'Recorded in the server audit log.',required: false,+ advanced: true,}),},async run(configValue) {+ const reason = configValue.propsValue.deletion_reason;+const request: HttpRequest = {url: `https://discord.com/api/v9/guilds/${configValue.propsValue.guild_id}/roles/${configValue.propsValue.role_id}`,method: HttpMethod.DELETE,headers: {Authorization: `Bot ${configValue.auth.secret_text}`,'Content-Type': 'application/json',- 'X-Audit-Log-Reason': `${configValue.propsValue.deletion_reason}`,+ ...(reason ? { 'X-Audit-Log-Reason': reason } : {}),},};@@ -42,13 +45,28 @@ export const discordDeleteGuildRole = createAction({return {success: res.status === 204,};- } catch (error: any) {- // Discord returns 404 (Unknown Role, 10011) when the role is already- // gone. Treat that as success so the action is idempotent.- if (error?.response?.status === 404) {+ } catch (error) {+ if (isResponseWithStatus(error) && error.response.status === 404) {return { success: true, alreadyAbsent: true };}throw error;}},});++function isResponseWithStatus(error: unknown): error is ResponseWithStatus {+ return (+ typeof error === 'object' &&+ error !== null &&+ 'response' in error &&+ typeof error.response === 'object' &&+ error.response !== null &&+ 'status' in error.response+ );+}++interface ResponseWithStatus {+ response: {+ status: number;+ };+}diff --git a/packages/pieces/community/discord/src/lib/actions/find-channel.ts b/packages/pieces/community/discord/src/lib/actions/find-channel.tsindex 2994bcd4066..f179b305b17 100644--- a/packages/pieces/community/discord/src/lib/actions/find-channel.ts+++ b/packages/pieces/community/discord/src/lib/actions/find-channel.ts@@ -13,22 +13,23 @@ export const discordFindChannel = createAction({auth: discordAuth,name: 'find_channel',classification: 'SEARCH',- description: 'find a channel by name',+ description: 'Look up a channel in a server by its exact name.',audience: 'human',aiMetadata: { description: 'Looks up a channel in a guild by its exact name and returns its channel ID, given the guild ID. Use to resolve a channel name into the ID required by message, rename, or delete actions. Read-only and idempotent; matching is exact and returns the first match.', idempotent: true },- displayName: 'Find channel',+ displayName: 'Find Channel',outputSchema: discordSuccessWithChannelIdActionOutputSchema,props: {guild_id: discordCommon.guilds,name: Property.ShortText({displayName: 'Name',- description: 'The name of the channel',+ description: 'Exact name without the leading #, case-sensitive.',+ placeholder: 'general',required: true,}),},async run(configValue) {- const request: HttpRequest<any> = {+ const request: HttpRequest = {method: HttpMethod.GET,url: `https://discord.com/api/v9/guilds/${configValue.propsValue.guild_id}/channels`,headers: {diff --git a/packages/pieces/community/discord/src/lib/actions/find-guild-member.ts b/packages/pieces/community/discord/src/lib/actions/find-guild-member.tsindex 8f96a6f1714..9753b18f309 100644--- a/packages/pieces/community/discord/src/lib/actions/find-guild-member.ts+++ b/packages/pieces/community/discord/src/lib/actions/find-guild-member.ts@@ -6,59 +6,110 @@ import {} from '@activepieces/pieces-common';import { discordAuth } from '../auth';import { discordCommon } from '../common';-import { Member } from '../common/models';import { discordListGuildMembersActionOutputSchema } from '../output-schemas';export const discordFindGuildMemberByUsername = createAction({auth: discordAuth,name: 'list_guild_members',classification: 'SEARCH',- description: 'List Guild Members',+ description: 'List server members, optionally filtered by name.',audience: 'human',aiMetadata: { description: 'Lists members of a guild, returning their user IDs and usernames for the given guild ID. Use to look up a member ID before role, kick, or ban actions, or to enumerate who is in a server. Read-only and idempotent; requires the Server Members privileged intent to be enabled for the bot.', idempotent: true },- displayName: 'List guild members',+ displayName: 'List Members',outputSchema: discordListGuildMembersActionOutputSchema,props: {guild_id: discordCommon.guilds,shortText: Property.ShortText({displayName: 'Search',- description: 'Search for a member',- required: true,+ description:+ 'Only members whose username or nickname contains this text.',+ placeholder: 'jane',+ required: false,}),},async run(configValue) {- const request: HttpRequest<any> = {- method: HttpMethod.GET,- url: `https://discord.com/api/v9/guilds/${configValue.propsValue.guild_id}/members`,- headers: {- authorization: `Bot ${configValue.auth.secret_text}`,- 'Content-Type': 'application/json',- },- };+ const members = await fetchAllMembers({+ guildId: configValue.propsValue.guild_id,+ token: configValue.auth.secret_text,+ });- const res = await httpClient.sendRequest<Member[]>(request);+ const search = configValue.propsValue.shortText?.trim().toLowerCase() ?? '';+ const matching =+ search.length === 0+ ? members+ : members.filter((member) => matchesSearch({ member, search }));- const options: { options: { value: string; label: string }[] } = {- options: [],- };-- if (res.body.length === 0)+ if (matching.length === 0)return {disabled: true,options: [],- placeholder: 'No members found, please add the bot to a guild first',+ placeholder: 'No members found',};- await Promise.all(- res.body.map(async (member) => {- options.options.push({- value: member.user.id,- label: member.user.username,- });- })- );-- return options;+ return {+ options: matching.map((member) => ({+ value: member.user.id,+ label: member.user.username,+ })),+ };},});++async function fetchAllMembers({+ guildId,+ token,+}: {+ guildId: string;+ token: string;+}): Promise<GuildMember[]> {+ const pages: GuildMember[][] = [];+ let after: string | undefined = undefined;++ do {+ const request: HttpRequest = {+ method: HttpMethod.GET,+ url: `https://discord.com/api/v9/guilds/${guildId}/members`,+ queryParams: {+ limit: `${MEMBERS_PAGE_SIZE}`,+ ...(after ? { after } : {}),+ },+ headers: {+ authorization: `Bot ${token}`,+ 'Content-Type': 'application/json',+ },+ };+ const res = await httpClient.sendRequest<GuildMember[]>(request);+ pages.push(res.body);+ after =+ res.body.length === MEMBERS_PAGE_SIZE+ ? res.body[res.body.length - 1].user.id+ : undefined;+ } while (after !== undefined);++ return pages.flat();+}++function matchesSearch({+ member,+ search,+}: {+ member: GuildMember;+ search: string;+}): boolean {+ const haystack = [member.user.username, member.user.global_name, member.nick];+ return haystack.some(+ (value) => typeof value === 'string' && value.toLowerCase().includes(search)+ );+}++interface GuildMember {+ user: {+ id: string;+ username: string;+ global_name?: string | null;+ };+ nick?: string | null;+}++const MEMBERS_PAGE_SIZE = 1000;diff --git a/packages/pieces/community/discord/src/lib/actions/remove-ban-from-user.ts b/packages/pieces/community/discord/src/lib/actions/remove-ban-from-user.tsindex aee4c088da3..fcd2c8ae6e6 100644--- a/packages/pieces/community/discord/src/lib/actions/remove-ban-from-user.ts+++ b/packages/pieces/community/discord/src/lib/actions/remove-ban-from-user.ts@@ -12,8 +12,8 @@ export const discordRemoveBanFromUser = createAction({auth: discordAuth,name: 'remove_ban_from_user',classification: 'WRITE',- displayName: 'Remove ban from user',- description: 'Removes the guild ban from a user',+ displayName: 'Remove Ban from User',+ description: 'Lift a ban so the user can rejoin the server.',audience: 'both',aiMetadata: { description: 'Lifts a guild ban for a user, identified by guild ID and user ID, with an optional audit-log reason; the user may rejoin afterward. Use to reverse a previous ban. Requires the bot to have Ban Members permission; idempotent, since unbanning a user who is not banned yields the same end state.', idempotent: true },outputSchema: discordSuccessActionOutputSchema,@@ -21,27 +21,30 @@ export const discordRemoveBanFromUser = createAction({guild_id: discordCommon.guilds,user_id: Property.ShortText({displayName: 'User ID',- description: 'The ID of the user',+ description:+ 'Right-click the member and choose Copy User ID in Developer Mode.',+ placeholder: '123456789012345678',required: true,}),unban_reason: Property.ShortText({- displayName: 'Unban Reason',- description: 'The reason for unbanning the user',+ displayName: 'Reason',+ description: 'Recorded in the server audit log.',required: false,+ advanced: true,}),},async run(configValue) {- const request: HttpRequest<any> = {+ const reason = configValue.propsValue.unban_reason;++ const request: HttpRequest = {method: HttpMethod.DELETE,url: `https://discord.com/api/v9/guilds/${configValue.propsValue.guild_id}/bans/${configValue.propsValue.user_id}`,headers: {authorization: `Bot ${configValue.auth.secret_text}`,'Content-Type': 'application/json',- 'X-Audit-Log-Reason': `${configValue.propsValue.unban_reason}`,- },- body: {- reason: `${configValue.propsValue.unban_reason}`,+ ...(reason ? { 'X-Audit-Log-Reason': reason } : {}),},+ body: reason ? { reason } : undefined,};const res = await httpClient.sendRequest<never>(request);diff --git a/packages/pieces/community/discord/src/lib/actions/remove-member-from-guild.ts b/packages/pieces/community/discord/src/lib/actions/remove-member-from-guild.tsindex bc87c54adf8..585619ec607 100644--- a/packages/pieces/community/discord/src/lib/actions/remove-member-from-guild.ts+++ b/packages/pieces/community/discord/src/lib/actions/remove-member-from-guild.ts@@ -12,22 +12,24 @@ export const discordRemoveMemberFromGuild = createAction({auth: discordAuth,name: 'remove_member_from_guild',classification: 'DESTRUCTIVE',- description: 'Remove Guild Member',+ description: 'Kick a member; they can rejoin with an invite.',audience: 'both',aiMetadata: { description: 'Kicks a member from a guild, identified by guild ID and user ID; the user may rejoin later via an invite. Use to remove someone without a permanent ban. Requires the bot to have Kick Members permission; idempotent, since removing an absent member yields the same end state.', idempotent: true },outputSchema: discordSuccessActionOutputSchema,- displayName: 'Remove member from guild',+ displayName: 'Remove Member from Server',props: {guild_id: discordCommon.guilds,user_id: Property.ShortText({displayName: 'User ID',- description: 'The user id of the member',+ description:+ 'Right-click the member and choose Copy User ID in Developer Mode.',+ placeholder: '123456789012345678',required: true,}),},async run(configValue) {- const request: HttpRequest<any> = {+ const request: HttpRequest = {method: HttpMethod.DELETE,url: `https://discord.com/api/v9/guilds/${configValue.propsValue.guild_id}/members/${configValue.propsValue.user_id}`,headers: {diff --git a/packages/pieces/community/discord/src/lib/actions/remove-role-from-member.ts b/packages/pieces/community/discord/src/lib/actions/remove-role-from-member.tsindex 73c89f2131f..b339f9f6945 100644--- a/packages/pieces/community/discord/src/lib/actions/remove-role-from-member.ts+++ b/packages/pieces/community/discord/src/lib/actions/remove-role-from-member.ts@@ -12,23 +12,25 @@ export const discordRemoveRoleFromMember = createAction({auth: discordAuth,name: 'remove_role_from_member',classification: 'WRITE',- description: 'Remove Guild Member Role',+ description: 'Take a role away from a member of a server.',audience: 'human',aiMetadata: { description: 'Removes a role from a guild member, identified by guild ID, user ID, and role ID. Use to revoke permissions or untag a user. Requires the bot to have Manage Roles and a higher role than the target; idempotent, since removing a role the member does not have leaves them unchanged.', idempotent: true },- displayName: 'Remove role from member',+ displayName: 'Remove Role from Member',outputSchema: discordSuccessActionOutputSchema,props: {guild_id: discordCommon.guilds,user_id: Property.ShortText({displayName: 'User ID',- description: 'The user id of the member',+ description:+ 'Right-click the member and choose Copy User ID in Developer Mode.',+ placeholder: '123456789012345678',required: true,}),role_id: discordCommon.roles,},async run(configValue) {- const request: HttpRequest<any> = {+ const request: HttpRequest = {method: HttpMethod.DELETE,url: `https://discord.com/api/v9/guilds/${configValue.propsValue.guild_id}/members/${configValue.propsValue.user_id}/roles/${configValue.propsValue.role_id}`,headers: {diff --git a/packages/pieces/community/discord/src/lib/actions/rename-channel.ts b/packages/pieces/community/discord/src/lib/actions/rename-channel.tsindex 0d28dde7009..6f9da63536d 100644--- a/packages/pieces/community/discord/src/lib/actions/rename-channel.ts+++ b/packages/pieces/community/discord/src/lib/actions/rename-channel.ts@@ -12,22 +12,23 @@ export const discordRenameChannel = createAction({auth: discordAuth,name: 'rename_channel',classification: 'WRITE',- description: 'rename a channel',+ description: 'Give a channel a new name.',audience: 'human',aiMetadata: { description: 'Renames an existing channel, identified by channel ID, to a new name. Use to update a channel title. Requires the bot to have Manage Channels permission; idempotent, since setting the same name repeatedly yields the same result.', idempotent: true },- displayName: 'Rename channel',+ displayName: 'Rename Channel',outputSchema: discordSuccessActionOutputSchema,props: {channel_id: discordCommon.channel,name: Property.ShortText({displayName: 'Name',- description: 'The new name of the channel',+ description: 'Discord lowercases the name and turns spaces into dashes.',+ placeholder: 'project-updates',required: true,}),},async run(configValue) {- const request: HttpRequest<any> = {+ const request: HttpRequest = {method: HttpMethod.PATCH,url: `https://discord.com/api/v9/channels/${configValue.propsValue.channel_id}`,body: {@@ -42,7 +43,7 @@ export const discordRenameChannel = createAction({const res = await httpClient.sendRequest<never>(request);return {- success: res.status === 204,+ success: res.status >= 200 && res.status < 300,};},});diff --git a/packages/pieces/community/discord/src/lib/actions/send-approval-message.ts b/packages/pieces/community/discord/src/lib/actions/send-approval-message.tsindex 749d5a00358..780bf949b55 100644--- a/packages/pieces/community/discord/src/lib/actions/send-approval-message.ts+++ b/packages/pieces/community/discord/src/lib/actions/send-approval-message.ts@@ -14,18 +14,18 @@ export const discordSendApprovalMessage = createAction({name: 'request_approval_message',classification: 'WRITE',description:- 'send a message to a channel asking for approval and wait for a response',+ 'Post a message with a review button and pause until someone responds.',audience: 'both',aiMetadata: { description: 'Posts a message with a single button linking to a confirmation page where a human chooses Approve or Disapprove to a Discord channel, then pauses the flow until they respond and resumes with the decision. Use as a human-in-the-loop approval gate before an agent proceeds with a consequential step. Blocks until a response arrives; each call posts a new approval message, so it is not idempotent.', idempotent: false },displayName: 'Request Approval in a Channel',outputSchema: discordSendApprovalMessageActionOutputSchema,props: {+ channel: discordCommon.channel,content: Property.LongText({displayName: 'Message',- description: 'The message you want to send',+ description: 'Say what needs approval; a Review & Respond button is added below.',required: true,}),- channel: discordCommon.channel,},async run(ctx) {if (ctx.executionType === ExecutionType.BEGIN) {diff --git a/packages/pieces/community/discord/src/lib/actions/send-message-webhook.ts b/packages/pieces/community/discord/src/lib/actions/send-message-webhook.tsindex a9b4d285c3f..029e2cac7a9 100644--- a/packages/pieces/community/discord/src/lib/actions/send-message-webhook.ts+++ b/packages/pieces/community/discord/src/lib/actions/send-message-webhook.ts@@ -8,39 +8,48 @@ import {export const discordSendMessageWebhook = createAction({name: 'send_message_webhook',classification: 'WRITE',- description: 'Send a discord message via webhook',+ description: 'Post a message to a channel through a Discord webhook URL.',audience: 'both',aiMetadata: { description: 'Posts a message to a Discord channel through an incoming webhook URL, with optional custom username, avatar, and rich embeds. Use when you have a webhook URL rather than a bot connection; no Discord auth is needed. Each call posts a new message, so it is not idempotent.', idempotent: false },- displayName: 'Send Message Webhook',+ displayName: 'Send Message via Webhook',requireAuth: false,props: {webhook_url: Property.ShortText({displayName: 'Webhook URL',+ description: 'Server Settings, Integrations, Webhooks, then Copy Webhook URL.',+ placeholder: 'https://discord.com/api/webhooks/…',required: true,}),- username: Property.ShortText({- displayName: 'Name',- required: false,- }),content: Property.LongText({displayName: 'Message',required: true,}),+ username: Property.ShortText({+ displayName: 'Display Name',+ description: 'Shown instead of the webhook name for this message.',+ placeholder: 'Deploy Bot',+ required: false,+ advanced: true,+ }),avatar_url: Property.ShortText({displayName: 'Avatar URL',- description: 'The avatar url for webhook',+ description: 'Shown instead of the webhook avatar for this message.',+ placeholder: 'https://example.com/avatar.png',required: false,+ advanced: true,}),embeds: Property.Json({- displayName: 'embeds',- description: 'Embeds to send along with the message',+ displayName: 'Embeds',+ description: 'JSON array of Discord embed objects.',required: false,+ advanced: true,defaultValue: [],}),tts: Property.Checkbox({- displayName: 'Text to speech',- description: 'Robot reads the message',+ displayName: 'Text to Speech',+ description: 'Discord reads the message aloud in the channel.',required: false,+ advanced: true,}),},async run(configValue) {diff --git a/packages/pieces/community/discord/src/lib/actions/send-message-with-bot.ts b/packages/pieces/community/discord/src/lib/actions/send-message-with-bot.tsindex db62120b8dc..768718527cf 100644--- a/packages/pieces/community/discord/src/lib/actions/send-message-with-bot.ts+++ b/packages/pieces/community/discord/src/lib/actions/send-message-with-bot.ts@@ -19,7 +19,7 @@ export const sendMessageWithBot = createAction({auth:discordAuth,displayName: 'Send Message with Bot',description:- 'Send messages via bot to any channel or thread you want, with an optional file attachment.',+ 'Post a message and optional files to a channel or thread as the bot.',audience: 'human',aiMetadata: { description: 'Posts a new message (optionally with file attachments) to a Discord channel or thread using a bot token. Use when an agent needs to send bot-authored content to a known channel ID. Requires the bot to have access to that channel; each call posts a separate message, so it is not idempotent.', idempotent: false },outputSchema: discordMessageOutputSchema,@@ -27,15 +27,15 @@ export const sendMessageWithBot = createAction({channel_id: discordCommon.channel,message: Property.LongText({displayName: 'Message',- description: 'Message content to send.',+ description: 'Text of the message. Leave empty to send only files.',required: false,}),files: Property.Array({displayName: 'Attachments',+ description: 'Files uploaded with the message.',properties: {file: Property.File({displayName: 'File',- description: 'Optional file to send with the message.',required: false,}),},@@ -49,7 +49,9 @@ export const sendMessageWithBot = createAction({const files = configValue.propsValue.files as FileObject[] ?? [];const formData = new FormData();- formData.append('content', message);+ if (typeof message === 'string' && message.length > 0) {+ formData.append('content', message);+ }if (files && files.length > 0) {files.forEach((fileObj, index) => {@@ -63,7 +65,6 @@ export const sendMessageWithBot = createAction({url: `https://discord.com/api/v10/channels/${channelId}/messages`,headers: {authorization: `Bot ${configValue.auth.secret_text}`,- 'Content-Type': 'multipart/form-data',},body: formData,};diff --git a/packages/pieces/community/discord/src/lib/auth.ts b/packages/pieces/community/discord/src/lib/auth.tsindex ee175ab1c9f..fdc342e6817 100644--- a/packages/pieces/community/discord/src/lib/auth.ts+++ b/packages/pieces/community/discord/src/lib/auth.ts@@ -1,11 +1,10 @@import { PieceAuth } from '@activepieces/pieces-framework';const markdown = `-To obtain a token, follow these steps:-1. Go to https://discord.com/developers/applications-2. Click on Application (or create one if you don't have one)-3. Click on Bot-4. Copy the token+1. Open https://discord.com/developers/applications and select or create an application.+2. In **Bot**, click **Reset Token** and copy the token.+3. Still in **Bot**, enable **Server Members Intent** and **Message Content Intent**.+4. In **OAuth2 → URL Generator**, pick the **bot** scope and the permissions you need, open the URL and add the bot to your server.`;export const discordAuth = PieceAuth.SecretText({diff --git a/packages/pieces/community/discord/src/lib/common/index.ts b/packages/pieces/community/discord/src/lib/common/index.tsindex e8dc5cc36cf..3375116c2c3 100644--- a/packages/pieces/community/discord/src/lib/common/index.ts+++ b/packages/pieces/community/discord/src/lib/common/index.ts@@ -1,20 +1,13 @@import { HttpMethod, httpClient } from '@activepieces/pieces-common';-import { Channel, Guild } from '../common/models';+import { Channel, Guild, Role } from '../common/models';import { Property } from '@activepieces/pieces-framework';import { discordAuth } from '../auth';-export interface Member {- user: {- id: string;- username: string;- };-}-export const discordCommon = {channel: Property.Dropdown({auth: discordAuth,displayName: 'Channel',- description: 'List of channels',+ description: 'Channels from every server the bot has joined.',required: true,refreshers: [],options: async ({ auth }) => {@@ -22,7 +15,7 @@ export const discordCommon = {return {disabled: true,options: [],- placeholder: 'Please connect your bot first',+ placeholder: 'Connect your bot first',};}@@ -35,46 +28,52 @@ export const discordCommon = {};const res = await httpClient.sendRequest<Guild[]>(request);- const options: { options: { value: string; label: string }[] } = {- options: [],- };if (res.body.length === 0)return {disabled: true,options: [],- placeholder: 'No guilds found, please add the bot to a guild first',+ placeholder: 'No servers found, add the bot to a server first',};- await Promise.all(- res.body.map(async (guild) => {- const requestChannels = {- method: HttpMethod.GET,- url: 'https://discord.com/api/v9/guilds/' + guild.id + '/channels',- headers: {- Authorization: 'Bot ' + auth.secret_text,- },- };-- const resChannels = await httpClient.sendRequest<Channel[]>(- requestChannels- );- resChannels.body.forEach((channel) => {- options.options.push({+ const options = (+ await Promise.all(+ res.body.map(async (guild) => {+ const requestChannels = {+ method: HttpMethod.GET,+ url:+ 'https://discord.com/api/v9/guilds/' + guild.id + '/channels',+ headers: {+ Authorization: 'Bot ' + auth.secret_text,+ },+ };++ const resChannels = await httpClient.sendRequest<Channel[]>(+ requestChannels+ );++ return resChannels.body.map((channel) => ({value: channel.id,- label: channel.name,- });- });- })- );+ label: `${channel.name} (${guild.name})`,+ }));+ })+ )+ ).flat();++ if (options.length === 0)+ return {+ disabled: true,+ options: [],+ placeholder: 'No channels found in the servers the bot has joined',+ };- return options;+ return { options };},}),roles: Property.Dropdown({auth: discordAuth,- displayName: 'Roles',- description: 'List of roles',+ displayName: 'Role',+ description: 'Roles of the selected server.',required: true,refreshers: ['guild_id'],options: async ({ auth, guild_id }) => {@@ -82,7 +81,7 @@ export const discordCommon = {return {disabled: true,options: [],- placeholder: 'Please connect your bot first',+ placeholder: 'Connect your bot first',};}@@ -90,7 +89,7 @@ export const discordCommon = {return {disabled: true,options: [],- placeholder: 'Please select a guild first',+ placeholder: 'Select a server first',};}@@ -102,35 +101,27 @@ export const discordCommon = {},};- const res = await httpClient.sendRequest<Guild[]>(request);-- const options: { options: { value: string; label: string }[] } = {- options: [],- };+ const res = await httpClient.sendRequest<Role[]>(request);if (res.body.length === 0)return {disabled: true,options: [],- placeholder: 'No roles found, please add the bot to a guild first',+ placeholder: 'No roles found in this server',};- await Promise.all(- res.body.map(async (role) => {- options.options.push({- value: role.id,- label: role.name,- });- })- );-- return options;+ return {+ options: res.body.map((role) => ({+ value: role.id,+ label: role.name,+ })),+ };},}),guilds: Property.Dropdown({auth: discordAuth,- displayName: 'Guilds',- description: 'List of guilds',+ displayName: 'Server',+ description: 'Only servers the bot has been added to are listed.',required: true,refreshers: [],options: async ({ auth }) => {@@ -138,7 +129,7 @@ export const discordCommon = {return {disabled: true,options: [],- placeholder: 'Please connect your bot first',+ placeholder: 'Connect your bot first',};}@@ -151,27 +142,20 @@ export const discordCommon = {};const res = await httpClient.sendRequest<Guild[]>(request);- const options: { options: { value: string; label: string }[] } = {- options: [],- };if (res.body.length === 0)return {disabled: true,options: [],- placeholder: 'No guilds found, please add the bot to a guild first',+ placeholder: 'No servers found, add the bot to a server first',};- await Promise.all(- res.body.map(async (guild) => {- options.options.push({- value: guild.id,- label: guild.name,- });- })- );-- return options;+ return {+ options: res.body.map((guild) => ({+ value: guild.id,+ label: guild.name,+ })),+ };},}),};diff --git a/packages/pieces/community/discord/src/lib/common/models.ts b/packages/pieces/community/discord/src/lib/common/models.tsindex f9714ba03ab..baadeb2c72e 100644--- a/packages/pieces/community/discord/src/lib/common/models.ts+++ b/packages/pieces/community/discord/src/lib/common/models.ts@@ -19,6 +19,11 @@ export interface Member {};}+export interface Role {+ id: string;+ name: string;+}+export interface Message {id: string;type: number;diff --git a/packages/pieces/community/discord/src/lib/triggers/new-member.ts b/packages/pieces/community/discord/src/lib/triggers/new-member.tsindex 03f0b6d330c..c1f7ea001ee 100644--- a/packages/pieces/community/discord/src/lib/triggers/new-member.ts+++ b/packages/pieces/community/discord/src/lib/triggers/new-member.ts@@ -14,7 +14,6 @@ import {} from '@activepieces/pieces-framework';import dayjs from 'dayjs';import { discordAuth } from '../auth';-import { discordCommon } from '../common';import { discordNewMemberTriggerOutputSchema } from '../output-schemas';interface Member {@@ -56,23 +55,30 @@ export const newMember = createTrigger({name: 'new_member',classification: 'READ',displayName: 'New Member',- description: 'Triggers when a new member joins a guild',+ description: 'Fires when a member joins a server.',aiMetadata: {description: 'Fires when a new member joins the specified Discord guild (server), emitting one event per joining member with their user details. Polls the guild member list periodically, so detection is near-real-time rather than instant.',},type: TriggerStrategy.POLLING,outputSchema: discordNewMemberTriggerOutputSchema,props: {+ guildId: Property.ShortText({+ displayName: 'Server ID',+ description:+ 'Right-click the server and choose Copy Server ID in Developer Mode.',+ placeholder: '123456789012345678',+ required: true,+ }),limit: Property.Number({displayName: 'Limit',- description: 'The number of members to fetch (max 1000)',+ description: 'Most recent members checked each poll, up to 1000.',required: false,defaultValue: 50,- }),- guildId: Property.ShortText({- displayName: 'Guild ID',- description: 'The ID of the Discord guild (server)',- required: true,+ display: 'stepper',+ min: 1,+ max: 1000,+ step: 1,+ advanced: true,}),},sampleData: {},diff --git a/packages/pieces/community/discord/src/lib/triggers/new-message.ts b/packages/pieces/community/discord/src/lib/triggers/new-message.tsindex 846e01101be..7137452344a 100644--- a/packages/pieces/community/discord/src/lib/triggers/new-message.ts+++ b/packages/pieces/community/discord/src/lib/triggers/new-message.ts@@ -51,21 +51,26 @@ export const newMessage = createTrigger({auth: discordAuth,name: 'new_message',classification: 'READ',- displayName: 'New message',- description: 'Triggers when a message is sent in a channel',+ displayName: 'New Message',+ description: 'Fires when a message is posted in a channel.',aiMetadata: {description: 'Fires when a new message is posted in the selected Discord channel, emitting one event per message. Polls the channel periodically, so detection is near-real-time rather than instant.',},type: TriggerStrategy.POLLING,outputSchema: discordMessageOutputSchema,props: {+ channel: discordCommon.channel,limit: Property.Number({displayName: 'Limit',- description: 'The number of messages to fetch',+ description: 'Most recent messages checked each poll, up to 100.',required: false,defaultValue: 50,+ display: 'stepper',+ min: 1,+ max: 100,+ step: 1,+ advanced: true,}),- channel: discordCommon.channel,},sampleData: {},onEnable: async (context) => {