Skip to content

Discord

Read guilds, channels, members and message history from Discord, post messages, and decode Discord ids and permissions

Connector software
Free and open source
Service credentials
Required
Query Farm hosting
Not available yet
Use with an agent

Install the Orchard skill in your project to help your agent find connectors, configure them, and verify SQL results.

npx skills add Query-farm/vgi-skills --skill orchard

Copy this request into your coding agent to get started.

Use https://query.farm/products/orchard/connectors/discord/index.md to help me query Discord with DuckDB or Haybarn 2.0.1 and VGI protocol 3.4. Ask only for missing details about the result I need or whether I want local execution, self-hosting or Query Farm hosting. Check the connector's actual hosting availability, credentials and input requirements. Read one format of each needed reference and the exact object declarations before writing SQL. Use a released connector, and distinguish a saved example result from anything you actually execute. If you cannot run the query, tell me what remains to verify.

The first four flags

Example output · captured
Connector release
v0.1.0
Engine
2.0.1
VGI protocol
3.4.0
SELECT name, bit
FROM discord.main.permission_flags
WHERE bit < 4
ORDER BY bit
Result
name bit
CREATE_INSTANT_INVITE 0
KICK_MEMBERS 1
BAN_MEMBERS 2
ADMINISTRATOR 3

Quick start

Choose where to run Discord, then follow the steps below.

The connector runs alongside DuckDB or Haybarn. No Query Farm account is needed.

1. Install the vgi extension

Run this in your SQL client. On DuckDB, keep FROM query_farm on LOAD in later sessions.

setup.sql
SET allow_extension_repositories = 'allowed';

CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
    WITH PREFIX 'https://duckdb-extensions.query.farm';

INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;

2. Attach the connector

Attach the release directly

Downloads the latest release for your platform and caches it locally.

ATTACH 'discord' AS discord (
  TYPE vgi,
  LOCATION 'github-auto://Query-farm/vgi-discord'
);

3. Add service credentials

After attaching, create the secret for the service you want to query in the same SQL session. Replace the placeholders with your service settings.

discord credentials

Discord bot token (and optional API base URL) used by the discord worker's API functions.

Get these credentials →
secret.sql
CREATE SECRET discord (
    TYPE discord,
    token    '<DISCORD_TOKEN>',  -- secret
    api_base '<api_base>'
);
Credential fields and requirements →

4. Run a query

query.sql
SELECT name, bit
FROM discord.main.permission_flags
WHERE bit < 4
ORDER BY bit
More example queries →
Technical details
Verified connector release
v0.1.0
Engine
2.0.1
VGI protocol
3.4.0
Verified on
December 1, 2026
Release notes on GitHub
Pin a version for production

When running the connector yourself, keep a specific release until you’re ready to upgrade. Replace the ATTACH statement above with this one and follow the same extension and credential setup.

Attach the release directly

Uses the verified release each time you attach the connector.

ATTACH 'discord' AS discord (
  TYPE vgi,
  LOCATION 'github-auto://Query-farm/[email protected]'
);

Overview

Discord servers, channels, members and message history as SQL tables, plus posting messages back through a bot token or webhook.

Catalog

Everything discord exposes once attached — read straight from the worker's released build.

discord 1 schema
main 2 tables · 34 functions

All Discord functions and reference tables.

Schema examples (18)
Examples (18)

The first four flags

SELECT name, bit
FROM discord.main.permission_flags
WHERE bit < 4
ORDER BY bit;
Result
name bit
CREATE_INSTANT_INVITE 0
KICK_MEMBERS 1
BAN_MEMBERS 2
ADMINISTRATOR 3

Thread channel types

SELECT type, name
FROM discord.main.channel_types
WHERE name LIKE '%THREAD'
ORDER BY type;
Result
type name
10 ANNOUNCEMENT_THREAD
11 PUBLIC_THREAD
12 PRIVATE_THREAD

Check which bot the token belongs to

SELECT user_id, username, created_at FROM discord.main.me();

The bot's ten largest servers

SELECT name, approximate_member_count
FROM discord.main.guilds()
ORDER BY approximate_member_count DESC
LIMIT 10;
14 more examples

Boost tier and size of one server

SELECT name, owner_id, premium_tier, approximate_member_count
FROM discord.main.guild('123456789012345678');

Count a server's channels by type

SELECT type_name, count(*) AS channels
FROM discord.main.channels('123456789012345678')
GROUP BY type_name
ORDER BY channels DESC;

The five busiest open threads

SELECT name, message_count
FROM discord.main.active_threads('123456789012345678')
ORDER BY message_count DESC
LIMIT 5;

Roles that grant Administrator

SELECT name, position
FROM discord.main.roles('123456789012345678')
WHERE discord.main.has_permission(permissions, 'ADMINISTRATOR')
ORDER BY position DESC;

Human members joining per month

SELECT date_trunc('month', joined_at) AS month, count(*) AS joins
FROM discord.main.members('123456789012345678', max_members := 50000)
WHERE NOT is_bot
GROUP BY month
ORDER BY month;

A server's animated emojis

SELECT name, markup
FROM discord.main.emojis('123456789012345678')
WHERE animated
ORDER BY name;

Upcoming events in date order

SELECT name, scheduled_start, user_count
FROM discord.main.scheduled_events('123456789012345678')
WHERE status = 'SCHEDULED'
ORDER BY scheduled_start;

Most active posters in the last 5000 messages

SELECT author_username, count(*) AS messages
FROM discord.main.messages('123456789012345678', max_messages := 5000)
GROUP BY author_username
ORDER BY messages DESC
LIMIT 10;

Look up one message

SELECT author_username, content, reaction_count
FROM discord.main.message('123456789012345678', '234567890123456789');

A channel's pins, newest first

SELECT pinned_at, author_username, content
FROM discord.main.pinned_messages('123456789012345678')
ORDER BY pinned_at DESC;

Count human thumbs-up votes on a message

SELECT count(*) FILTER (WHERE NOT is_bot) AS votes
FROM discord.main.reaction_users('123456789012345678', '234567890123456789', '👍');

Announce that a job finished

SELECT message_id, created_at
FROM discord.main.send_message('123456789012345678', 'Nightly load finished ✅');

