Skip to content

createDiscordBotClient

createDiscordBotClient(opts): object

Defined in: bot/bot.ts:175

Bot-authenticated Discord REST resources (Authorization: Bot <token>), for provisioning a server: channels, roles, and per-channel webhooks. Webhook posting stays on createDiscordClient, which needs no token.

http-client only knows Bearer/Basic/api-key, so the Bot scheme is sent as an api-key header carrying the whole Bot <token> value.

baseUrl is a test seam: the bot token is sent to whatever host it names, so never derive it from untrusted input.

DiscordBotClientOptions

object

application: object

get: () => Promise<DiscordApplication>

GET /applications/@me — the bot’s own application: description, tags, install settings, URLs.

Promise<DiscordApplication>

modify: (body) => Promise<DiscordApplication>

PATCH /applications/@me — only what is in the body changes.

ModifyApplicationInput

Promise<DiscordApplication>

channels: object

addReaction: (channelId, messageId, emoji) => Promise<void>

PUT /channels/:id/messages/:id/reactions/:emoji/@me — the bot reacts; a reaction it already has is a no-op. emoji is a Unicode emoji or name:id for a custom one.

string

string

string

Promise<void>

createInvite: (channelId, body) => Promise<DiscordInvite>

POST /channels/:id/invites — a join link for the server, e.g. to hand over a newly created one.

string

CreateInviteInput = {}

Promise<DiscordInvite>

createMessage: (channelId, body) => Promise<DiscordMessage>

POST /channels/:id/messages as the bot. Mentions are off unless allowed_mentions asks for them.

string

CreateMessageInput

Promise<DiscordMessage>

createWebhook: (channelId, body) => Promise<DiscordChannelWebhook>

string

string

Promise<DiscordChannelWebhook>

deleteMessage: (channelId, messageId) => Promise<void>

string

string

Promise<void>

editMessage: (channelId, messageId, body) => Promise<DiscordMessage>

PATCH /channels/:id/messages/:id — a message this bot posted. Mentions are off unless allowed_mentions asks for them.

string

string

EditMessageInput

Promise<DiscordMessage>

message: (channelId, messageId) => Promise<DiscordChannelMessage>

GET /channels/:id/messages/:id — one message, e.g. the first message of a forum post (its id is the post’s).

string

string

Promise<DiscordChannelMessage>

messages: (channelId, limit, before?) => Promise<DiscordChannelMessage[]>

GET /channels/:id/messages — the newest messages first, to read a post back. before is a message id: read the page older than it.

string

number = 50

string

Promise<DiscordChannelMessage[]>

modify: (channelId, body) => Promise<DiscordChannel>

string

ModifyChannelInput

Promise<DiscordChannel>

pin: (channelId, messageId) => Promise<void>

PUT /channels/:id/pins/:id — pins a message; one already pinned is a no-op.

string

string

Promise<void>

startThread: (channelId, messageId, body) => Promise<DiscordThread>

POST /channels/:id/messages/:id/threads — starts a public thread on a message of a text channel, as the bot. Not idempotent (a message has one thread; a second try is a 400): read the message’s thread first. A 403 says the bot needs Create Public Threads (and Send Messages in Threads to post in it).

string

string

StartThreadInput

Promise<DiscordThread>

webhooks: (channelId) => Promise<DiscordChannelWebhook[]>

string

Promise<DiscordChannelWebhook[]>

guilds: object

addMemberRole: (guildId, userId, roleId) => Promise<void>

PUT /guilds/:id/members/:id/roles/:id — gives the member the role; giving one they have is a no-op.

string

string

string

Promise<void>

channels: (guildId) => Promise<DiscordChannel[]>

string

Promise<DiscordChannel[]>

create: (body) => Promise<DiscordGuild>

POST /guilds — a new server the bot owns. Not idempotent: look one up by name (users.guilds) before retrying.

CreateGuildInput

Promise<DiscordGuild>

createChannel: (guildId, body) => Promise<DiscordChannel>

string

CreateChannelInput

Promise<DiscordChannel>

createEmoji: (guildId, body) => Promise<DiscordEmoji>

POST /guilds/:id/emojis — makes a custom emoji from image, a data: URI (at most 256 KiB: JPEG, PNG, GIF, WebP or AVIF). Needs Create Guild Expressions. Discord does not apply the usual rate limit headers to it.

string

CreateEmojiInput

Promise<DiscordEmoji>

createRole: (guildId, body) => Promise<DiscordRole>

string

CreateRoleInput

Promise<DiscordRole>

delete: (guildId) => Promise<void>

DELETE /guilds/:id — only the owner may; a 404 counts as done.

string

Promise<void>

deleteEmoji: (guildId, emojiId) => Promise<void>

DELETE /guilds/:id/emojis/:id — deletes a custom emoji, and so every reaction made with it. The bot may delete an emoji it made with Create Guild Expressions; one made by someone else needs Manage Guild Expressions.

string

string

Promise<void>

emojis: (guildId) => Promise<DiscordEmoji[]>

GET /guilds/:id/emojis — custom emoji, for welcome screen and onboarding ids.

string

Promise<DiscordEmoji[]>

get: (guildId) => Promise<DiscordGuild>

string

Promise<DiscordGuild>

member: (guildId, userId) => Promise<DiscordGuildMember>

GET /guilds/:id/members/:id — one member and the roles they hold. A 404 means either they are not in the server or the guild id is unknown; read the error body to tell them apart.

string

string

Promise<DiscordGuildMember>

