Skip to content

Commit 3580241

Browse files
authored
feat(discord): added discord block/tools (#347)
* feat(tools): added discord oauth, block, and tools * added docs * remove extraneous comments/logs * added tooltips for disabled subblocks, acknowledged PR comments * added tools and blocks for new repo structure * added docs * added more type safety, fixed some styling * updated docs * fixed style of dropdown in tool-input * acknowledged PR comments
1 parent 0fc0f68 commit 3580241

File tree

35 files changed

+2046
-156
lines changed

35 files changed

+2046
-156
lines changed
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
---
2+
title: Discord
3+
description: Interact with Discord
4+
---
5+
6+
import { BlockInfoCard } from '@/components/ui/block-info-card'
7+
8+
<BlockInfoCard
9+
type="discord"
10+
color="#E0E0E0"
11+
icon={true}
12+
iconSvg={`<svg className="block-icon" viewBox="0 -28.5 256 256" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlnsXlink="http://www.w3.org/1999/xlink" preserveAspectRatio="xMidYMid">
13+
<g>
14+
<path d="M216.856339,16.5966031 C200.285002,8.84328665 182.566144,3.2084988 164.041564,0 C161.766523,4.11318106 159.108624,9.64549908 157.276099,14.0464379 C137.583995,11.0849896 118.072967,11.0849896 98.7430163,14.0464379 C96.9108417,9.64549908 94.1925838,4.11318106 91.8971895,0 C73.3526068,3.2084988 55.6133949,8.86399117 39.0420583,16.6376612 C5.61752293,67.146514 -3.4433191,116.400813 1.08711069,164.955721 C23.2560196,181.510915 44.7403634,191.567697 65.8621325,198.148576 C71.0772151,190.971126 75.7283628,183.341335 79.7352139,175.300261 C72.104019,172.400575 64.7949724,168.822202 57.8887866,164.667963 C59.7209612,163.310589 61.5131304,161.891452 63.2445898,160.431257 C105.36741,180.133187 151.134928,180.133187 192.754523,160.431257 C194.506336,161.891452 196.298154,163.310589 198.110326,164.667963 C191.183787,168.842556 183.854737,172.420929 176.223542,175.320965 C180.230393,183.341335 184.861538,190.991831 190.096624,198.16893 C211.238746,191.588051 232.743023,181.531619 254.911949,164.955721 C260.227747,108.668201 245.831087,59.8662432 216.856339,16.5966031 Z M85.4738752,135.09489 C72.8290281,135.09489 62.4592217,123.290155 62.4592217,108.914901 C62.4592217,94.5396472 72.607595,82.7145587 85.4738752,82.7145587 C98.3405064,82.7145587 108.709962,94.5189427 108.488529,108.914901 C108.508531,123.290155 98.3405064,135.09489 85.4738752,135.09489 Z M170.525237,135.09489 C157.88039,135.09489 147.510584,123.290155 147.510584,108.914901 C147.510584,94.5396472 157.658606,82.7145587 170.525237,82.7145587 C183.391518,82.7145587 193.761324,94.5189427 193.539891,108.914901 C193.539891,123.290155 183.391518,135.09489 170.525237,135.09489 Z" fill="#5865F2" fillRule="nonzero">
15+
16+
</path>
17+
</g>
18+
</svg>`}
19+
/>
20+
21+
{/* MANUAL-CONTENT-START:intro */}
22+
[Discord](https://discord.com) is a powerful communication platform that allows you to connect with friends, communities, and teams. It offers a range of features for team collaboration, including text channels, voice channels, and video calls.
23+
24+
With a Discord account or bot, you can:
25+
26+
- **Send messages**: Send messages to a specific channel
27+
- **Get messages**: Get messages from a specific channel
28+
- **Get server**: Get information about a specific server
29+
- **Get user**: Get information about a specific user
30+
31+
In Sim Studio, the Discord integration enables your agents to access and leverage your organization's Discord servers. Agents can retrieve information from Discord channels, search for specific users, get server information, and send messages. This allows your workflows to integrate with your Discord communities, automate notifications, and create interactive experiences.
32+
33+
> **Important:** To read message content, your Discord bot needs the "Message Content Intent" enabled in the Discord Developer Portal. Without this permission, you'll still receive message metadata but the content field will appear empty.
34+
35+
Discord components in Sim Studio use efficient lazy loading, only fetching data when needed to minimize API calls and prevent rate limiting. Token refreshing happens automatically in the background to maintain your connection.
36+
37+
### Setting Up Your Discord Bot
38+
39+
1. Go to the [Discord Developer Portal](https://discord.com/developers/applications)
40+
2. Create a new application and navigate to the "Bot" tab
41+
3. Create a bot and copy your bot token
42+
4. Under "Privileged Gateway Intents", enable the **Message Content Intent** to read message content
43+
5. Invite your bot to your servers with appropriate permissions
44+
{/* MANUAL-CONTENT-END */}
45+
46+
## Usage Instructions
47+
48+
Connect to Discord to send messages, manage channels, and interact with servers. Automate notifications, community management, and integrate Discord into your workflows.
49+
50+
## Tools
51+
52+
### `discord_send_message`
53+
54+
Send a message to a Discord channel
55+
56+
#### Input
57+
58+
| Parameter | Type | Required | Description |
59+
| ----------- | ------ | -------- | --------------------------------------------- |
60+
| `botToken` | string | Yes | The bot token for authentication |
61+
| `channelId` | string | Yes | The Discord channel ID to send the message to |
62+
| `content` | string | No | The text content of the message |
63+
| `serverId` | string | Yes | The Discord server ID \(guild ID\) |
64+
65+
#### Output
66+
67+
| Parameter | Type |
68+
| --------- | ------ |
69+
| `message` | string |
70+
71+
### `discord_get_messages`
72+
73+
Retrieve messages from a Discord channel
74+
75+
#### Input
76+
77+
| Parameter | Type | Required | Description |
78+
| ----------- | ------ | -------- | ---------------------------------------------------------------- |
79+
| `botToken` | string | Yes | The bot token for authentication |
80+
| `channelId` | string | Yes | The Discord channel ID to retrieve messages from |
81+
| `limit` | number | No | Maximum number of messages to retrieve \(default: 10, max: 100\) |
82+
83+
#### Output
84+
85+
| Parameter | Type |
86+
| --------- | ------ |
87+
| `message` | string |
88+
89+
### `discord_get_server`
90+
91+
Retrieve information about a Discord server (guild)
92+
93+
#### Input
94+
95+
| Parameter | Type | Required | Description |
96+
| ---------- | ------ | -------- | ---------------------------------- |
97+
| `botToken` | string | Yes | The bot token for authentication |
98+
| `serverId` | string | Yes | The Discord server ID \(guild ID\) |
99+
100+
#### Output
101+
102+
| Parameter | Type |
103+
| --------- | ------ |
104+
| `message` | string |
105+
106+
### `discord_get_user`
107+
108+
Retrieve information about a Discord user
109+
110+
#### Input
111+
112+
| Parameter | Type | Required | Description |
113+
| ---------- | ------ | -------- | ------------------------------------ |
114+
| `botToken` | string | Yes | Discord bot token for authentication |
115+
| `userId` | string | Yes | The Discord user ID |
116+
117+
#### Output
118+
119+
| Parameter | Type |
120+
| --------- | ------ |
121+
| `message` | string |
122+
123+
## Block Configuration
124+
125+
### Input
126+
127+
| Parameter | Type | Required | Description |
128+
| ----------- | ------ | -------- | ----------- |
129+
| `operation` | string | Yes | Operation |
130+
131+
### Outputs
132+
133+
| Output | Type | Description |
134+
| ----------- | ------ | ----------------------- |
135+
| `response` | object | Output from response |
136+
|`message` | string | message of the response |
137+
|`data` | any | data of the response |
138+
139+
## Notes
140+
141+
- Category: `tools`
142+
- Type: `discord`

apps/docs/content/docs/tools/elevenlabs.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ Convert TTS using ElevenLabs voices
6767

6868
| Parameter | Type | Required | Description |
6969
| --------- | ------ | -------- | ------------------------------------------ |
70-
| `text` | string | No | Text - Enter the text to convert to speech |
70+
| `text` | string | Yes | Text - Enter the text to convert to speech |
7171

7272
### Outputs
7373

apps/docs/content/docs/tools/google_search.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ Search the web with the Custom Search API
7878

7979
| Parameter | Type | Required | Description |
8080
| --------- | ------ | -------- | -------------------------------------- |
81-
| `query` | string | No | Search Query - Enter your search query |
81+
| `query` | string | Yes | Search Query - Enter your search query |
8282

8383
### Outputs
8484

apps/docs/content/docs/tools/meta.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"browser_use",
77
"clay",
88
"confluence",
9+
"discord",
910
"dropdown",
1011
"elevenlabs",
1112
"exa",

apps/docs/content/docs/tools/reddit.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ Fetch comments from a specific Reddit post
114114

115115
| Parameter | Type | Required | Description |
116116
| --------- | ------ | -------- | ----------- |
117-
| `action` | string | No | Action |
117+
| `action` | string | Yes | Action |
118118

119119
### Outputs
120120

apps/docs/content/docs/tools/thinking.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ Processes a provided thought/instruction, making it available for subsequent ste
6363

6464
| Parameter | Type | Required | Description |
6565
| --------- | ------ | -------- | ---------------------------------------------------------------------------------- |
66-
| `thought` | string | No | Thought Process / Instruction - Describe the step-by-step thinking process here... |
66+
| `thought` | string | Yes | Thought Process / Instruction - Describe the step-by-step thinking process here... |
6767

6868
### Outputs
6969

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
import { NextResponse } from 'next/server'
2+
import { createLogger } from '@/lib/logs/console-logger'
3+
4+
interface DiscordChannel {
5+
id: string
6+
name: string
7+
type: number
8+
guild_id?: string
9+
}
10+
11+
const logger = createLogger('DiscordChannelsAPI')
12+
13+
export async function POST(request: Request) {
14+
try {
15+
const { botToken, serverId, channelId } = await request.json()
16+
17+
if (!botToken) {
18+
logger.error('Missing bot token in request')
19+
return NextResponse.json({ error: 'Bot token is required' }, { status: 400 })
20+
}
21+
22+
if (!serverId) {
23+
logger.error('Missing server ID in request')
24+
return NextResponse.json({ error: 'Server ID is required' }, { status: 400 })
25+
}
26+
27+
// If channelId is provided, we'll fetch just that specific channel
28+
if (channelId) {
29+
logger.info(`Fetching single Discord channel: ${channelId}`)
30+
31+
// Fetch a specific channel by ID
32+
const response = await fetch(`https://discord.com/api/v10/channels/${channelId}`, {
33+
method: 'GET',
34+
headers: {
35+
Authorization: `Bot ${botToken}`,
36+
'Content-Type': 'application/json',
37+
},
38+
})
39+
40+
if (!response.ok) {
41+
logger.error('Discord API error fetching channel:', {
42+
status: response.status,
43+
statusText: response.statusText,
44+
})
45+
46+
let errorMessage
47+
try {
48+
const errorData = await response.json()
49+
logger.error('Error details:', errorData)
50+
errorMessage = errorData.message || `Failed to fetch channel (${response.status})`
51+
} catch (e) {
52+
errorMessage = `Failed to fetch channel: ${response.status} ${response.statusText}`
53+
}
54+
return NextResponse.json({ error: errorMessage }, { status: response.status })
55+
}
56+
57+
const channel = (await response.json()) as DiscordChannel
58+
59+
// Verify this is a text channel and belongs to the requested server
60+
if (channel.guild_id !== serverId) {
61+
logger.error('Channel does not belong to the specified server')
62+
return NextResponse.json(
63+
{ error: 'Channel not found in specified server' },
64+
{ status: 404 }
65+
)
66+
}
67+
68+
if (channel.type !== 0) {
69+
logger.warn('Requested channel is not a text channel')
70+
return NextResponse.json({ error: 'Channel is not a text channel' }, { status: 400 })
71+
}
72+
73+
logger.info(`Successfully fetched channel: ${channel.name}`)
74+
75+
return NextResponse.json({
76+
channel: {
77+
id: channel.id,
78+
name: channel.name,
79+
type: channel.type,
80+
},
81+
})
82+
}
83+
84+
logger.info(`Fetching all Discord channels for server: ${serverId}`)
85+
86+
// Fetch all channels from Discord API
87+
const response = await fetch(`https://discord.com/api/v10/guilds/${serverId}/channels`, {
88+
method: 'GET',
89+
headers: {
90+
Authorization: `Bot ${botToken}`,
91+
'Content-Type': 'application/json',
92+
},
93+
})
94+
95+
if (!response.ok) {
96+
logger.error('Discord API error:', {
97+
status: response.status,
98+
statusText: response.statusText,
99+
})
100+
101+
let errorMessage
102+
try {
103+
const errorData = await response.json()
104+
logger.error('Error details:', errorData)
105+
errorMessage = errorData.message || `Failed to fetch channels (${response.status})`
106+
} catch (e) {
107+
errorMessage = `Failed to fetch channels: ${response.status} ${response.statusText}`
108+
}
109+
return NextResponse.json({ error: errorMessage }, { status: response.status })
110+
}
111+
112+
const channels = (await response.json()) as DiscordChannel[]
113+
114+
// Filter to just text channels (type 0)
115+
const textChannels = channels.filter((channel: DiscordChannel) => channel.type === 0)
116+
117+
logger.info(`Successfully fetched ${textChannels.length} text channels`)
118+
119+
return NextResponse.json({
120+
channels: textChannels.map((channel: DiscordChannel) => ({
121+
id: channel.id,
122+
name: channel.name,
123+
type: channel.type,
124+
})),
125+
})
126+
} catch (error) {
127+
logger.error('Error processing request:', error)
128+
return NextResponse.json(
129+
{
130+
error: 'Failed to retrieve Discord channels',
131+
details: (error as Error).message,
132+
},
133+
{ status: 500 }
134+
)
135+
}
136+
}

0 commit comments

Comments
 (0)