Post a low-stock alert per item and see which posts succeeded and why any failed

SELECT channel_id, message_id, ok, error
FROM discord.main.send_messages((SELECT '123456789012345678' AS channel_id, 'Low stock: ' || sku AS content FROM (VALUES ('A-1', 2), ('B-7', 40), ('C-3', 1)) inv(sku, qty) WHERE qty < 5), fail_on_error := false);
Result
channel_id message_id ok error
123456789012345678 NULL false No Discord bot token: run CREATE SECRET (TYPE discord, TOKEN '...') or set DISC…
123456789012345678 NULL false No Discord bot token: run CREATE SECRET (TYPE discord, TOKEN '...') or set DISC…

Post a daily metric through a webhook

SELECT message_id
FROM discord.main.send_webhook('https://discord.com/api/webhooks/123456789012345678/token', 'Daily revenue: ' || format('{:,}', 12345), username := 'Revenue Bot');
Tables
channel_types 1 example3 cols

Channel Type Reference: static Discord reference data, no token needed.

Columns
typenot null INTEGER
Channel type enum value as sent by the Discord API (unitless code).
name VARCHAR
Channel type name.
description VARCHAR
What the channel type is.
ConstraintsPRIMARY KEY (type)
Example

Thread channel types

SELECT type, name
FROM discord.main.channel_types
WHERE name LIKE '%THREAD'
ORDER BY type;
Result
type name
10 ANNOUNCEMENT_THREAD
11 PUBLIC_THREAD
12 PRIVATE_THREAD
Link
permission_flags 1 example4 cols

Permission Flag Reference: static Discord reference data, no token needed.

Columns
namenot null VARCHAR
Flag name, e.g. SEND_MESSAGES.
bit INTEGER
Zero-based bit index in the permission integer (value = 2^bit).
value VARCHAR
1 << bit as a decimal string.
description VARCHAR
What the permission allows.
ConstraintsPRIMARY KEY (name)
Example

The first four flags

SELECT name, bit
FROM discord.main.permission_flags
WHERE bit < 4
ORDER BY bit;
Result
name bit
CREATE_INSTANT_INVITE 0
KICK_MEMBERS 1
BAN_MEMBERS 2
ADMINISTRATOR 3
Link
Scalar functions
avatar_url (user_id VARCHAR, avatar_hash VARCHAR) 1 example

CDN URL of a user's avatar (or their default avatar when the hash is NULL)

Arguments
user_id VARCHAR
User snowflake id. Invalid ids give NULL.
avatar_hash VARCHAR
Avatar hash from me()/members().avatar; NULL gives the default avatar.
ReturnsVARCHAR
Example

Avatar URL from a hash

SELECT discord.main.avatar_url('80351110224678912', 'abc123') AS url;
Result
url
https://cdn.discordapp.com/avatars/80351110224678912/abc123.png
Link
channel_mention (id VARCHAR) 1 example

Discord mention markup for a channel id, e.g. <#id>

Arguments
id VARCHAR
Channel snowflake id as a string. Invalid ids give NULL.
ReturnsVARCHAR
Example

Mention a channel

SELECT discord.main.channel_mention('80351110224678912') AS m;
Result
m
<#80351110224678912>
Link
channel_type_name (type INTEGER) 1 example

Name of a Discord channel type number, e.g. 0 -> GUILD_TEXT

Arguments
type INTEGER
Channel type number as in channels().type. Unknown numbers give NULL.
ReturnsVARCHAR
Example

Name type 15

SELECT discord.main.channel_type_name(15) AS name;
Result
name
GUILD_FORUM
Link
escape_markdown (text VARCHAR) 1 example

Escape Discord markdown characters so text displays literally

Arguments
text VARCHAR
Text to escape; NULL in, NULL out.
ReturnsVARCHAR
Example

Escape bold and underscore markers

SELECT discord.main.escape_markdown('**not bold** my_file') AS t;
Result
t
\*\*not bold\*\* my\_file
Link
has_permission (permissions VARCHAR, permission VARCHAR) 1 example

Whether a Discord permission bit set includes a named permission flag

Arguments
permissions VARCHAR
A permission bit set as a decimal string, as in roles().permissions or guilds().permissions.
permission VARCHAR
Flag name such as 'ADMINISTRATOR' or 'manage_messages' (case-insensitive).
ReturnsBOOLEAN
Example

Does 8 include ADMINISTRATOR?

SELECT discord.main.has_permission('8', 'ADMINISTRATOR') AS admin;
Result
admin
true
Link
message_url (guild_id VARCHAR, channel_id VARCHAR, message_id VARCHAR) 1 example

Clickable https://discord.com/channels/... link to a message

Arguments
guild_id VARCHAR
Guild id; NULL for a direct message (uses @me).
channel_id VARCHAR
Channel id; NULL gives NULL.
message_id VARCHAR
Message id; NULL gives NULL.
ReturnsVARCHAR
Example

Link to a message

SELECT discord.main.message_url('1', '2', '3') AS url;
Result
url
https://discord.com/channels/1/2/3
Link
permission_names (permissions VARCHAR) 1 example

Decode a Discord permission bit set into a list of flag names

Arguments
permissions VARCHAR
A permission bit set as a decimal string, as in roles().permissions or guilds().permissions.
ReturnsVARCHAR[]
Example

Decode View Channel + Send Messages

SELECT discord.main.permission_names('3072') AS names;
Result
names
["VIEW_CHANNEL", "SEND_MESSAGES"]
Link
role_mention (id VARCHAR) 1 example

Discord mention markup for a role id, e.g. <@&id>

Arguments
id VARCHAR
Role snowflake id as a string. Invalid ids give NULL.
ReturnsVARCHAR
Example

Mention a role

SELECT discord.main.role_mention('80351110224678912') AS m;
Result
m
<@&80351110224678912>
Link
snowflake_from_timestamp (ts TIMESTAMP WITH TIME ZONE) 1 example

The smallest Discord snowflake id created at a given time, for before_id/after_id cursors

Arguments
ts TIMESTAMP WITH TIME ZONE
The moment to convert; moments before the Discord epoch (2015) give '0'.
ReturnsVARCHAR
Example