members: (guildId, opts) => Promise<DiscordGuildMember[]>

GET /guilds/:id/members — one page. Needs the privileged Server Members Intent, switched on in the developer portal; without it Discord answers 403.

string

ListMembersInput = {}

Promise<DiscordGuildMember[]>

membersWithRole: (guildId, roleId) => Promise<DiscordGuildMember[]>

Every member holding the role, read page by page; needs the same intent as members.

string

string

Promise<DiscordGuildMember[]>

modify: (guildId, body) => Promise<DiscordGuild>

PATCH /guilds/:id — verification, notification defaults, content filter, system channels.

string

ModifyGuildInput

Promise<DiscordGuild>

modifyOnboarding: (guildId, body) => Promise<DiscordOnboarding>

PUT replaces the whole onboarding config, so send every prompt you want to keep. Discord has no conditional write: two callers that read, edit and PUT at once, the later one wins.

string

Omit<DiscordOnboarding, "guild_id">

Promise<DiscordOnboarding>

modifyRole: (guildId, roleId, body) => Promise<DiscordRole>

string

string

ModifyRoleInput

Promise<DiscordRole>

modifyWelcomeScreen: (guildId, body) => Promise<DiscordWelcomeScreen>

Needs the community features on.

string

ModifyWelcomeScreenInput

Promise<DiscordWelcomeScreen>

onboarding: (guildId) => Promise<DiscordOnboarding>

string

Promise<DiscordOnboarding>

removeMemberRole: (guildId, userId, roleId) => Promise<void>

DELETE /guilds/:id/members/:id/roles/:id — takes the role away; taking one they lack is a no-op.

string

string

string

Promise<void>

renameEmoji: (guildId, emojiId, name) => Promise<DiscordEmoji>

PATCH /guilds/:id/emojis/:id — renames a custom emoji (the image cannot change). The bot may change an emoji it made with Create Guild Expressions; one made by someone else needs Manage Guild Expressions.

string

string

string

Promise<DiscordEmoji>

roles: (guildId) => Promise<DiscordRole[]>

string

Promise<DiscordRole[]>

welcomeScreen: (guildId) => Promise<DiscordWelcomeScreen>

string

Promise<DiscordWelcomeScreen>

threads: object

active: (guildId) => Promise<DiscordThread[]>

GET /guilds/:id/threads/active — every active thread in the server, across channels.

string

Promise<DiscordThread[]>

archived: (channelId, opts) => Promise<DiscordArchivedThreads>

GET /channels/:id/threads/archived/public — one page of a channel’s archived threads, newest archived first.

string

ListArchivedThreadsInput = {}

Promise<DiscordArchivedThreads>

createForumPost: (channelId, body) => Promise<DiscordForumPost>

POST /channels/:id/threads in a forum channel — a new post with its first message. Not idempotent: look the post up (inChannel) before retrying. Mentions in the first message are off unless asked for.

string

CreateForumPostInput

Promise<DiscordForumPost>

delete: (threadId) => Promise<void>

DELETE /channels/:id on a thread — deletes the thread and its messages. A 404 counts as done, as when a retry follows a lost response.

string

Promise<void>

inChannel: (guildId, channelId) => Promise<DiscordThread[]>

Every post in a forum channel, active and archived: Discord hides a post that has been quiet for a while, so a lookup that read only the active ones would miss it and make it again. Reads every page; to look for one post, read pages and stop at it.

string

string

Promise<DiscordThread[]>

messages: (threadId) => Promise<DiscordChannelMessage[]>

Every message of a thread, oldest first, read in pages of 100 (at most MAX_THREAD_PAGES pages).

string

Promise<DiscordChannelMessage[]>

modify: (threadId, body) => Promise<DiscordThread>

PATCH /channels/:id on a thread — its title, tags, archived or locked state. Writing to an archived post unarchives it.

string

ModifyThreadInput

Promise<DiscordThread>

pages: (guildId, channelId) => AsyncGenerator<DiscordThread[]>

The posts of a forum channel in pages, newest first: the active ones (one call, for the whole server), then each archived page (100 a call, newest archived first). A caller that stops reading stops the calls, so a lookup that finds its post near the top costs a call or two and not the whole archive.

string

string

AsyncGenerator<DiscordThread[]>

post: (threadId, body) => Promise<DiscordMessage>

Posts a message in a thread (the thread’s id is the channel id its messages go to), as the bot. Mentions are off unless asked for. A 403 says the bot needs Send Messages in Threads.

string

CreateMessageInput

Promise<DiscordMessage>

users: object

get: (userId) => Promise<DiscordUser>

GET /users/:id — a user’s name, for reports that would otherwise show a bare id.

string

Promise<DiscordUser>

guilds: (opts) => Promise<DiscordUserGuild[]>

GET /users/@me/guilds — one page of the servers the bot is in, each with whether it owns it. This is how a retry finds a server guilds.create already made, since that call is not idempotent.

ListUserGuildsInput = {}

Promise<DiscordUserGuild[]>

me: () => Promise<DiscordUser>

GET /users/@me — the bot’s own user; a cheap token check.

Promise<DiscordUser>

webhooks: object

delete: (webhookId) => Promise<void>

A 404 counts as done: the webhook is already gone, as when a retry follows a lost response.

string

Promise<void>

modify: (webhookId, body) => Promise<DiscordChannelWebhook>

PATCH /webhooks/:id — name and avatar of a webhook this bot manages.

string

ModifyWebhookInput

Promise<DiscordChannelWebhook>