Discord
Discord
Let agents keep up with a Discord community: summarize what happened in a busy channel, find the thread where something was decided, search the whole server for a topic, or look up who a member is and which roles they have.
With write access, agents can also take part: post an announcement, reply to a question, start a thread, react with an emoji, or edit and delete what they posted. Everything they post appears as Houston's bot, never as you, and does not ping anyone unless the agent deliberately mentions specific people or roles.
Houston adds its bot to one server you choose. Each connection covers that one server, and Houston cannot see servers it was not added to, or the channels its role is not allowed to view. Read access lets agents read and search, but never post.
Continue with Discord, pick your server and confirm the bot's permissions. See Connect a Discord server.
Setup instructions
Setup instructions
Connect Discord
You need Manage Server permission. Houston installs its own bot; no app setup is required.
- Choose Read or Write for Access in Houston.
- Select Continue with Discord, sign in and choose the server.
- Review permissions and select Authorize.
Every connection to this server sees channels Houston's bot can view, including private channels. Connections keep working if their creator leaves. Only grant the bot access to channels every connected account may read.
Advanced
Discord grants the same bot permissions at either access level; Houston blocks writes on connections with Read access. Adjust the bot's role/channel permissions to restrict reading, posting, threads or reactions. Missing messages may mean the bot lacks View Channels or Read Message History; contact Houston support if message text is empty despite those permissions.
Each connection covers one server; add another for a different server. Changing Houston's access level does not change the bot's Discord permissions.
Deleting a Houston connection leaves the shared bot installed. To stop all access, remove Houston under Server Settings → Integrations or kick the bot.
Files
Files
connector.luau
-- Discord REST API v10 as Houston's bot, bound to the one server (guild) this connection added it to. -- Arguments and results keep Discord's native field names. Credentials are injected only by Houston's proxy. type Options = {[string]: any} type Check = (any, string) -> any local API = "https://discord.com/api/v10/" -- Discord requires this User-Agent format for bots. local AGENT = "DiscordBot (https://ok-houston.com, 1.0)" local LIMIT = 25 local MAX_BODY = 4 * 1024 * 1024 local MAX_ID = "18446744073709551615" -- Captured by Houston from the install's token exchange. The proxy pins every guild route to -- it; channel routes carry no guild, so inGuild below checks each channel against it first. local GUILD: string? = if auth.facts then auth.facts.guild_id else nil local function snowflake(value: any, field: string): string assert(type(value) == "string" and #value <= 20 and string.match(value, "^[1-9]%d*$") ~= nil and (#value < 20 or value <= MAX_ID), "discord: " .. field .. " must be a Discord ID string of digits") return value end local function text(value: any, field: string, max: number): string assert(type(value) == "string" and value ~= "", "discord: " .. field .. " must be a nonempty string") local length = utf8.len(value) assert(length ~= nil and length <= max, "discord: " .. field .. " must be valid UTF-8 of at most " .. max .. " characters") return value end local function integer(min: number, max: number): Check return function(value: any, field: string): any assert(type(value) == "number" and value == math.floor(value) and value >= min and value <= max, "discord: " .. field .. " must be an integer from " .. min .. " to " .. max) return value end end local function boolean(value: any, field: string): any assert(type(value) == "boolean", "discord: " .. field .. " must be a boolean") return value end local function oneOf(values: {any}): Check return function(value: any, field: string): any assert(table.find(values, value) ~= nil, "discord: " .. field .. " must be one of " .. table.concat(values, ", ")) return value end end -- A dense array of 1 to max items; a single string counts as a one-item array. local function array(max: number, each: Check): Check return function(value: any, field: string): any if type(value) == "string" then value = {value} end assert(type(value) == "table", "discord: " .. field .. " must be an array") local count = 0 for _ in value do count += 1 end assert(count >= 1 and count <= max and #value == count, "discord: " .. field .. " must be an array of 1 to " .. max .. " items") local out = table.create(count) for index = 1, count do out[index] = each(value[index], field) end return out end end local function object(value: any, field: string): any assert(type(value) == "table", "discord: " .. field .. " must be a table") return value end -- Messages notify nobody unless the caller names the users or roles to mention. local function mentions(value: any, field: string): any assert(type(value) == "table", "discord: " .. field .. " must be a table") local out: Options = {parse = json.decode("[]")} for key, item in value do if key == "users" or key == "roles" then out[key] = array(100, snowflake)(item, field .. "." .. key) elseif key == "replied_user" then out[key] = boolean(item, field .. ".replied_user") else error("discord: unknown " .. field .. " field " .. tostring(key) .. "; use users, roles or replied_user") end end return out end local function flags(allowed: number): Check return function(value: any, field: string): any integer(0, allowed)(value, field) assert(bit32.band(value, bit32.bnot(allowed)) == 0, "discord: " .. field .. " only accepts the documented flags") return value end end local function nonce(value: any, field: string): any assert(type(value) == "string" and #value <= 25 and string.match(value, "^[%w_%-]+$") ~= nil, "discord: " .. field .. " must be at most 25 letters, digits, - or _") return value end local function timestamp(value: any, field: string): any assert(type(value) == "string" and #value <= 40 and string.match(value, "^%d%d%d%d%-%d%d%-%d%dT[%d:%.]+[%dZ:+%-]*$") ~= nil, "discord: " .. field .. " must be an ISO 8601 timestamp such as 2026-01-31T12:00:00Z") return value end local function options(value: any, allowed: {[string]: Check}): Options local copy: Options = {} if value == nil then return copy end assert(type(value) == "table", "discord: options must be a table") for key, item in value do local check = allowed[key] assert(check ~= nil, "discord: unknown option " .. tostring(key)) copy[key] = check(item, key) end return copy end local SERVER = table.freeze({with_counts = boolean}) local MESSAGES = table.freeze({before = snowflake, after = snowflake, around = snowflake, limit = integer(1, 100)}) local ARCHIVED = table.freeze({before = timestamp, limit = integer(2, 100)}) local MEMBERS = table.freeze({limit = integer(1, 1000)}) local HAS = {"image", "sound", "video", "file", "sticker", "embed", "link", "poll", "snapshot"} for index = 1, #HAS do table.insert(HAS, "-" .. HAS[index]) end local SEARCH = table.freeze({ channel_id = array(500, snowflake), author_id = array(100, snowflake), mentions = array(100, snowflake), author_type = array(6, oneOf({"user", "bot", "webhook", "-user", "-bot", "-webhook"})), has = array(18, oneOf(HAS)), min_id = snowflake, max_id = snowflake, pinned = boolean, include_nsfw = boolean, sort_by = oneOf({"timestamp", "relevance"}), sort_order = oneOf({"desc", "asc"}), limit = integer(1, 25), offset = integer(0, 9975), }) -- SUPPRESS_EMBEDS (4) and SUPPRESS_NOTIFICATIONS (4096); edits only accept SUPPRESS_EMBEDS. local POST = table.freeze({embeds = array(10, object), allowed_mentions = mentions, flags = flags(4100), nonce = nonce, enforce_nonce = boolean}) local EDIT = table.freeze({embeds = array(10, object), allowed_mentions = mentions, flags = flags(4)}) local THREAD = table.freeze({message = snowflake, auto_archive_duration = oneOf({60, 1440, 4320, 10080}), rate_limit_per_user = integer(0, 21600)}) local function query(params: Options): string local parts: {string} = {} for key, value in params do for _, item in (if type(value) == "table" then value else {value}) :: {any} do table.insert(parts, url.encode(key) .. "=" .. url.encode(item)) end end table.sort(parts) return if #parts == 0 then "" else "?" .. table.concat(parts, "&") end local function firstError(errors: any, path: string, depth: number): string? if type(errors) ~= "table" or depth > 8 then return nil end local list = errors._errors if type(list) == "table" and type(list[1]) == "table" and type(list[1].message) == "string" then return (if path == "" then "" else path .. ": ") .. string.sub(list[1].message, 1, 200) end for key, child in errors do local found = firstError(child, if path == "" then tostring(key) else path .. "." .. tostring(key), depth + 1) if found then return found end end return nil end local function retryAfter(headers: HttpHeaders, body: any): string? local wait = headers["retry-after"] if wait and wait[1] then return string.sub(wait[1], 1, 10) end if type(body) == "table" and type(body.retry_after) == "number" and body.retry_after > 0 and body.retry_after < 1e6 then return tostring(math.ceil(body.retry_after)) end return nil end -- Discord bans clients that repeat 401, 403 and 429 responses, so none of them is retried here. local function fail(operation: string, response: HttpResponse, write: boolean, guildRoute: boolean): never local status = response.statusCode local ok, body = pcall(json.decode, await(response.body:readPrefix(4096))) if not ok or type(body) ~= "table" then body = nil end local code = if body and type(body.code) == "number" then body.code else nil local message: string if status == 401 then message = "discord: Discord rejected Houston's bot credentials. This is a Houston configuration problem, not a problem with your connection; reconnecting does not fix it" elseif guildRoute and status == 404 and code == 10004 then message = "discord: Houston was removed from this Discord server; open the connection settings and add it again" elseif status == 403 and code == 50013 then message = "discord: Houston's bot lacks a Discord permission for this action (code 50013); a server admin can grant it in the channel or role settings" else message = "discord: " .. (if body and type(body.message) == "string" then string.sub(body.message, 1, 200) else "HTTP " .. status) if code and code ~= 0 then message ..= " (code " .. code .. ")" end local detail = if body then firstError(body.errors, "", 0) else nil if detail then message ..= ": " .. detail end end local wait = if status == 429 then retryAfter(response.headers, body) else nil if wait then message ..= "; retry after " .. wait .. "s" end -- A rejected (429) write had no effect; after a 5xx a write may still have been applied. return houston.fail({operation = operation, layer = "upstream", upstream_status = status, retryable = status == 429 or (status >= 500 and not write), message = message}) end local function send(method: string, path: string, params: Options?, body: any?): HttpResponse local headers: HttpHeaders = {["User-Agent"] = {AGENT}} local request: HttpRequest = {method = method, url = API .. path .. query(params or {}), headers = headers} if body ~= nil then headers["Content-Type"] = {"application/json"} request.body = json.encode(body) end return await(http.request(request)) end local function decode(operation: string, method: string, path: string, response: HttpResponse): any local status = response.statusCode if status < 200 or status >= 300 then fail(operation, response, method ~= "GET", string.sub(path, 1, 7) == "guilds/") end if status == 204 then response.body:close() return true end local ok, body = pcall(json.decode, await(response.body:readAll(MAX_BODY))) if not ok or type(body) ~= "table" then return houston.fail({operation = operation, layer = "upstream", upstream_status = status, retryable = false, message = "discord: invalid JSON response"}) end -- Search answers 202 with code 110000 while Discord is still indexing the server. if status == 202 then local wait = retryAfter(response.headers, body) return houston.fail({operation = operation, layer = "upstream", upstream_status = status, retryable = true, message = "discord: Discord is still indexing this server for search; retry after " .. (if wait then wait .. "s" else "a few seconds")}) end return body end local function call(operation: string, method: string, path: string, params: Options?, body: any?): any return decode(operation, method, path, send(method, path, params, body)) end local function guild(operation: string, path: string): string if GUILD == nil then return houston.fail({operation = operation, layer = "upstream", retryable = false, message = "discord: this connection is not bound to a Discord server; open the connection settings and add Houston to a server again"}) end return "guilds/" .. GUILD .. path end -- The isolation guard for channel, thread and message routes: Discord serves any channel the bot -- can see, in any server. Every outcome other than a channel of the bound server raises the same -- error, so a foreign or DM channel is never returned or distinguished from a missing one. local function inGuild(operation: string, channel: string): Options snowflake(channel, "channel ID") guild(operation, "") local path = "channels/" .. channel local response = send("GET", path) if response.statusCode == 403 or response.statusCode == 404 then response.body:close() else local found = decode(operation, "GET", path, response) if type(found) == "table" and found.guild_id == GUILD then return found end end return houston.fail({operation = operation, layer = "upstream", upstream_status = 404, retryable = false, message = "discord: channel " .. channel .. " is not in this server, or Houston's bot cannot view it (for example after the bot was removed from the server)"}) end local function channelPath(operation: string, channel: string, rest: string): string inGuild(operation, channel) return "channels/" .. channel .. rest end local function messagePath(operation: string, channel: string, message: string, rest: string): string snowflake(message, "message ID") return channelPath(operation, channel, "/messages/" .. message .. rest) end local function emoji(value: any): string assert(type(value) == "string" and value ~= "" and #value <= 200, "discord: emoji must be a nonempty string") local name, id = string.match(value, "^<a?:([%w_]+):(%d+)>$") if name == nil then name, id = string.match(value, "^([%w_]+):(%d+)$") end if name ~= nil and id ~= nil then return url.encode(name .. ":" .. snowflake(id, "custom emoji ID")) end assert(utf8.len(value) ~= nil and string.find(value, "[%c%s/\\%%:<>]") == nil and string.find(value, "[\128-\255]") ~= nil, "discord: emoji must be a Unicode emoji such as \"👍\" or a custom emoji as \"name:id\"") return url.encode(value) end local function getServer(opts: Options?): Options local params = options(opts, SERVER) return call("getServer", "GET", guild("getServer", ""), params) end local function listChannels(): Options return call("listChannels", "GET", guild("listChannels", "/channels")) end local function getChannel(channel: string): Options return inGuild("getChannel", channel) end local function listMessages(channel: string, opts: Options?): Options local params = options(opts, MESSAGES) local anchors = (if params.before then 1 else 0) + (if params.after then 1 else 0) + (if params.around then 1 else 0) assert(anchors <= 1, "discord: pass only one of before, after and around") params.limit = params.limit or LIMIT return call("listMessages", "GET", channelPath("listMessages", channel, "/messages"), params) end local function getMessage(channel: string, message: string): Options return call("getMessage", "GET", messagePath("getMessage", channel, message, "")) end local function listThreads(): Options return call("listThreads", "GET", guild("listThreads", "/threads/active")) end local function listArchivedThreads(channel: string, opts: Options?): Options local params = options(opts, ARCHIVED) params.limit = params.limit or LIMIT return call("listArchivedThreads", "GET", channelPath("listArchivedThreads", channel, "/threads/archived/public"), params) end local function searchMessages(content: string?, opts: Options?): Options local params = options(opts, SEARCH) if content ~= nil and content ~= "" then params.content = text(content, "query", 1024) end return call("searchMessages", "GET", guild("searchMessages", "/messages/search"), params) end local function searchMembers(prefix: string, opts: Options?): Options local params = options(opts, MEMBERS) params.query = text(prefix, "query", 100) params.limit = params.limit or LIMIT return call("searchMembers", "GET", guild("searchMembers", "/members/search"), params) end local function getMember(user: string): Options return call("getMember", "GET", guild("getMember", "/members/" .. snowflake(user, "user ID"))) end local function listRoles(): Options return call("listRoles", "GET", guild("listRoles", "/roles")) end local function messageBody(content: string, opts: Options?, allowed: {[string]: Check}): Options local body = options(opts, allowed) body.content = text(content, "content", 2000) body.allowed_mentions = body.allowed_mentions or {parse = json.decode("[]")} return body end local function postMessage(channel: string, content: string, opts: Options?): Options local body = messageBody(content, opts, POST) return call("postMessage", "POST", channelPath("postMessage", channel, "/messages"), nil, body) end local function reply(channel: string, message: string, content: string, opts: Options?): Options local body = messageBody(content, opts, POST) body.message_reference = {message_id = snowflake(message, "message ID")} return call("reply", "POST", channelPath("reply", channel, "/messages"), nil, body) end local function editMessage(channel: string, message: string, content: string, opts: Options?): Options local body = messageBody(content, opts, EDIT) return call("editMessage", "PATCH", messagePath("editMessage", channel, message, ""), nil, body) end local function deleteMessage(channel: string, message: string): boolean return call("deleteMessage", "DELETE", messagePath("deleteMessage", channel, message, "")) end local function reaction(operation: string, method: string, channel: string, message: string, value: string): boolean local encoded = emoji(value) return call(operation, method, messagePath(operation, channel, message, "/reactions/" .. encoded .. "/@me")) end local function createThread(channel: string, name: string, opts: Options?): Options local body = options(opts, THREAD) body.name = text(name, "name", 100) local start = body.message body.message = nil local parent = inGuild("createThread", channel) if start then return call("createThread", "POST", "channels/" .. channel .. "/messages/" .. start .. "/threads", nil, body) end assert(parent.type == 0 or parent.type == 5, "discord: threads without a starting message need a text or announcement channel") body.type = if parent.type == 5 then 10 else 11 return call("createThread", "POST", "channels/" .. channel .. "/threads", nil, body) end local exports: {[string]: any} = { getServer = getServer, listChannels = listChannels, getChannel = getChannel, listMessages = listMessages, getMessage = getMessage, listThreads = listThreads, listArchivedThreads = listArchivedThreads, searchMessages = searchMessages, searchMembers = searchMembers, getMember = getMember, listRoles = listRoles, } if houston.allows("data:write") then exports.postMessage = postMessage exports.reply = reply exports.editMessage = editMessage exports.deleteMessage = deleteMessage exports.addReaction = function(channel: string, message: string, value: string): boolean return reaction("addReaction", "PUT", channel, message, value) end exports.removeReaction = function(channel: string, message: string, value: string): boolean return reaction("removeReaction", "DELETE", channel, message, value) end exports.createThread = createThread end local operationHelp: {[string]: string} = { getServer = [[getServer(opts?) -> guild The connected server: id, name, description, owner_id, roles, emojis, features... opts: with_counts (true adds approximate_member_count and approximate_presence_count).]], listChannels = [[listChannels() -> {channel} The server's channels and categories (not threads): id, type (0 text, 2 voice, 4 category, 5 announcement, 15 forum), name, parent_id, position, topic. Channels Houston's bot cannot view may be missing.]], getChannel = [[getChannel(channel) -> channel One channel or thread of this server.]], listMessages = [[listMessages(channel, opts?) -> {message} Newest first. opts: limit (1-100, default 25) and at most one of before, after or around (message IDs). For older messages pass before = the last message's id. Returns [] when the bot lacks Read Message History in that channel.]], getMessage = [[getMessage(channel, message) -> message One message: id, channel_id, author, content, timestamp, edited_timestamp, attachments, embeds, mentions, reactions, message_reference, referenced_message, thread...]], listThreads = [[listThreads() -> {threads, members} Active threads in the whole server, newest first; members lists the threads the bot has joined.]], listArchivedThreads = [[listArchivedThreads(channel, opts?) -> {threads, members, has_more} Public archived threads of a text or announcement channel, most recently archived first. opts: limit (2-100, default 25), before (ISO 8601 timestamp; pass the last thread's thread_metadata.archive_timestamp for the next page).]], searchMessages = [[searchMessages(query, opts?) -> {total_results, messages, threads?, members?} Searches the whole server; query is the text to match, or "" to search by filters only. Each item of messages is a one-element array holding the matching message. opts (Discord's names): channel_id, author_id, mentions (ID or array of IDs), author_type ("user", "bot", "webhook", "-bot"...), has ("link", "file", "image", "embed", "-link"...), min_id, max_id, pinned, include_nsfw, sort_by ("timestamp" default or "relevance"), sort_order ("desc" default or "asc"), limit (1-25, default 25), offset (0-9975). Discord can return fewer than limit even when more match, so get the next page with offset = offset + limit; total_results is approximate. While Discord indexes a server for the first time this fails as retryable with the wait.]], searchMembers = [[searchMembers(query, opts?) -> {member} Members whose username or nickname starts with query (1-100 characters). opts: limit (1-1000, default 25). Each member: user {id, username, global_name, bot?}, nick, roles (role IDs), joined_at.]], getMember = [[getMember(user) -> member One member of this server by user ID.]], listRoles = [[listRoles() -> {role} The server's roles: id, name, color, position, permissions, mentionable. The @everyone role's id is the server id.]], postMessage = [[postMessage(channel, content, opts?) -> message Posts as Houston's bot in a channel or thread; content is 1-2000 characters of Discord markdown. Mention people as <@userId> and roles as <@&roleId>; mentions notify nobody unless opts.allowed_mentions names them: {users = {userId}, roles = {roleId}, replied_user = true}. opts: embeds (up to 10 embed objects), allowed_mentions, flags (4 suppresses link previews, 4096 sends silently), nonce plus enforce_nonce = true (Discord then ignores a repeat with the same nonce for a few minutes). After an error the message may already be posted: check listMessages, or resend with the same nonce and enforce_nonce, rather than retrying blindly.]], reply = [[reply(channel, message, content, opts?) -> message Replies to a message in the same channel. Same opts as postMessage; the replied-to author is notified only with allowed_mentions.replied_user = true.]], editMessage = [[editMessage(channel, message, content, opts?) -> message Replaces the content of a message Houston's bot posted. opts: embeds, allowed_mentions, flags (4 suppresses link previews).]], deleteMessage = [[deleteMessage(channel, message) -> true Deletes a message Houston's bot posted; other people's messages cannot be deleted.]], addReaction = [[addReaction(channel, message, emoji) -> true Reacts as Houston's bot. emoji is the Unicode character, such as "👍", or a server emoji as "name:id"; Slack-style names such as "thumbsup" are rejected.]], removeReaction = [[removeReaction(channel, message, emoji) -> true Removes Houston's bot's reaction. Same emoji format as addReaction.]], createThread = [[createThread(channel, name, opts?) -> channel Starts a public thread named name (1-100 characters) and returns it; post into it with postMessage(thread.id, ...). opts: message (start the thread from this message; one thread per message), auto_archive_duration (60, 1440, 4320 or 10080 minutes), rate_limit_per_user (0-21600 seconds). Without message the channel must be a text or announcement channel; forum posts are not supported.]], } exports.help = function(): string local names: {string} = {} for name in exports do if name ~= "help" then table.insert(names, name) end end table.sort(names) local sections = {[[Discord: Houston's bot in one Discord server, the one this connection added it to. Credentials stay on Houston. Calls return completed values; do not wrap them in await(). Pass every ID (server, channel, thread, message, user, role) as a string, never a number. Results keep Discord's field names. Unknown options are rejected. Scope: guild routes always address the connected server, and channel, thread and message calls first check that the channel belongs to it; any other channel, including DMs, fails with "is not in this server". Threads are channels: pass a thread's id wherever a channel is expected. The bot sees only channels its role can view. Without Discord's Message Content access, messages from other people can have empty content, embeds and attachments (the bot's own messages and messages mentioning it stay complete). Each call returns one page and never paginates on its own. Discord rate-limits the bot across every Houston server, so prefer searchMessages over scanning channels page by page, keep limits small, and do not loop over many channels. Rate-limited calls fail as retryable with the wait; permission errors (403) never succeed on retry. Writes act as Houston's bot, need write access and never retry automatically.]]} for _, name in names do local section = operationHelp[name] assert(section, "missing help for configured function " .. name) table.insert(sections, "## " .. section) end return table.concat(sections, "\n\n") end return exportshouston.json
{ "schema_version": 2, "name": "Discord", "files": [ "connector.luau" ], "icon": "icon.svg", "access": [ { "name": "data", "label": "Access", "levels": [ { "value": "read", "label": "Read" }, { "value": "write", "label": "Write" } ], "default": "read" } ], "auth": { "oauth": { "type": "oauth2", "label": "Continue with Discord", "brand": "discord", "authorize_url": "https://discord.com/oauth2/authorize", "token_url": "https://discord.com/api/oauth2/token", "client_id": "{{publisher.client_id}}", "client_secret": "{{publisher.client_secret}}", "client_auth": "basic", "pkce": "none", "scopes": [ { "values": [ "bot" ] } ], "authorize_params": { "permissions": "309237730368" }, "token_response": { "checks": [ { "op": "equals", "path": "/token_type", "value": "Bearer" }, { "op": "exists", "path": "/guild/id" } ], "facts": { "guild_id": "/guild/id" }, "label": "/guild/name", "scopes_unreported": true } } }, "publisher": { "client_id": { "label": "Discord client ID", "order": 1, "required": true, "type": "string" }, "client_secret": { "label": "Discord client secret", "order": 2, "required": true, "type": "secret" }, "bot_token": { "label": "Discord bot token", "order": 3, "required": true, "type": "secret" } }, "proxy": [ { "match": { "protocol": "http", "host": [ "discord.com" ], "method": [ "GET" ], "path": [ "/api/v10/guilds/{{auth.oauth.guild_id}}", "/api/v10/guilds/{{auth.oauth.guild_id}}/channels", "/api/v10/guilds/{{auth.oauth.guild_id}}/threads/active", "/api/v10/guilds/{{auth.oauth.guild_id}}/roles", "/api/v10/guilds/{{auth.oauth.guild_id}}/members/search", "/api/v10/guilds/{{auth.oauth.guild_id}}/members/{user_id}", "/api/v10/guilds/{{auth.oauth.guild_id}}/messages/search", "/api/v10/channels/{channel_id}", "/api/v10/channels/{channel_id}/messages", "/api/v10/channels/{channel_id}/messages/{message_id}", "/api/v10/channels/{channel_id}/threads/archived/public" ] }, "action": { "headers": { "set": { "Authorization": "Bot {{publisher.bot_token}}" } } } }, { "if": "{{ allows access.data \"write\" }}", "match": { "protocol": "http", "host": [ "discord.com" ], "method": [ "POST" ], "path": [ "/api/v10/channels/{channel_id}/messages", "/api/v10/channels/{channel_id}/messages/{message_id}/threads", "/api/v10/channels/{channel_id}/threads" ] }, "action": { "headers": { "set": { "Authorization": "Bot {{publisher.bot_token}}" } } } }, { "if": "{{ allows access.data \"write\" }}", "match": { "protocol": "http", "host": [ "discord.com" ], "method": [ "PATCH", "DELETE" ], "path": [ "/api/v10/channels/{channel_id}/messages/{message_id}" ] }, "action": { "headers": { "set": { "Authorization": "Bot {{publisher.bot_token}}" } } } }, { "if": "{{ allows access.data \"write\" }}", "match": { "protocol": "http", "host": [ "discord.com" ], "method": [ "PUT", "DELETE" ], "path": [ "/api/v10/channels/{channel_id}/messages/{message_id}/reactions/{emoji}/@me" ], "colon_path_parameters": [ "emoji" ] }, "action": { "headers": { "set": { "Authorization": "Bot {{publisher.bot_token}}" } } } } ] }icon.svg
README.md
--- description: Let agents read and search a Discord server, and post, reply and react as Houston's bot. --- # Discord Let agents keep up with a Discord community: summarize what happened in a busy channel, find the thread where something was decided, search the whole server for a topic, or look up who a member is and which roles they have. With write access, agents can also take part: post an announcement, reply to a question, start a thread, react with an emoji, or edit and delete what they posted. Everything they post appears as Houston's bot, never as you, and does not ping anyone unless the agent deliberately mentions specific people or roles. Houston adds its bot to one server you choose. Each connection covers that one server, and Houston cannot see servers it was not added to, or the channels its role is not allowed to view. Read access lets agents read and search, but never post. Continue with Discord, pick your server and confirm the bot's permissions. See [Connect a Discord server](SETUP.md).SETUP.md
# Connect Discord You need **Manage Server** permission. Houston installs its own bot; no app setup is required. 1. Choose **Read** or **Write** for **Access** in Houston. 2. Select **Continue with Discord**, sign in and choose the server. 3. Review permissions and select **Authorize**. > Every connection to this server sees channels Houston's bot can view, including > private channels. Connections keep working if their creator leaves. Only grant > the bot access to channels every connected account may read. ## Advanced Discord grants the same bot permissions at either access level; Houston blocks writes on connections with **Read** access. Adjust the bot's role/channel permissions to restrict reading, posting, threads or reactions. Missing messages may mean the bot lacks **View Channels** or **Read Message History**; contact Houston support if message text is empty despite those permissions. Each connection covers one server; add another for a different server. Changing Houston's access level does not change the bot's Discord permissions. Deleting a Houston connection leaves the shared bot installed. To stop all access, remove Houston under **Server Settings → Integrations** or kick the bot.tests
authentication.luau
return { contract = function(m) m.authentication({ { auth = {}, config = {}, endpoint = { "GET", "https://discord.com/api/v10/channels/1300000000000000001" }, expected = "Bot synthetic-bot-secret", header = "Authorization", method = "oauth", oauth = true, publisher = { bot_token = "synthetic-bot-secret", client_id = "synthetic-public-client", client_secret = "synthetic-client-secret", }, scopes = true, }, }) end, }errors.luau
return { scenario = {publisher = {client_id = "fixture-client", client_secret = "fixture-private-secret", bot_token = "fixture-bot-token"}, config = {}, auth_method = "oauth", auth_config = {}, granted_scopes = {"bot"}, facts = {guild_id = "290926798626357999"}}, access = {data = "write"}, configure = function() calls, queue = 0, {} http = {request = function(req) calls += 1 local response = table.remove(queue, 1) assert(response, "unexpected request: " .. req.url) return fixture.operation({statusCode = response[1], headers = response[3] or {}, body = fixture.reader(response[2])}) end} C, M = "1300000000000000001", "1400000000000000001" CHANNEL = {200, '{"id":"' .. C .. '","type":0,"guild_id":"290926798626357999"}'} end, run = function(discord) -- Each case queues the exact responses; a retried call would find the queue empty. local function upstream(responses, expected, call) queue = responses local before, expectedCalls = calls, #responses local ok, err = pcall(call or function() discord.listRoles() end) for _, text in expected do assert(not ok and string.find(tostring(err), text, 1, true), "missing " .. text .. " in " .. tostring(err)) end assert(calls == before + expectedCalls and #queue == 0, "failed call was retried or stopped early") return tostring(err) end local post = function() discord.postMessage(C, "Hi") end upstream({{401, '{"message":"401: Unauthorized","code":0}'}}, {"Houston configuration problem", "reconnecting does not fix it", '"upstream_status":401', '"retryable":false'}) upstream({{401, '{"message":"401: Unauthorized","code":0}'}}, {"Houston configuration problem"}, function() discord.getChannel(C) end) upstream({{403, '{"message":"Missing Access","code":50001}'}}, {"discord: Missing Access (code 50001)", '"upstream_status":403', '"retryable":false'}) upstream({{404, '{"message":"Unknown Guild","code":10004}'}}, {"Houston was removed from this Discord server; open the connection settings and add it again", '"upstream_status":404'}, function() discord.searchMessages("x") end) upstream({{404, '{"message":"Unknown Member","code":10007}'}}, {"discord: Unknown Member (code 10007)", '"upstream_status":404'}, function() discord.getMember("80351110224678912") end) upstream({CHANNEL, {403, '{"message":"Missing Permissions","code":50013}'}}, {"lacks a Discord permission for this action (code 50013)", '"upstream_status":403', '"retryable":false'}, post) upstream({CHANNEL, {403, '{"message":"Missing Access","code":50001}'}}, {"discord: Missing Access (code 50001)"}, function() discord.getMessage(C, M) end) upstream({CHANNEL, {400, '{"message":"Invalid Form Body","code":50035,"errors":{"embeds":{"0":{"title":{"_errors":[{"code":"BASE_TYPE_MAX_LENGTH","message":"Must be 256 or fewer in length."}]}}}}}'}}, {"discord: Invalid Form Body (code 50035): embeds.0.title: Must be 256 or fewer in length.", '"upstream_status":400'}, post) upstream({{429, '{"message":"You are being rate limited.","retry_after":64.57,"global":false}', {["retry-after"] = {"65"}}}}, {"rate limited.; retry after 65s", '"upstream_status":429', '"retryable":true'}) upstream({{429, '{"message":"You are being rate limited.","retry_after":1.5,"global":true}'}}, {"retry after 2s", '"retryable":true'}) upstream({CHANNEL, {429, '{"message":"You are being rate limited.","retry_after":3,"code":20028}'}}, {"(code 20028); retry after 3s", '"retryable":true'}, post) upstream({{503, "<html>Service Unavailable</html>"}}, {"discord: HTTP 503", '"retryable":true'}) upstream({CHANNEL, {502, "<html>Bad Gateway</html>"}}, {"discord: HTTP 502", '"retryable":false'}, post) upstream({CHANNEL, {500, '{"message":"500: Internal Server Error","code":0}'}}, {"Internal Server Error", '"retryable":false'}, function() discord.deleteMessage(C, M) end) upstream({{202, '{"message":"Index not yet available. Try again later","code":110000,"documents_indexed":0,"retry_after":2}'}}, {"still indexing this server for search; retry after 2s", '"upstream_status":202', '"retryable":true'}, function() discord.searchMessages("deploy") end) upstream({{202, '{"message":"Index not yet available. Try again later","code":110000,"documents_indexed":0,"retry_after":0}'}}, {"retry after a few seconds", '"retryable":true'}, function() discord.searchMessages("deploy") end) upstream({{200, "<html>Maintenance</html>"}}, {"discord: invalid JSON response", '"retryable":false'}) upstream({{200, '"ok"'}}, {"discord: invalid JSON response"}) local long = upstream({{400, '{"message":"' .. string.rep("x", 5000) .. '","code":50035}'}}, {"discord: HTTP 400"}) assert(#long < 1000, "error messages stay bounded") long = upstream({{400, '{"message":"' .. string.rep("x", 3000) .. '","code":50035}'}}, {"discord: xxxx"}) assert(#long < 1000, "error messages stay bounded") end, }guild_guard.luau
return { scenario = {publisher = {client_id = "fixture-client", client_secret = "fixture-private-secret", bot_token = "fixture-bot-token"}, config = {}, auth_method = "oauth", auth_config = {}, granted_scopes = {"bot"}, facts = {guild_id = "290926798626357999"}}, access = {data = "write"}, configure = function() requests, guard = {}, nil http = {request = function(req) table.insert(requests, req) assert(guard, "unexpected request: " .. req.url) local response = guard guard = nil return fixture.operation({statusCode = response[1], headers = {}, body = fixture.reader(response[2])}) end} end, run = function(discord) local C, M, E = "1300000000000000001", "1400000000000000001", "1600000000000000001" local foreign = {200, '{"id":"' .. C .. '","type":0,"guild_id":"390926798626357000","name":"secret-plans","topic":"acquisition"}'} local thread = {200, '{"id":"' .. C .. '","type":11,"guild_id":"390926798626357000","parent_id":"1","name":"secret-thread"}'} local dm = {200, '{"id":"' .. C .. '","type":1,"recipients":[{"id":"80351110224678912","username":"ana"}],"last_message_id":"1"}'} local missing = {404, '{"message":"Unknown Channel","code":10003}'} local hidden = {403, '{"message":"Missing Access","code":50001}'} local unbound = {200, '{"id":"' .. C .. '","type":0,"name":"no-guild"}'} local calls = { function() return discord.getChannel(C) end, function() return discord.listMessages(C) end, function() return discord.getMessage(C, M) end, function() return discord.listArchivedThreads(C) end, function() return discord.postMessage(C, "Hi") end, function() return discord.reply(C, M, "Hi") end, function() return discord.editMessage(C, M, "Hi") end, function() return discord.deleteMessage(C, M) end, function() return discord.addReaction(C, M, "👍") end, function() return discord.removeReaction(C, M, "houston:" .. E) end, function() return discord.createThread(C, "Plan") end, function() return discord.createThread(C, "Plan", {message = M}) end, } for _, response in {foreign, thread, dm, missing, hidden, unbound} do for index, call in calls do guard = response local before = #requests local ok, err = pcall(call) local message = tostring(err) assert(not ok, "call " .. index .. " accepted a channel outside the server") assert(#requests == before + 1 and requests[#requests].method == "GET" and requests[#requests].url == "https://discord.com/api/v10/channels/" .. C, "call " .. index .. " sent more than the guard request") assert(string.find(message, "channel " .. C .. " is not in this server, or Houston's bot cannot view it", 1, true) and string.find(message, '"upstream_status":404', 1, true), "one generic error: " .. message) for _, leak in {"secret", "acquisition", "390926798626357000", "ana", "Unknown Channel", "Missing Access", "no-guild"} do assert(not string.find(message, leak, 1, true), "the foreign channel leaked " .. leak) end end end end, }manifest.luau
return { contract = function(m) -- TestDiscordBoundServerRoutes do if not (m.publisherClient(m.raw.auth["oauth"])) then m.fail("Discord OAuth client must belong to the publication") end local api, guild, other = "https://discord.com/api/v10", "290926798626357999", "390926798626357000" local read = { "GET " .. api .. "/guilds/" .. guild, "GET " .. api .. "/guilds/" .. guild .. "?with_counts=true", "GET " .. api .. "/guilds/" .. guild .. "/channels", "GET " .. api .. "/guilds/" .. guild .. "/threads/active", "GET " .. api .. "/guilds/" .. guild .. "/roles", "GET " .. api .. "/guilds/" .. guild .. "/members/search?query=a&limit=25", "GET " .. api .. "/guilds/" .. guild .. "/members/80351110224678912", "GET " .. api .. "/guilds/" .. guild .. "/messages/search?content=hi&channel_id=1&channel_id=2", "GET " .. api .. "/channels/1300000000000000001", "GET " .. api .. "/channels/1300000000000000001/messages?limit=25", "GET " .. api .. "/channels/1300000000000000001/messages/1400000000000000001", "GET " .. api .. "/channels/1300000000000000001/threads/archived/public?limit=25", } local writes = { "POST " .. api .. "/channels/1300000000000000001/messages", "PATCH " .. api .. "/channels/1300000000000000001/messages/1400000000000000001", "DELETE " .. api .. "/channels/1300000000000000001/messages/1400000000000000001", "PUT " .. api .. "/channels/1300000000000000001/messages/1400000000000000001/reactions/%F0%9F%91%8D/@me", "DELETE " .. api .. "/channels/1300000000000000001/messages/1400000000000000001/reactions/houston%3A1600000000000000001/@me", "POST " .. api .. "/channels/1300000000000000001/messages/1400000000000000001/threads", "POST " .. api .. "/channels/1300000000000000001/threads", } local denied = { "GET " .. api .. "/guilds/" .. other, "GET " .. api .. "/guilds/" .. other .. "/channels", "GET " .. api .. "/guilds/" .. other .. "/members/search?query=a", "GET " .. api .. "/guilds/" .. other .. "/messages/search?content=hi", "GET " .. api .. "/guilds/" .. guild .. "0/roles", "GET " .. api .. "/guilds/%7B%7Bauth.oauth.guild_id%7D%7D/roles", "GET " .. api .. "/guilds/{{auth.oauth.guild_id}}/roles", "GET " .. api .. "/users/@me/guilds", "DELETE " .. api .. "/users/@me/guilds/" .. guild, "GET " .. api .. "/users/@me", "POST " .. api .. "/users/@me/channels", "GET " .. api .. "/users/@me/channels", "GET " .. api .. "/guilds/" .. guild .. "/members?limit=1000", "PATCH " .. api .. "/guilds/" .. guild .. "/members/80351110224678912", "DELETE " .. api .. "/guilds/" .. guild .. "/members/80351110224678912", "PUT " .. api .. "/guilds/" .. guild .. "/bans/80351110224678912", "GET " .. api .. "/guilds/" .. guild .. "/webhooks", "POST " .. api .. "/channels/1300000000000000001/webhooks", "GET " .. api .. "/channels/1300000000000000001/invites", "PATCH " .. api .. "/channels/1300000000000000001", "DELETE " .. api .. "/channels/1300000000000000001", "DELETE " .. api .. "/channels/1300000000000000001/messages/1/reactions", "PUT " .. api .. "/channels/1300000000000000001/messages/1/reactions/x/80351110224678912", "POST " .. api .. "/channels/1300000000000000001/messages/bulk-delete", "GET " .. api .. "/channels/1300000000000000001/messages/1/reactions/x", "POST https://discord.com/api/oauth2/token", "POST https://discord.com/api/oauth2/token/revoke", "GET https://discord.com/api/oauth2/@me", "GET https://discord.com/api/v9/guilds/" .. guild, "GET https://discord.com/api/guilds/" .. guild, "GET " .. api .. "/channels/1300000000000000001/messages/..%2F..%2Fusers%2F@me", "GET " .. api .. "/guilds/" .. guild .. "/channels/../../users/@me/guilds", "GET https://discord.com.evil.test/api/v10/guilds/" .. guild, "GET https://evil.discord.com/api/v10/guilds/" .. guild, "GET https://discordapp.com/api/v10/guilds/" .. guild, "GET https://canary.discord.com/api/v10/guilds/" .. guild, } local publisher = { client_id = "fixture-client", client_secret = "fixture-secret", bot_token = "fixture-bot-token", } for _, access in { "read", "write" } do local r, err = m.resolve(publisher, {}, nil, "oauth", { data = access }) assert(not err, tostring(err)) if not (m.equal(r.Scopes, { "bot" })) then m.fail("access=%s scopes %s", access, r.Scopes) end r.Context.Auth["oauth"].access_token = "fixture-user-token" r.Context.Auth["oauth"].guild_id = guild do r.Proxy, err = m.renderPaths(r, r.Context) assert(not err, tostring(err)) end m.routes(r, "Bot fixture-bot-token", true, read) m.routes(r, "Bot fixture-bot-token", (access == "write"), writes) m.routes(r, "Bot fixture-bot-token", false, denied) end end -- TestDiscordScopesProvenByGuild do local r = m.raw.auth["oauth"].token_response if not r.scopes_unreported or not ( m.some(r.checks, function(c) return ((c.op == "exists") and (c.path == "/guild/id")) end) ) then m.fail("Discord scopes must be unreported and proven by /guild/id: %s", r) end end end, }read_only.luau
return { scenario = {publisher = {client_id = "fixture-client", client_secret = "fixture-private-secret", bot_token = "fixture-bot-token"}, config = {}, auth_method = "oauth", auth_config = {}, granted_scopes = {"bot"}, facts = {guild_id = "290926798626357999"}}, access = {data = "read"}, configure = function() requests = {} http = {request = function(req) table.insert(requests, req) return fixture.operation({statusCode = 200, headers = {}, body = fixture.reader("[]")}) end} end, run = function(discord) local names = {} for name, fn in discord do assert(type(fn) == "function") table.insert(names, name) end table.sort(names) assert(table.concat(names, ",") == "getChannel,getMember,getMessage,getServer,listArchivedThreads,listChannels," .. "listMessages,listRoles,listThreads,searchMembers,searchMessages", "a read-only connection exports only reads: " .. table.concat(names, ",")) assert(json.encode(discord.listRoles()) == "[]" and #requests == 1) assert(requests[1].url == "https://discord.com/api/v10/guilds/290926798626357999/roles") end, }reads.luau
return { scenario = {publisher = {client_id = "fixture-client", client_secret = "fixture-private-secret", bot_token = "fixture-bot-token"}, config = {}, auth_method = "oauth", auth_config = {}, granted_scopes = {"bot"}, facts = {guild_id = "290926798626357999"}}, access = {data = "read"}, configure = function() requests, responses = {}, {} http = {request = function(req) table.insert(requests, req) assert(#responses > 0, "unexpected request: " .. req.url) local response = table.remove(responses, 1) if type(response) == "string" then response = {body = response} end return fixture.operation({statusCode = response.status or 200, headers = {}, body = fixture.reader(response.body)}) end} API = "https://discord.com/api/v10/" G, C, T, M, U = "290926798626357999", "1300000000000000001", "1300000000000000002", "1400000000000000001", "80351110224678912" CHANNEL = '{"id":"' .. C .. '","type":0,"guild_id":"' .. G .. '","name":"general"}' function sent(index) local req = requests[index or #requests] assert(req.method == "GET" and req.body == nil, "reads send GET without a body") assert(req.headers["User-Agent"][1] == "DiscordBot (https://ok-houston.com, 1.0)", "Discord's bot User-Agent") assert(req.headers.Authorization == nil, "credentials stay in the proxy") return req.url end function rejected(fn, ...) local before = #requests local ok, err = pcall(fn, ...) assert(not ok and #requests == before, "invalid input reached Discord") return tostring(err) end end, run = function(discord) responses = {'{"id":"' .. G .. '","name":"Fixture"}', '{"id":"' .. G .. '","approximate_member_count":3}'} assert(discord.getServer().name == "Fixture" and sent() == API .. "guilds/" .. G) assert(discord.getServer({with_counts = true}).approximate_member_count == 3 and sent() == API .. "guilds/" .. G .. "?with_counts=true") responses = {"[]", '[' .. CHANNEL .. ',{"id":"1300000000000000003","type":4,"guild_id":"' .. G .. '","name":"Info"}]'} assert(json.encode(discord.listChannels()) == "[]" and sent() == API .. "guilds/" .. G .. "/channels") local channels = discord.listChannels() assert(#channels == 2 and channels[2].type == 4) responses = {CHANNEL} local before = #requests assert(discord.getChannel(C).name == "general" and #requests == before + 1 and sent() == API .. "channels/" .. C) responses = {CHANNEL, "[]"} assert(json.encode(discord.listMessages(C)) == "[]") assert(sent(#requests - 1) == API .. "channels/" .. C, "the channel is checked first") assert(sent() == API .. "channels/" .. C .. "/messages?limit=25") local opts = {before = M, limit = 100} responses = {CHANNEL, '[{"id":"1399999999999999999","channel_id":"' .. C .. '","content":"hi"}]'} local messages = discord.listMessages(C, opts) assert(#messages == 1 and messages[1].content == "hi" and opts.limit == 100 and opts.after == nil, "options are not mutated") assert(sent() == API .. "channels/" .. C .. "/messages?before=" .. M .. "&limit=100") responses = {CHANNEL, '{"id":"' .. M .. '","channel_id":"' .. C .. '","content":"hello","reactions":[]}'} assert(discord.getMessage(C, M).content == "hello" and sent() == API .. "channels/" .. C .. "/messages/" .. M) local thread = '{"id":"' .. T .. '","type":11,"guild_id":"' .. G .. '","parent_id":"' .. C .. '"}' responses = {'{"threads":[],"members":[]}', '{"threads":[' .. thread .. '],"members":[]}'} local active = discord.listThreads() assert(json.encode(active.threads) == "[]" and sent() == API .. "guilds/" .. G .. "/threads/active") assert(discord.listThreads().threads[1].parent_id == C) responses = {thread, '[]'} assert(json.encode(discord.listMessages(T, {after = M, limit = 1})) == "[]", "threads are channels") assert(sent() == API .. "channels/" .. T .. "/messages?after=" .. M .. "&limit=1") responses = {CHANNEL, '{"threads":[],"members":[],"has_more":false}', CHANNEL, '{"threads":[' .. thread .. '],"members":[],"has_more":true}'} assert(discord.listArchivedThreads(C).has_more == false and sent() == API .. "channels/" .. C .. "/threads/archived/public?limit=25") assert(discord.listArchivedThreads(C, {before = "2026-01-31T12:00:00.000000+00:00", limit = 2}).has_more) assert(sent() == API .. "channels/" .. C .. "/threads/archived/public?before=2026-01-31T12%3A00%3A00.000000%2B00%3A00&limit=2") responses = {'{"total_results":0,"messages":[],"doing_deep_historical_index":false}', '{"total_results":1,"messages":[[{"id":"' .. M .. '","content":"deploy done"}]],"doing_deep_historical_index":false}'} assert(discord.searchMessages("deploy").total_results == 0 and sent() == API .. "guilds/" .. G .. "/messages/search?content=deploy") local found = discord.searchMessages("", {channel_id = {C, T}, author_id = U, author_type = {"-bot"}, has = {"link"}, sort_by = "relevance", limit = 5, offset = 5, pinned = false}) assert(found.messages[1][1].content == "deploy done") assert(sent() == API .. "guilds/" .. G .. "/messages/search?author_id=" .. U .. "&author_type=-bot&channel_id=" .. C .. "&channel_id=" .. T .. "&has=link&limit=5&offset=5&pinned=false&sort_by=relevance") responses = {"[]", '[{"user":{"id":"' .. U .. '","username":"ana"},"nick":"Ana","roles":[]}]', '{"user":{"id":"' .. U .. '"},"roles":["1"]}'} assert(json.encode(discord.searchMembers("zz")) == "[]" and sent() == API .. "guilds/" .. G .. "/members/search?limit=25&query=zz") assert(discord.searchMembers("an a", {limit = 1000})[1].nick == "Ana") assert(sent() == API .. "guilds/" .. G .. "/members/search?limit=1000&query=an%20a") assert(discord.getMember(U).user.id == U and sent() == API .. "guilds/" .. G .. "/members/" .. U) responses = {"[]", '[{"id":"' .. G .. '","name":"@everyone"}]'} assert(json.encode(discord.listRoles()) == "[]" and sent() == API .. "guilds/" .. G .. "/roles") assert(discord.listRoles()[1].name == "@everyone") assert(string.find(rejected(discord.getChannel, 1300000000000000001), "must be a Discord ID string", 1, true)) rejected(discord.getChannel, "../users/@me") rejected(discord.getChannel, "0123") rejected(discord.getChannel, "18446744073709551616") rejected(discord.getMember, "@me") rejected(discord.getMessage, C, "1.5") assert(string.find(rejected(discord.listMessages, C, {before = M, after = M}), "only one of before", 1, true)) rejected(discord.listMessages, C, {limit = 0}) rejected(discord.listMessages, C, {limit = 101}) rejected(discord.listMessages, C, {limit = 0 / 0}) assert(string.find(rejected(discord.listMessages, C, {cursor = "x"}), "unknown option cursor", 1, true)) rejected(discord.listArchivedThreads, C, {limit = 1}) rejected(discord.listArchivedThreads, C, {before = "yesterday"}) rejected(discord.getServer, {with_counts = "yes"}) rejected(discord.searchMessages, string.rep("x", 1025)) rejected(discord.searchMessages, "x", {limit = 26}) rejected(discord.searchMessages, "x", {offset = 9976}) rejected(discord.searchMessages, "x", {channel_id = {}}) rejected(discord.searchMessages, "x", {has = {"links"}}) rejected(discord.searchMessages, "x", {guild_id = "1"}) rejected(discord.searchMembers, "") rejected(discord.searchMembers, string.rep("x", 101)) rejected(discord.searchMembers, "ana", {limit = 1001}) end, }unbound.luau
return { scenario = {publisher = {client_id = "fixture-client", client_secret = "fixture-private-secret", bot_token = "fixture-bot-token"}, config = {}, auth_method = "oauth", auth_config = {}, granted_scopes = {"bot"}}, access = {data = "write"}, configure = function() http = {request = function(req) error("unexpected request: " .. req.url) end} end, run = function(discord) -- Without the server fact from the install, nothing can be addressed. local C, M = "1300000000000000001", "1400000000000000001" for _, call in { function() discord.getServer() end, function() discord.listChannels() end, function() discord.listRoles() end, function() discord.searchMessages("x") end, function() discord.getMember("80351110224678912") end, function() discord.getChannel(C) end, function() discord.listMessages(C) end, function() discord.postMessage(C, "Hi") end, function() discord.addReaction(C, M, "👍") end, function() discord.createThread(C, "Plan") end, } do local ok, err = pcall(call) assert(not ok and string.find(tostring(err), "not bound to a Discord server", 1, true), tostring(err)) end end, }writes.luau
return { scenario = {publisher = {client_id = "fixture-client", client_secret = "fixture-private-secret", bot_token = "fixture-bot-token"}, config = {}, auth_method = "oauth", auth_config = {}, granted_scopes = {"bot"}, facts = {guild_id = "290926798626357999"}}, access = {data = "write"}, configure = function() requests, responses = {}, {} http = {request = function(req) table.insert(requests, req) assert(#responses > 0, "unexpected request: " .. req.url) local response = table.remove(responses, 1) if type(response) == "string" then response = {body = response} end return fixture.operation({statusCode = response.status or 200, headers = {}, body = fixture.reader(response.body or "")}) end} API = "https://discord.com/api/v10/" G, C, A, F, M, U, R = "290926798626357999", "1300000000000000001", "1300000000000000005", "1300000000000000006", "1400000000000000001", "80351110224678912", "1500000000000000001" CHANNEL = '{"id":"' .. C .. '","type":0,"guild_id":"' .. G .. '","name":"general"}' POSTED = '{"id":"1400000000000000009","channel_id":"' .. C .. '","content":"Hi"}' function sent(index, method, path) local req = requests[index] assert(requests[index - 1].method == "GET" and requests[index - 1].url == API .. "channels/" .. string.match(path, "^channels/(%d+)"), "the channel is checked before " .. method) assert(req.method == method and req.url == API .. path, "unexpected " .. req.method .. " " .. req.url) assert(req.headers["User-Agent"][1] == "DiscordBot (https://ok-houston.com, 1.0)" and req.headers.Authorization == nil) if req.body == nil then return nil end assert(req.headers["Content-Type"][1] == "application/json") return json.decode(req.body) end function silent(body) assert(json.encode(body.allowed_mentions.parse) == "[]", "mentions notify nobody by default") end function rejected(fn, ...) local before = #requests local ok, err = pcall(fn, ...) assert(not ok and #requests == before, "invalid input reached Discord") return tostring(err) end end, run = function(discord) for _, name in {"postMessage", "reply", "editMessage", "deleteMessage", "addReaction", "removeReaction", "createThread"} do assert(type(discord[name]) == "function", name .. " is exported with write access") end responses = {CHANNEL, POSTED} assert(discord.postMessage(C, "Hi @everyone").id == "1400000000000000009") local body = sent(2, "POST", "channels/" .. C .. "/messages") assert(body.content == "Hi @everyone" and body.message_reference == nil and body.users == nil) silent(body) assert(body.allowed_mentions.users == nil and body.allowed_mentions.roles == nil) local opts = {allowed_mentions = {users = {U}, roles = R, replied_user = true}, embeds = {{title = "Q3", url = "https://example.com"}}, flags = 4096, nonce = "run-42", enforce_nonce = true} responses = {CHANNEL, POSTED} discord.reply(C, M, "<@" .. U .. "> done", opts) body = sent(4, "POST", "channels/" .. C .. "/messages") assert(body.message_reference.message_id == M and body.content == "<@" .. U .. "> done") silent(body) assert(body.allowed_mentions.users[1] == U and body.allowed_mentions.roles[1] == R and body.allowed_mentions.replied_user == true) assert(body.embeds[1].title == "Q3" and body.flags == 4096 and body.nonce == "run-42" and body.enforce_nonce == true) assert(opts.content == nil and opts.message_reference == nil and opts.allowed_mentions.parse == nil, "options are not mutated") responses = {CHANNEL, POSTED} discord.editMessage(C, M, "Edited", {flags = 4}) body = sent(6, "PATCH", "channels/" .. C .. "/messages/" .. M) assert(body.content == "Edited" and body.flags == 4) silent(body) responses = {CHANNEL, {status = 204}} assert(discord.deleteMessage(C, M) == true) assert(sent(8, "DELETE", "channels/" .. C .. "/messages/" .. M) == nil) responses = {CHANNEL, {status = 204}, CHANNEL, {status = 204}, CHANNEL, {status = 204}, CHANNEL, {status = 204}} assert(discord.addReaction(C, M, "👍") == true) sent(10, "PUT", "channels/" .. C .. "/messages/" .. M .. "/reactions/%F0%9F%91%8D/@me") discord.addReaction(C, M, "<a:party_blob:1600000000000000001>") sent(12, "PUT", "channels/" .. C .. "/messages/" .. M .. "/reactions/party_blob%3A1600000000000000001/@me") discord.removeReaction(C, M, "houston:1600000000000000002") sent(14, "DELETE", "channels/" .. C .. "/messages/" .. M .. "/reactions/houston%3A1600000000000000002/@me") discord.removeReaction(C, M, "1️⃣") sent(16, "DELETE", "channels/" .. C .. "/messages/" .. M .. "/reactions/1%EF%B8%8F%E2%83%A3/@me") local thread = '{"id":"1300000000000000007","type":11,"guild_id":"' .. G .. '","parent_id":"' .. C .. '","name":"Plan"}' responses = {CHANNEL, {status = 201, body = thread}} assert(discord.createThread(C, "Plan").id == "1300000000000000007") body = sent(18, "POST", "channels/" .. C .. "/threads") assert(body.name == "Plan" and body.type == 11, "a thread without a message is public") responses = {'{"id":"' .. A .. '","type":5,"guild_id":"' .. G .. '"}', {status = 201, body = thread}} discord.createThread(A, "News", {auto_archive_duration = 1440}) body = sent(20, "POST", "channels/" .. A .. "/threads") assert(body.type == 10 and body.auto_archive_duration == 1440, "announcement channels get announcement threads") responses = {CHANNEL, {status = 201, body = thread}} discord.createThread(C, "Follow-up", {message = M, rate_limit_per_user = 30}) body = sent(22, "POST", "channels/" .. C .. "/messages/" .. M .. "/threads") assert(body.name == "Follow-up" and body.rate_limit_per_user == 30 and body.type == nil and body.message == nil) responses = {'{"id":"' .. F .. '","type":15,"guild_id":"' .. G .. '"}'} local ok, err = pcall(discord.createThread, F, "Post") assert(not ok and string.find(tostring(err), "text or announcement channel", 1, true) and #requests == 23, "forum posts are not created") rejected(discord.postMessage, C, "") assert(string.find(rejected(discord.postMessage, C, string.rep("é", 2001)), "at most 2000 characters", 1, true)) responses = {CHANNEL, POSTED} discord.postMessage(C, string.rep("é", 2000), {flags = 4100}) assert(utf8.len(sent(25, "POST", "channels/" .. C .. "/messages").content) == 2000, "Discord counts characters, not bytes") assert(string.find(rejected(discord.postMessage, C, "Hi", {allowed_mentions = {parse = {"everyone"}}}), "use users, roles or replied_user", 1, true)) rejected(discord.postMessage, C, "Hi", {allowed_mentions = {users = {"@everyone"}}}) rejected(discord.postMessage, C, "Hi", {flags = 8}) rejected(discord.postMessage, C, "Hi", {nonce = string.rep("x", 26)}) rejected(discord.postMessage, C, "Hi", {embeds = {{}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}}}) rejected(discord.postMessage, C, "Hi", {tts = true}) rejected(discord.postMessage, C, "Hi", {message_reference = {message_id = M}}) rejected(discord.postMessage, 1300000000000000001, "Hi") rejected(discord.reply, C, "not-an-id", "Hi") rejected(discord.editMessage, C, M, "Edited", {flags = 4096}) rejected(discord.deleteMessage, C, "") assert(string.find(rejected(discord.addReaction, C, M, "thumbsup"), "Unicode emoji", 1, true)) rejected(discord.addReaction, C, M, ":thumbsup:") rejected(discord.addReaction, C, M, "a/b") rejected(discord.addReaction, C, M, "%F0%9F%91%8D") rejected(discord.addReaction, C, M, "") rejected(discord.addReaction, C, M, "..") rejected(discord.removeReaction, C, M, "name:../1") rejected(discord.createThread, C, "") rejected(discord.createThread, C, string.rep("x", 101)) rejected(discord.createThread, C, "Plan", {auto_archive_duration = 30}) rejected(discord.createThread, C, "Plan", {type = 12}) rejected(discord.createThread, C, "Plan", {message = "x"}) end, }