Id cursor for a fixed instant

SELECT discord.main.snowflake_from_timestamp(TIMESTAMPTZ '2016-04-30 11:18:25.796+00') AS id;
Result
id
175928847298985984
Link
snowflake_parts (id VARCHAR) 1 example

Split a Discord snowflake id into timestamp, worker id, process id and increment

Arguments
id VARCHAR
A Discord snowflake id as a string, e.g. '175928847299117063'. Invalid ids give NULL.
ReturnsSTRUCT of 4 fields
STRUCT 4 fields
  • created_atTIMESTAMP WITH TIME ZONE
  • worker_idINTEGER
  • process_idINTEGER
  • incrementINTEGER
Example

Worker, process and increment of a known id

SELECT p.worker_id, p.process_id, p.increment
FROM (SELECT discord.main.snowflake_parts('175928847299117063') AS p);
Result
worker_id process_id increment
1 0 7
Link
snowflake_timestamp (id VARCHAR) 1 example

Creation time encoded in a Discord snowflake id

Arguments
id VARCHAR
A Discord snowflake id as a string, e.g. '175928847299117063'. Invalid ids give NULL.
ReturnsTIMESTAMP WITH TIME ZONE
Example

Decode the creation time of a user id (UTC epoch milliseconds)

SELECT epoch_ms(discord.main.snowflake_timestamp('175928847299117063')) AS ms;
Result
ms
1,462,015,105,796
Link
timestamp_markdown (ts TIMESTAMP WITH TIME ZONE, style VARCHAR) +1 overload 2 examples

Discord <t:unix> markup that renders a time in each reader's own time zone

Arguments
ts TIMESTAMP WITH TIME ZONE
The moment to render.
style VARCHAR
t short time, T long time, d short date, D long date, f short date/time, F long date/time, R relative ('in 2 hours').
Overloads
timestamp_markdown(ts TIMESTAMP WITH TIME ZONE) → VARCHARtimestamp_markdown(ts TIMESTAMP WITH TIME ZONE, style VARCHAR) → VARCHAR
ReturnsVARCHAR
Examples (2)

Render a time for every reader's time zone

SELECT discord.main.timestamp_markdown(TIMESTAMPTZ '2026-01-01 00:00:00+00') AS t;
Result
t
<t:1767225600>

Relative-time markup

SELECT discord.main.timestamp_markdown(TIMESTAMPTZ '2026-01-01 00:00:00+00', 'R') AS t;
Result
t
<t:1767225600:R>
Link
user_mention (id VARCHAR) 1 example

Discord mention markup for a user id, e.g. <@id>

Arguments
id VARCHAR
User snowflake id as a string. Invalid ids give NULL.
ReturnsVARCHAR
Example

Mention a user

SELECT discord.main.user_mention('80351110224678912') AS m;
Result
m
<@80351110224678912>
Link
Table functions
active_threads (guild_id VARCHAR) 1 example

All active (non-archived) threads in a Discord guild

Arguments
guild_id VARCHAR
Guild (server) snowflake id, as a string, e.g. from discord.main.guilds().
Returns columns
thread_id VARCHAR
Thread (channel) snowflake id.
guild_id VARCHAR
Guild the thread belongs to.
parent_id VARCHAR
Text or forum channel the thread was created in.
name VARCHAR
Thread name.
type_name VARCHAR
PUBLIC_THREAD, PRIVATE_THREAD or ANNOUNCEMENT_THREAD.
owner_id VARCHAR
User id of the thread creator.
message_count INTEGER
Approximate number of messages (excluding the starter).
member_count INTEGER
Approximate number of members (stops counting at 50).
archived BOOLEAN
True when archived.
locked BOOLEAN
True when only moderators can unarchive.
auto_archive_minutes INTEGER
Inactivity minutes before auto-archive.
applied_tags VARCHAR[]
Forum tag ids applied to the thread.
created_at TIMESTAMP WITH TIME ZONE
Thread creation time.
archived_at TIMESTAMP WITH TIME ZONE
Last archive-status change.
Example

The five busiest open threads

SELECT name, message_count
FROM discord.main.active_threads('123456789012345678')
ORDER BY message_count DESC
LIMIT 5;
Link
add_reaction (channel_id VARCHAR, message_id VARCHAR, emoji VARCHAR) 1 example

Add the bot's reaction to a Discord message

Arguments
channel_id VARCHAR
Channel or thread id containing the message.
message_id VARCHAR
Id of the message to react to.
emoji VARCHAR
A unicode emoji such as '✅', or 'name:id' for a custom emoji.
Returns columns
channel_id VARCHAR
Channel id the action applied to.
message_id VARCHAR
Message id the action applied to.
emoji VARCHAR
The emoji added.
ok BOOLEAN
True when Discord accepted the action.
Example

Mark a message as handled

SELECT ok
FROM discord.main.add_reaction('123456789012345678', '234567890123456789', '✅');
Link
channel_types_rows () 1 example

Backing rows of the channel_types table; query the table instead

No arguments
Returns columns
type INTEGER
Channel type enum value as sent by the Discord API (unitless code).
name VARCHAR
Channel type name.
description VARCHAR
What the channel type is.
Example

Count the channel_types rows

SELECT count(*) AS n FROM discord.main.channel_types_rows();
Result
n
13
Link
channels (guild_id VARCHAR) 1 example

All channels (text, voice, categories, forums, ...) in a Discord guild

Arguments
guild_id VARCHAR
Guild (server) snowflake id, as a string, e.g. from discord.main.guilds().
Returns columns
channel_id VARCHAR
Channel snowflake id.
guild_id VARCHAR
Guild the channel belongs to.
name VARCHAR
Channel name.
type INTEGER
Channel type number (see the channel_types table).
type_name VARCHAR
Channel type name, e.g. GUILD_TEXT, GUILD_VOICE.
position INTEGER
Sort position in the channel list.
parent_id VARCHAR
Category id (or parent channel id for threads).
topic VARCHAR
Channel topic.
nsfw BOOLEAN
True for age-restricted channels.
last_message_id VARCHAR
Id of the most recent message (may point to a deleted one).
rate_limit_per_user INTEGER
Slowmode delay in seconds (0 = off).
bitrate INTEGER
Voice bitrate in bits per second.
user_limit INTEGER
Voice user limit (0 = unlimited).
created_at TIMESTAMP WITH TIME ZONE
Channel creation time, from the snowflake.
Example

Count a server's channels by type

SELECT type_name, count(*) AS channels
FROM discord.main.channels('123456789012345678')
GROUP BY type_name
ORDER BY channels DESC;
Link
delete_message (channel_id VARCHAR, message_id VARCHAR) 1 example

Delete a Discord message

Arguments
channel_id VARCHAR
Channel or thread id containing the message.
message_id VARCHAR
Id of the message to delete.
Returns columns
channel_id VARCHAR
Channel id the action applied to.
message_id VARCHAR
Message id the action applied to.
ok BOOLEAN
True when Discord accepted the action.
Example

Delete one message

SELECT ok
FROM discord.main.delete_message('123456789012345678', '234567890123456789');
Link
edit_message (channel_id VARCHAR, message_id VARCHAR, content VARCHAR) 1 example

Replace the text of a message the bot sent and return the edited message

Arguments
channel_id VARCHAR
Channel or thread id containing the message.
message_id VARCHAR
Id of a message the bot authored.
content VARCHAR
Message text; must not be empty or exceed Discord's message length limit. Markdown is rendered.
Returns columns
message_id VARCHAR
Message snowflake id.
channel_id VARCHAR
Channel (or thread) the message is in.
author_id VARCHAR
Author's user id (the webhook id for webhook messages).
author_username VARCHAR
Author's username.
author_global_name VARCHAR
Author's display name.
author_is_bot BOOLEAN
True when the author is a bot.
webhook_id VARCHAR
Set when a webhook posted the message.
type INTEGER
Message type: 0 default, 19 reply, 7 member join, ...
content VARCHAR
Message text (empty without the Message Content intent).
created_at TIMESTAMP WITH TIME ZONE
When the message was sent.
edited_at TIMESTAMP WITH TIME ZONE
When the message was last edited, if ever.
pinned BOOLEAN
True when pinned.
tts BOOLEAN
True for text-to-speech messages.
mention_everyone BOOLEAN
True when the message mentions @everyone or @here.
mentioned_user_ids VARCHAR[]
Ids of users mentioned.
mentioned_role_ids VARCHAR[]
Ids of roles mentioned.
attachment_count INTEGER
Number of attached files.
attachment_urls VARCHAR[]
CDN URLs of attached files.
embed_count INTEGER
Number of embeds.
reactions STRUCT(emoji VARCHAR, count INTEGER)[]
Reactions as a list of {emoji, count}.
reaction_count INTEGER
Total reactions across all emojis.
referenced_message_id VARCHAR
Message this one replies to or forwards.
thread_id VARCHAR
Thread started from this message, if any.
flags INTEGER
Message flag bit set.
Example

Refresh a status message in place

SELECT edited_at
FROM discord.main.edit_message('123456789012345678', '234567890123456789', 'Status: ' || 3 || ' jobs running');
Link
emojis (guild_id VARCHAR) 1 example

Custom emojis uploaded to a Discord guild

Arguments
guild_id VARCHAR
Guild (server) snowflake id, as a string, e.g. from discord.main.guilds().
Returns columns
emoji_id VARCHAR
Emoji snowflake id.
guild_id VARCHAR
Guild id.
name VARCHAR
Emoji name (use as :name: in messages).
animated BOOLEAN
True for animated emojis.
available BOOLEAN
False when unavailable (lost boosts).
managed BOOLEAN
True when managed by an integration.
role_ids VARCHAR[]
Roles allowed to use the emoji (empty = everyone).
creator_id VARCHAR
User who uploaded it (needs Manage Expressions).
markup VARCHAR
Message markup, e.g. <:name:id> or <a:name:id>.
url VARCHAR
CDN URL of the emoji image.
created_at TIMESTAMP WITH TIME ZONE
Upload time, from the snowflake.
Example

A server's animated emojis

SELECT name, markup
FROM discord.main.emojis('123456789012345678')
WHERE animated
ORDER BY name;
Link
guild (guild_id VARCHAR) 1 example

Detailed settings and counts for one Discord guild

Arguments
guild_id VARCHAR
Guild (server) snowflake id, as a string, e.g. from discord.main.guilds().
Returns columns
guild_id VARCHAR
Guild (server) snowflake id.
name VARCHAR
Guild name.
description VARCHAR
Guild description (community guilds).
owner_id VARCHAR
User id of the guild owner.
icon VARCHAR
Icon hash.
verification_level INTEGER
0 none, 1 low, 2 medium, 3 high, 4 very high.
explicit_content_filter INTEGER
0 disabled, 1 members without roles, 2 all members.
mfa_level INTEGER
1 when moderators need two-factor auth.
nsfw_level INTEGER
0 default, 1 explicit, 2 safe, 3 age restricted.
premium_tier INTEGER
Server boost level, 0-3.
premium_subscription_count INTEGER
Number of boosts.
preferred_locale VARCHAR
Preferred locale, e.g. en-US.
vanity_url_code VARCHAR
Vanity invite code, if any.
afk_channel_id VARCHAR
AFK voice channel id.
system_channel_id VARCHAR
Channel for system messages (joins, boosts).
rules_channel_id VARCHAR
Rules channel id (community guilds).
features VARCHAR[]
Enabled guild feature flags.
approximate_member_count INTEGER
Approximate number of members.
approximate_presence_count INTEGER
Approximate number of online members.
max_members INTEGER
Maximum number of members.
role_count INTEGER
Number of roles, including @everyone.
emoji_count INTEGER
Number of custom emojis.
created_at TIMESTAMP WITH TIME ZONE
Guild creation time, from the snowflake.
Example

Boost tier and size of one server

SELECT name, owner_id, premium_tier, approximate_member_count
FROM discord.main.guild('123456789012345678');
Link
guilds () 1 example

Every Discord guild (server) the bot is a member of, with approximate member counts

No arguments
Returns columns
guild_id VARCHAR
Guild (server) snowflake id.
name VARCHAR
Guild name.
icon VARCHAR
Icon hash.
is_owner BOOLEAN
True when the bot owns the guild.
permissions VARCHAR
The bot's permission bit set in the guild (decimal string).
features VARCHAR[]
Enabled guild feature flags, e.g. COMMUNITY.
approximate_member_count INTEGER
Approximate number of members.
approximate_presence_count INTEGER
Approximate number of online members.
created_at TIMESTAMP WITH TIME ZONE
Guild creation time, from the snowflake.
Example

The bot's ten largest servers

SELECT name, approximate_member_count
FROM discord.main.guilds()
ORDER BY approximate_member_count DESC
LIMIT 10;
Link
me () 1 example

The Discord bot user that the configured token authenticates as

No arguments
Returns columns
user_id VARCHAR
User snowflake id.
username VARCHAR
Unique username.
global_name VARCHAR
Display name, if set.
discriminator VARCHAR
Legacy 4-digit tag ('0' for migrated users).
is_bot BOOLEAN
True for bot accounts.
avatar VARCHAR
Avatar hash; pass to avatar_url() for a link.
created_at TIMESTAMP WITH TIME ZONE
Account creation time, from the snowflake.
Example

Check which bot the token belongs to

SELECT user_id, username, created_at FROM discord.main.me();
Link
members (guild_id VARCHAR, max_members := BIGINT) 1 example

Members of a Discord guild, paginated 1000 at a time (needs the Server Members intent)

Positional arguments
guild_id VARCHAR
Guild (server) snowflake id, as a string, e.g. from discord.main.guilds().
Named arguments
max_members := BIGINT
Stop after this many members; 1 to 1,000,000. Default 1000. · default 1000
Returns columns
user_id VARCHAR
Member's user snowflake id.
guild_id VARCHAR
Guild id.
username VARCHAR
Unique username.
global_name VARCHAR
Account-wide display name.
nick VARCHAR
Guild-specific nickname.
display_name VARCHAR
What Discord shows: nick, else global_name, else username.
is_bot BOOLEAN
True for bot accounts.
role_ids VARCHAR[]
Ids of roles assigned to the member (excluding @everyone).
joined_at TIMESTAMP WITH TIME ZONE
When the member joined the guild.
premium_since TIMESTAMP WITH TIME ZONE
When the member started boosting, if boosting.
pending BOOLEAN
True until the member passes membership screening.
timed_out_until TIMESTAMP WITH TIME ZONE
End of an active timeout, if any.
avatar VARCHAR
User avatar hash.
account_created_at TIMESTAMP WITH TIME ZONE
User account creation time, from the snowflake.
Example

Human members joining per month

SELECT date_trunc('month', joined_at) AS month, count(*) AS joins
FROM discord.main.members('123456789012345678', max_members := 50000)
WHERE NOT is_bot
GROUP BY month
ORDER BY month;
Link
message (channel_id VARCHAR, message_id VARCHAR) 1 example

A single Discord message by channel and message id

Arguments
channel_id VARCHAR
Channel or thread snowflake id, as a string, e.g. from discord.main.channels().
message_id VARCHAR
Message snowflake id, as a string.
Returns columns
message_id VARCHAR
Message snowflake id.
channel_id VARCHAR
Channel (or thread) the message is in.
author_id VARCHAR
Author's user id (the webhook id for webhook messages).
author_username VARCHAR
Author's username.
author_global_name VARCHAR
Author's display name.
author_is_bot BOOLEAN
True when the author is a bot.
webhook_id VARCHAR
Set when a webhook posted the message.
type INTEGER
Message type: 0 default, 19 reply, 7 member join, ...
content VARCHAR
Message text (empty without the Message Content intent).
created_at TIMESTAMP WITH TIME ZONE
When the message was sent.
edited_at TIMESTAMP WITH TIME ZONE
When the message was last edited, if ever.
pinned BOOLEAN
True when pinned.
tts BOOLEAN
True for text-to-speech messages.
mention_everyone BOOLEAN
True when the message mentions @everyone or @here.
mentioned_user_ids VARCHAR[]
Ids of users mentioned.
mentioned_role_ids VARCHAR[]
Ids of roles mentioned.
attachment_count INTEGER
Number of attached files.
attachment_urls VARCHAR[]
CDN URLs of attached files.
embed_count INTEGER
Number of embeds.
reactions STRUCT(emoji VARCHAR, count INTEGER)[]
Reactions as a list of {emoji, count}.
reaction_count INTEGER
Total reactions across all emojis.
referenced_message_id VARCHAR
Message this one replies to or forwards.
thread_id VARCHAR
Thread started from this message, if any.
flags INTEGER
Message flag bit set.
Example

Look up one message

SELECT author_username, content, reaction_count
FROM discord.main.message('123456789012345678', '234567890123456789');
Link
messages (channel_id VARCHAR, after_id := VARCHAR, before_id := VARCHAR, max_messages := BIGINT) 2 examples

Message history of a Discord channel or thread, paginated 100 at a time

Positional arguments
channel_id VARCHAR
Channel or thread snowflake id, as a string, e.g. from discord.main.channels().
Named arguments
after_id := VARCHAR
Only messages newer than this message id (walks forwards). Cannot be combined with before_id. · default null
before_id := VARCHAR
Only messages older than this message id (walks backwards). Build one from a time with snowflake_from_timestamp(). · default null
max_messages := BIGINT
Stop after this many messages; 1 to 1,000,000. Default 100. · default 100
Returns columns
message_id VARCHAR
Message snowflake id.
channel_id VARCHAR
Channel (or thread) the message is in.
author_id VARCHAR
Author's user id (the webhook id for webhook messages).
author_username VARCHAR
Author's username.
author_global_name VARCHAR
Author's display name.
author_is_bot BOOLEAN
True when the author is a bot.
webhook_id VARCHAR
Set when a webhook posted the message.
type INTEGER
Message type: 0 default, 19 reply, 7 member join, ...
content VARCHAR
Message text (empty without the Message Content intent).
created_at TIMESTAMP WITH TIME ZONE
When the message was sent.
edited_at TIMESTAMP WITH TIME ZONE
When the message was last edited, if ever.
pinned BOOLEAN
True when pinned.
tts BOOLEAN
True for text-to-speech messages.
mention_everyone BOOLEAN
True when the message mentions @everyone or @here.
mentioned_user_ids VARCHAR[]
Ids of users mentioned.
mentioned_role_ids VARCHAR[]
Ids of roles mentioned.
attachment_count INTEGER
Number of attached files.
attachment_urls VARCHAR[]
CDN URLs of attached files.
embed_count INTEGER
Number of embeds.
reactions STRUCT(emoji VARCHAR, count INTEGER)[]
Reactions as a list of {emoji, count}.
reaction_count INTEGER
Total reactions across all emojis.
referenced_message_id VARCHAR
Message this one replies to or forwards.
thread_id VARCHAR
Thread started from this message, if any.
flags INTEGER
Message flag bit set.
Examples (2)

Most active posters in the last 5000 messages

SELECT author_username, count(*) AS messages
FROM discord.main.messages('123456789012345678', max_messages := 5000)
GROUP BY author_username
ORDER BY messages DESC
LIMIT 10;

Every message since New Year 2026, oldest first

SELECT created_at, author_username, content
FROM discord.main.messages('123456789012345678', max_messages := 10000, after_id := discord.main.snowflake_from_timestamp(TIMESTAMPTZ '2026-01-01 00:00:00+00'))
ORDER BY created_at;
Link
permission_flags_rows () 1 example

Backing rows of the permission_flags table; query the table instead

No arguments
Returns columns
name VARCHAR
Flag name, e.g. SEND_MESSAGES.
bit INTEGER
Zero-based bit index in the permission integer (value = 2^bit).
value VARCHAR
1 << bit as a decimal string.
description VARCHAR
What the permission allows.
Example

Count the permission_flags rows

SELECT count(*) AS n FROM discord.main.permission_flags_rows();
Result
n
51
Link
pinned_messages (channel_id VARCHAR) 1 example

Pinned messages in a Discord channel, most recently pinned first

Arguments
channel_id VARCHAR
Channel or thread snowflake id, as a string, e.g. from discord.main.channels().
Returns columns
pinned_at TIMESTAMP WITH TIME ZONE
When the message was pinned.
message_id VARCHAR
Message snowflake id.
channel_id VARCHAR
Channel (or thread) the message is in.
author_id VARCHAR
Author's user id (the webhook id for webhook messages).
author_username VARCHAR
Author's username.
author_global_name VARCHAR
Author's display name.
author_is_bot BOOLEAN
True when the author is a bot.
webhook_id VARCHAR
Set when a webhook posted the message.
type INTEGER
Message type: 0 default, 19 reply, 7 member join, ...
content VARCHAR
Message text (empty without the Message Content intent).
created_at TIMESTAMP WITH TIME ZONE
When the message was sent.
edited_at TIMESTAMP WITH TIME ZONE
When the message was last edited, if ever.
pinned BOOLEAN
True when pinned.
tts BOOLEAN
True for text-to-speech messages.
mention_everyone BOOLEAN
True when the message mentions @everyone or @here.
mentioned_user_ids VARCHAR[]
Ids of users mentioned.
mentioned_role_ids VARCHAR[]
Ids of roles mentioned.
attachment_count INTEGER
Number of attached files.
attachment_urls VARCHAR[]
CDN URLs of attached files.
embed_count INTEGER
Number of embeds.
reactions STRUCT(emoji VARCHAR, count INTEGER)[]
Reactions as a list of {emoji, count}.
reaction_count INTEGER
Total reactions across all emojis.
referenced_message_id VARCHAR
Message this one replies to or forwards.
thread_id VARCHAR
Thread started from this message, if any.
flags INTEGER
Message flag bit set.
Example

A channel's pins, newest first

SELECT pinned_at, author_username, content
FROM discord.main.pinned_messages('123456789012345678')
ORDER BY pinned_at DESC;
Link
reaction_users (channel_id VARCHAR, message_id VARCHAR, emoji VARCHAR) 1 example

Users who reacted to a Discord message with a given emoji

Arguments
channel_id VARCHAR
Channel or thread snowflake id, as a string, e.g. from discord.main.channels().
message_id VARCHAR
Message snowflake id, as a string.
emoji VARCHAR
A unicode emoji such as '👍', or 'name:id' for a custom emoji (as in messages().reactions).
Returns columns
message_id VARCHAR
The reacted-to message id.
emoji VARCHAR
The emoji, as passed in.
user_id VARCHAR
User snowflake id.
username VARCHAR
Unique username.
global_name VARCHAR
Display name, if set.
discriminator VARCHAR
Legacy 4-digit tag ('0' for migrated users).
is_bot BOOLEAN
True for bot accounts.
avatar VARCHAR
Avatar hash; pass to avatar_url() for a link.
created_at TIMESTAMP WITH TIME ZONE
Account creation time, from the snowflake.
Example

Count human thumbs-up votes on a message

SELECT count(*) FILTER (WHERE NOT is_bot) AS votes
FROM discord.main.reaction_users('123456789012345678', '234567890123456789', '👍');
Link
roles (guild_id VARCHAR) 1 example

All roles defined in a Discord guild, with colors and permission bit sets

Arguments
guild_id VARCHAR
Guild (server) snowflake id, as a string, e.g. from discord.main.guilds().
Returns columns
role_id VARCHAR
Role snowflake id (the @everyone role's id equals the guild id).
guild_id VARCHAR
Guild the role belongs to.
name VARCHAR
Role name.
color INTEGER
RGB color as an integer (0 = no color).
color_hex VARCHAR
Color as #rrggbb, NULL when the role has no color.
hoist BOOLEAN
True when shown separately in the member list.
position INTEGER
Position in the role hierarchy (higher wins).
permissions VARCHAR
Permission bit set (decimal string); decode with permission_names().
managed BOOLEAN
True when managed by an integration or bot.
mentionable BOOLEAN
True when anyone can @mention the role.
created_at TIMESTAMP WITH TIME ZONE
Role creation time, from the snowflake.
Example

Roles that grant Administrator

SELECT name, position
FROM discord.main.roles('123456789012345678')
WHERE discord.main.has_permission(permissions, 'ADMINISTRATOR')
ORDER BY position DESC;
Link
scheduled_events (guild_id VARCHAR) 1 example

Scheduled events in a Discord guild, with subscriber counts

Arguments
guild_id VARCHAR
Guild (server) snowflake id, as a string, e.g. from discord.main.guilds().
Returns columns
event_id VARCHAR
Scheduled event snowflake id.
guild_id VARCHAR
Guild id.
name VARCHAR
Event name.
description VARCHAR
Event description.
status VARCHAR
SCHEDULED, ACTIVE, COMPLETED or CANCELED.
entity_type VARCHAR
STAGE_INSTANCE, VOICE or EXTERNAL.
channel_id VARCHAR
Voice/stage channel id (NULL for external events).
location VARCHAR
Location of an external event.
creator_id VARCHAR
User who created the event.
user_count INTEGER
Users subscribed to the event.
scheduled_start TIMESTAMP WITH TIME ZONE
Scheduled start time.
scheduled_end TIMESTAMP WITH TIME ZONE
Scheduled end time, if set.
Example

Upcoming events in date order

SELECT name, scheduled_start, user_count
FROM discord.main.scheduled_events('123456789012345678')
WHERE status = 'SCHEDULED'
ORDER BY scheduled_start;
Link
send_message (channel_id VARCHAR, content VARCHAR, allow_mentions := BOOLEAN, reply_to := VARCHAR, tts := BOOLEAN) 1 example

Post a message to a Discord channel and return the created message

Positional arguments
channel_id VARCHAR
Channel or thread snowflake id to post in.
content VARCHAR
Message text; must not be empty or exceed Discord's message length limit. Markdown is rendered.
Named arguments
allow_mentions := BOOLEAN
When false (default) no @user, @role or @everyone mention in the text pings anyone; true lets them ping. · default false
reply_to := VARCHAR
Message id to reply to in the same channel; NULL (default) for a normal message. · default null
tts := BOOLEAN
Send as a text-to-speech message. Default false. · default false
Returns columns
message_id VARCHAR
Message snowflake id.
channel_id VARCHAR
Channel (or thread) the message is in.
author_id VARCHAR
Author's user id (the webhook id for webhook messages).
author_username VARCHAR
Author's username.
author_global_name VARCHAR
Author's display name.
author_is_bot BOOLEAN
True when the author is a bot.
webhook_id VARCHAR
Set when a webhook posted the message.
type INTEGER
Message type: 0 default, 19 reply, 7 member join, ...
content VARCHAR
Message text (empty without the Message Content intent).
created_at TIMESTAMP WITH TIME ZONE
When the message was sent.
edited_at TIMESTAMP WITH TIME ZONE
When the message was last edited, if ever.
pinned BOOLEAN
True when pinned.
tts BOOLEAN
True for text-to-speech messages.
mention_everyone BOOLEAN
True when the message mentions @everyone or @here.
mentioned_user_ids VARCHAR[]
Ids of users mentioned.
mentioned_role_ids VARCHAR[]
Ids of roles mentioned.
attachment_count INTEGER
Number of attached files.
attachment_urls VARCHAR[]
CDN URLs of attached files.
embed_count INTEGER
Number of embeds.
reactions STRUCT(emoji VARCHAR, count INTEGER)[]
Reactions as a list of {emoji, count}.
reaction_count INTEGER
Total reactions across all emojis.
referenced_message_id VARCHAR
Message this one replies to or forwards.
thread_id VARCHAR
Thread started from this message, if any.
flags INTEGER
Message flag bit set.
Example

Announce that a job finished

SELECT message_id, created_at
FROM discord.main.send_message('123456789012345678', 'Nightly load finished ✅');
Link
send_webhook (webhook_url VARCHAR, content VARCHAR, allow_mentions := BOOLEAN, avatar_url := VARCHAR, username := VARCHAR) 1 example

Post a message through a Discord webhook URL (no bot token needed)

Positional arguments
webhook_url VARCHAR
Webhook URL from the channel's Integrations settings: https://discord.com/api/webhooks/<id>/<token>.
content VARCHAR
Message text; must not be empty or exceed Discord's message length limit. Markdown is rendered.
Named arguments
allow_mentions := BOOLEAN
When false (default) no @user, @role or @everyone mention in the text pings anyone; true lets them ping. · default false
avatar_url := VARCHAR
Override the webhook's avatar with this image URL. Default NULL keeps it. · default null
username := VARCHAR
Override the webhook's display name for this message. Default NULL keeps it. · default null
Returns columns
message_id VARCHAR
Message snowflake id.
channel_id VARCHAR
Channel (or thread) the message is in.
author_id VARCHAR
Author's user id (the webhook id for webhook messages).
author_username VARCHAR
Author's username.
author_global_name VARCHAR
Author's display name.
author_is_bot BOOLEAN
True when the author is a bot.
webhook_id VARCHAR
Set when a webhook posted the message.
type INTEGER
Message type: 0 default, 19 reply, 7 member join, ...
content VARCHAR
Message text (empty without the Message Content intent).
created_at TIMESTAMP WITH TIME ZONE
When the message was sent.
edited_at TIMESTAMP WITH TIME ZONE
When the message was last edited, if ever.
pinned BOOLEAN
True when pinned.
tts BOOLEAN
True for text-to-speech messages.
mention_everyone BOOLEAN
True when the message mentions @everyone or @here.
mentioned_user_ids VARCHAR[]
Ids of users mentioned.
mentioned_role_ids VARCHAR[]
Ids of roles mentioned.
attachment_count INTEGER
Number of attached files.
attachment_urls VARCHAR[]
CDN URLs of attached files.
embed_count INTEGER
Number of embeds.
reactions STRUCT(emoji VARCHAR, count INTEGER)[]
Reactions as a list of {emoji, count}.
reaction_count INTEGER
Total reactions across all emojis.
referenced_message_id VARCHAR
Message this one replies to or forwards.
thread_id VARCHAR
Thread started from this message, if any.
flags INTEGER
Message flag bit set.
Example

Post a daily metric through a webhook

SELECT message_id
FROM discord.main.send_webhook('https://discord.com/api/webhooks/123456789012345678/token', 'Daily revenue: ' || format('{:,}', 12345), username := 'Revenue Bot');
Link
Table in-out functions
send_messages (data TABLE, allow_mentions := BOOLEAN, fail_on_error := BOOLEAN) 1 example

Post one Discord message per input row (columns channel_id, content, optional reply_to)

Positional arguments
data TABLE
Subquery of messages to send: text columns channel_id and content, optional reply_to.
Named arguments
allow_mentions := BOOLEAN
When false (default) no @user, @role or @everyone mention in the text pings anyone; true lets them ping. · default false
fail_on_error := BOOLEAN
When true (default) the first failure aborts the query; false records it in ok/error and continues. · default true
Returns columns
channel_id VARCHAR
Channel the message was posted to (from the input row).
message_id VARCHAR
Id of the created message; NULL if it failed.
created_at TIMESTAMP WITH TIME ZONE
When the message was created; NULL if it failed.
ok BOOLEAN
True when the message was posted.
error VARCHAR
Error message (with HTTP status) when ok is false.
Example

Post a low-stock alert per item and see which posts succeeded and why any failed

SELECT channel_id, message_id, ok, error
FROM discord.main.send_messages((SELECT '123456789012345678' AS channel_id, 'Low stock: ' || sku AS content FROM (VALUES ('A-1', 2), ('B-7', 40), ('C-3', 1)) inv(sku, qty) WHERE qty < 5), fail_on_error := false);
Result
channel_id message_id ok error
123456789012345678 NULL false No Discord bot token: run CREATE SECRET (TYPE discord, TOKEN '...') or set DISC…
123456789012345678 NULL false No Discord bot token: run CREATE SECRET (TYPE discord, TOKEN '...') or set DISC…
Link

Credentials

The secret type discord declares, as reported by the worker itself.

discord

How to get these credentials

Discord bot token (and optional API base URL) used by the discord worker's API functions.

secret.sql
CREATE SECRET discord (
    TYPE discord,
    token    '<DISCORD_TOKEN>',  -- secret
    api_base '<api_base>'
);
Key Type Required Description
token secret VARCHAR — Discord bot token, from the Bot page of your application in the Discord Developer Portal (Reset Token to reveal it).
api_base VARCHAR — Optional Discord API base URL; defaults to https://discord.com/api/v10.

The worker doesn't mark which keys are required.

Needed by send_messages

Create the secret in the same session, after attaching discord — the worker registers its secret types at ATTACH. Keys marked secret are masked in duckdb_secrets(); angle-bracket values are placeholders. Read credentials from your environment or secret store in your application and pass them through your SQL client’s parameter bindings. Keep real values out of saved SQL and history. Native DuckDB and Haybarn do not provide a SQL getenv() function.

Try these queries

Post a low-stock alert per item and see which posts succeeded and why any failed

SELECT channel_id, message_id, ok, error
FROM discord.main.send_messages((SELECT '123456789012345678' AS channel_id, 'Low stock: ' || sku AS content FROM (VALUES ('A-1', 2), ('B-7', 40), ('C-3', 1)) inv(sku, qty) WHERE qty < 5), fail_on_error := false)
Result
channel_id message_id ok error
123456789012345678 NULL false No Discord bot token: run CREATE SECRET (TYPE discord, TOKEN '...') or set DISC…
123456789012345678 NULL false No Discord bot token: run CREATE SECRET (TYPE discord, TOKEN '...') or set DISC…
Example output · captured
Connector release
v0.1.0
Engine
2.0.1
VGI protocol
3.4.0

Uses send_messages

Thread channel types

SELECT type, name
FROM discord.main.channel_types
WHERE name LIKE '%THREAD'
ORDER BY type
Result
type name
10 ANNOUNCEMENT_THREAD
11 PUBLIC_THREAD
12 PRIVATE_THREAD
Example output · captured
Connector release
v0.1.0
Engine
2.0.1
VGI protocol
3.4.0

Uses channel_types

Worker, process and increment of a known id

SELECT p.worker_id, p.process_id, p.increment
FROM (SELECT discord.main.snowflake_parts('175928847299117063') AS p)
Result
worker_id process_id increment
1 0 7
Example output · captured
Connector release
v0.1.0
Engine
2.0.1
VGI protocol
3.4.0

Uses snowflake_parts

Count the permission_flags rows

SELECT count(*) AS n FROM discord.main.permission_flags_rows()
Result
n
51
Example output · captured
Connector release
v0.1.0
Engine
2.0.1
VGI protocol
3.4.0

Uses permission_flags_rows

Count the channel_types rows

SELECT count(*) AS n FROM discord.main.channel_types_rows()
Result
n
13
Example output · captured
Connector release
v0.1.0
Engine
2.0.1
VGI protocol
3.4.0

Uses channel_types_rows

Decode the creation time of a user id (UTC epoch milliseconds)

SELECT epoch_ms(discord.main.snowflake_timestamp('175928847299117063')) AS ms
Result
ms
1,462,015,105,796
Example output · captured
Connector release
v0.1.0
Engine
2.0.1
VGI protocol
3.4.0

Uses snowflake_timestamp

31 more examples in the Catalog, each listed under the table or function it uses.

Questions it can answer

Plain-English questions from the worker's agent test tasks. An AI agent with this catalog attached should answer each one with SQL.

  • Using the discord worker, when was the Discord object with id 175928847299117063 created? Return epoch milliseconds.
  • Using the discord worker, what are the worker id, process id and increment encoded in Discord id 175928847299117063?
  • Using the discord worker, what message id cursor corresponds to 2026-01-01 00:00 UTC, for reading messages after that time?
  • Using the discord worker, which permission flag names are set in the Discord permission bit set '268435464'?
  • Using the discord worker, does the permission bit set '268435464' include the Administrator permission?
  • Using the discord worker, list the names and bit positions of every Discord permission flag whose name starts with MANAGE_, by bit.

Discord is an independent open-source connector from Query.Farm. It is not affiliated with, endorsed by or sponsored by the services, projects or organisations it works with. Product names, logos and trademarks belong to their respective owners.