Skip to content

DiscordNotifications

Defined in: plugins/holocron-plugin-discord/src/capabilities/notifications.ts:273

The Discord implementation of the notifications capability: sends messages through webhooks and provisions the server’s channels, roles and webhooks with the bot.

  • Notifications

new DiscordNotifications(client, opts, defaultWebhookUrl, bot?, oauth?, fetchImage?): DiscordNotifications

Defined in: plugins/holocron-plugin-discord/src/capabilities/notifications.ts:279

{ deleteMessage: (id, token, messageId) => Promise<void>; editMessage: (id, token, messageId, body) => Promise<void>; execute: (id, token, content) => Promise<void>; executeAndWait: (id, token, content, options?) => Promise<{ channel_id: string; id: string; }>; get: (id, token) => Promise<DiscordWebhookInfo>; }

(id, token, messageId) => Promise<void>

(id, token, messageId, body) => Promise<void>

(id, token, content) => Promise<void>

(id, token, content, options?) => Promise<{ channel_id: string; id: string; }>

(id, token) => Promise<DiscordWebhookInfo>

DiscordNotificationsOptions

() => string

Memoized thunk — resolves the default webhook URL on the first send().

() => object

Memoized thunk — resolves the bot token on first provisioning call, never on send().

(redirectUri) => Promise<{ authorizeUrl: (input) => string; connections: (accessToken) => Promise<DiscordConnection[]>; exchangeCode: (code) => Promise<DiscordOAuthToken>; refresh: (refreshToken) => Promise<DiscordOAuthToken>; revoke: (token) => Promise<void>; user: (accessToken) => Promise<DiscordOAuthUser>; }>

Builds the OAuth client for one redirect URI; needs the application’s client secret.

(url) => Promise<Uint8Array<ArrayBufferLike>>

Reads the bytes at a public URL (an emoji on Discord’s CDN). Tests pass their own.

DiscordNotifications

readonly key: "notifications"

Defined in: plugins/holocron-plugin-discord/src/capabilities/notifications.ts:275

The capability this class provides, always "notifications".

Notifications.key


readonly providerName: "discord" = "discord"

Defined in: plugins/holocron-plugin-discord/src/capabilities/notifications.ts:277

The provider name, "discord".

Notifications.providerName

get layout(): NotificationsLayout | undefined

Defined in: plugins/holocron-plugin-discord/src/capabilities/notifications.ts:326

The server layout the owner declared for this provider, if any. Read by holocron setup notifications; the provider just carries it from its options.

NotificationsLayout | undefined

Notifications.layout

addRoleMember(roleName, memberId): Promise<void>

Defined in: plugins/holocron-plugin-discord/src/capabilities/notifications.ts:2860

Give a member the role; one who has it already is left alone.

string

string

Promise<void>

Notifications.addRoleMember


checkDelivery(input): Promise<NotificationsDelivery>

Defined in: plugins/holocron-plugin-discord/src/capabilities/notifications.ts:2653

Proves a channel’s webhook delivers: posts text through it, reads the post back from the channel and removes it again, unless keep is true, in which case the post is left in the channel (and the result has kept instead of removed). Never throws for a failed step; the result says which one failed. Posts a visible message, so callers choose the channel with care.

string

string

boolean

string

string

Promise<NotificationsDelivery>

Notifications.checkDelivery


checkEmoji(input): Promise<EmojiCheck>

Defined in: plugins/holocron-plugin-discord/src/capabilities/notifications.ts:2529

Whether the server emoji with this name shows image. Discord returns no hash of an emoji’s picture, so the copy on its CDN (cdn.discordapp.com/emojis/<id>.png, the lossless size of the upload) is read and both pictures are decoded and compared pixel by pixel with a small tolerance, which also absorbs Discord re-encoding the upload. Read-only. Anything that stops the comparison (the layout’s image is not a PNG, the CDN does not answer, a picture that cannot be decoded) is unknown with the reason, never different.

string

string

Promise<EmojiCheck>

Notifications.checkEmoji


createServer(input): Promise<{ id: string; name: string; }>

Defined in: plugins/holocron-plugin-discord/src/capabilities/notifications.ts:2756

Creates the server the layout describes, empty, owned by the provider’s own bot, and makes it the server every other call in this run works on. Refuses when the config already names a server unless force.

boolean

string

Promise<{ id: string; name: string; }>

Notifications.createServer


dedupeDiscussion(channel, key, opts?): Promise<number>

Defined in: plugins/holocron-plugin-discord/src/capabilities/notifications.ts:1324

Keeps the oldest post for key and deletes the others; returns how many it deleted. refresh reads the forum again first.

string

string

boolean

Promise<number>

Notifications.dedupeDiscussion


deleteDiscussion(channel, key): Promise<boolean>

Defined in: plugins/holocron-plugin-discord/src/capabilities/notifications.ts:1339

Deletes a discussion post unless a person has written in it; returns whether it did.

string

string

Promise<boolean>

Notifications.deleteDiscussion


deleteWebhook(id): Promise<void>

Defined in: plugins/holocron-plugin-discord/src/capabilities/notifications.ts:2649

Deletes a webhook by id (a 404 counts as done); used to undo one this run created.

string

Promise<void>

Notifications.deleteWebhook


duplicateDiscussions(channel): Promise<DuplicateDiscussion[]>

Defined in: plugins/holocron-plugin-discord/src/capabilities/notifications.ts:1329

The keys with more than one post in a forum, with how many are beyond the oldest. Deletes nothing.

string

Promise<DuplicateDiscussion[]>

Notifications.duplicateDiscussions


ensureApplication(app): Promise<{ todo?: string[]; updated: string[]; }>

Defined in: plugins/holocron-plugin-discord/src/capabilities/notifications.ts:1814

Bring the bot’s application settings in line with the layout, changing only what differs. Returns what it changed.

NotificationsApplicationLayout

Promise<{ todo?: string[]; updated: string[]; }>

Notifications.ensureApplication


ensureCategory(name, opts?): Promise<EnsuredResource>

Defined in: plugins/holocron-plugin-discord/src/capabilities/notifications.ts:2216

Provisioning. All optional, all idempotent (look up by name, create only what is missing), and all need provider credentials beyond the posting URL — so a provider that only posts simply omits them.

string

NotificationsAccess

Promise<EnsuredResource>

Notifications.ensureCategory


ensureChannel(input): Promise<EnsuredResource>

Defined in: plugins/holocron-plugin-discord/src/capabilities/notifications.ts:2376

Finds the text or announcement channel with this name (under the category, when given), or creates it; reports whether it was created. With kind: "forum" it is a forum channel with the layout’s tags. Discord cannot turn one kind into the other and this never deletes, so a channel of the other kind with the name stops the run with the fix.

NotificationsAccess

number

string

NotificationsReaction

"text" | "forum"

string

NotificationsForumTag[]

string

Promise<EnsuredResource>

Notifications.ensureChannel


ensureDiscussion(input): Promise<EnsuredDiscussion>

Defined in: plugins/holocron-plugin-discord/src/capabilities/notifications.ts:1299

Finds the post for a document in a forum channel, or makes it. See DiscordDiscussions.

EnsureDiscussionInput

Promise<EnsuredDiscussion>

Notifications.ensureDiscussion


ensureEmoji(input): Promise<EnsuredResource>

Defined in: plugins/holocron-plugin-discord/src/capabilities/notifications.ts:2473

Finds the server emoji with this name or makes it from image (a data: URI). One that exists is left exactly as it is (not replaced, renamed or deleted, and the image is not compared with it) unless replace is set, which setup does only for an emoji DiscordNotifications.checkEmoji found different. Making one needs Create Guild Expressions; without it the error says so and carries the link that invites the bot again asking for it.

With replace, Discord has no way to change an emoji’s image, so a new one is made. Names are unique per server, so the new emoji is made first under a temporary name (<name>_new), the old one deleted, and the new one renamed: a failure before the delete leaves the old emoji as it was (the new one is removed again), and one after it leaves the new emoji under the temporary name, which the error gives. The new emoji has a new id, so the caller must read ids again (forum default reactions and starter reactions are looked up by name each time, so setup’s channel step does). Reactions made with the old emoji disappear with it. Deleting an emoji the bot did not make needs Manage Guild Expressions; a 403 says so with the invite link.

string

string

boolean

Promise<EnsuredResource>

Notifications.ensureEmoji


ensureEveryone(everyone): Promise<{ updated: string[]; }>

Defined in: plugins/holocron-plugin-discord/src/capabilities/notifications.ts:1792

Grant or take away the named permissions from everyone, changing only what differs. Returns what it changed.

NotificationsEveryoneLayout

Promise<{ updated: string[]; }>

Notifications.ensureEveryone


ensureOnboarding(onboarding): Promise<{ updated: string[]; }>

Defined in: plugins/holocron-plugin-discord/src/capabilities/notifications.ts:1711

Bring onboarding in line with the layout, changing only what differs. Returns what it changed.

NotificationsOnboardingLayout

Promise<{ updated: string[]; }>

Notifications.ensureOnboarding


ensurePinned(pinned): Promise<{ updated: string[]; }>

Defined in: plugins/holocron-plugin-discord/src/capabilities/notifications.ts:1498

Post and pin the layout’s messages, replacing any that differ. Returns the channels it changed.

NotificationsPinnedLayout[]

Promise<{ updated: string[]; }>

Notifications.ensurePinned


ensureRole(input): Promise<EnsuredResource>

Defined in: plugins/holocron-plugin-discord/src/capabilities/notifications.ts:2869

Finds the role with this name, or creates it with the given mentionable, color, hoist and permissions settings; reports whether it was created.

string

boolean

boolean

string

string[]

Promise<EnsuredResource>

Notifications.ensureRole


ensureServer(settings): Promise<{ updated: string[]; }>

Defined in: plugins/holocron-plugin-discord/src/capabilities/notifications.ts:888

Bring the server’s own settings in line with the layout, changing only what differs. Returns the names of what it changed, empty when the server already matched.

NotificationsServerLayout

Promise<{ updated: string[]; }>

Notifications.ensureServer


ensureWebhook(input): Promise<EnsureWebhookResult>

Defined in: plugins/holocron-plugin-discord/src/capabilities/notifications.ts:2611

Finds the webhook with this name on the channel, or creates it; the optional avatar is the picture it posts with.

string

string

string

string

Promise<EnsureWebhookResult>

Notifications.ensureWebhook


ensureWelcome(welcome): Promise<{ updated: string[]; }>

Defined in: plugins/holocron-plugin-discord/src/capabilities/notifications.ts:1612

Bring the welcome screen in line with the layout, changing only what differs. Returns what it changed.

NotificationsWelcomeLayout

Promise<{ updated: string[]; }>

Notifications.ensureWelcome


findMessage(channel, marker): Promise<NotificationsPostedMessage | undefined>

Defined in: plugins/holocron-plugin-discord/src/capabilities/notifications.ts:380

The newest message whose text contains marker among the last 1,000 of the named channel (read a page of 100 at a time), with the thread started on it. Read with the bot (a webhook cannot read), so it needs the bot token and the server id.

string

string

Promise<NotificationsPostedMessage | undefined>

Notifications.findMessage


hasMember(memberId): Promise<boolean>

Defined in: plugins/holocron-plugin-discord/src/capabilities/notifications.ts:2801

Whether a person is in the server.

string

Promise<boolean>

Notifications.hasMember


hideLinkPreviews(input): Promise<HideLinkPreviewsResult>

Defined in: plugins/holocron-plugin-discord/src/capabilities/notifications.ts:1369

Hides the link-preview cards under the newest messages of a text channel by setting Suppress Embeds on each one (see previewAction for which). Who may edit a message depends on who wrote it: a webhook’s message is edited through that webhook (Discord refuses a bot any edit of another author’s message, 50005, whatever its permissions), which works only for a webhook this application made (the channel’s webhooks are read once; one made by another app is counted in foreign and left alone), and a message written by a person or by the bot itself is edited by the bot, which needs Manage Messages for a person’s (a 403 of that kind ends the channel’s run with the permission named and an invite link that carries it; any other 403 is reported in Discord’s own words). A 429 ends the run with the count left, a message that is gone (404 through its webhook) is counted in gone. Edits go one at a time through the client, which waits out a short rate limit itself. Reads pages of at most 100, never more than the limit.

HideLinkPreviewsInput

Promise<HideLinkPreviewsResult>

Notifications.hideLinkPreviews


holdsPermission(permission): Promise<boolean>

Defined in: plugins/holocron-plugin-discord/src/capabilities/notifications.ts:1082

Whether the bot holds the permission right now (the owner holds every one). Used to prove an elevation was taken back.

string

Promise<boolean>

Notifications.holdsPermission


inspect(layout): Promise<ServerInspection>

Defined in: plugins/holocron-plugin-discord/src/capabilities/notifications.ts:452

Read-only: what is on the server, for the parts of layout we will compare. Webhooks are listed only for channels the layout gives one (one request each), so the cost scales with the layout, not with the server.

NotificationsLayout

Promise<ServerInspection>

Notifications.inspect


inviteLink(channelName): Promise<string>

Defined in: plugins/holocron-plugin-discord/src/capabilities/notifications.ts:2789

A single-use link, valid for a day, that lets one person join the server through the named channel.

string

Promise<string>

Notifications.inviteLink


listDiscussions(channel): Promise<DiscussionPost[]>

Defined in: plugins/holocron-plugin-discord/src/capabilities/notifications.ts:1334

Every discussion post of a forum, read afresh.

string

Promise<DiscussionPost[]>

Notifications.listDiscussions


postDiscussionMessage(channel, key, content, opts?): Promise<void>

Defined in: plugins/holocron-plugin-discord/src/capabilities/notifications.ts:1314

Appends a message to a document’s post, reopening and closing it again if it was closed.

string

string

string

boolean

Promise<void>

Notifications.postDiscussionMessage


postMessage(channel, content): Promise<void>

Defined in: plugins/holocron-plugin-discord/src/capabilities/notifications.ts:1347

Posts content (up to 2000 characters) in a text channel as the bot, without letting it mention anyone. A #name that is one of the server’s channels is linked.

string

string

Promise<void>

Notifications.postMessage


postToThread(threadId, lines): Promise<void>

Defined in: plugins/holocron-plugin-discord/src/capabilities/notifications.ts:415

Posts lines in a thread as the bot, packed into messages under 2,000 characters without splitting a line. Embeds are suppressed: a thread of links (a release’s packages, each linking to npm) would otherwise unfurl every one of them into a preview card.

string

string[]

Promise<void>

Notifications.postToThread


preflight(layout): Promise<void>

Defined in: plugins/holocron-plugin-discord/src/capabilities/notifications.ts:758

Changing server settings needs Manage Server; an empty edit proves the bot has it without changing anything.

NotificationsLayout

Promise<void>

Notifications.preflight


readDiscussion(channel, key, url?): Promise<DiscussionPost | undefined>

Defined in: plugins/holocron-plugin-discord/src/capabilities/notifications.ts:1304

The post for a document in a forum channel, or undefined.

string

string

string

Promise<DiscussionPost | undefined>

Notifications.readDiscussion


readDiscussionMessages(channel, key, limit?): Promise<string[]>

Defined in: plugins/holocron-plugin-discord/src/capabilities/notifications.ts:1319

The text of a post’s recent messages, newest first.

string

string

number

Promise<string[]>

Notifications.readDiscussionMessages


readThread(threadId): Promise<string[]>

Defined in: plugins/holocron-plugin-discord/src/capabilities/notifications.ts:422

The text of every message in a thread, oldest first.

string

Promise<string[]>

Notifications.readThread


removeRoleMember(roleName, memberId): Promise<void>

Defined in: plugins/holocron-plugin-discord/src/capabilities/notifications.ts:2864

Take the role from a member; one who lacks it is left alone.

string

string

Promise<void>

Notifications.removeRoleMember


roleMembers(roleName): Promise<NotificationsMember[]>

Defined in: plugins/holocron-plugin-discord/src/capabilities/notifications.ts:2842

Who holds a role, by the provider’s member id. Needs whatever permission the provider asks for to list members (for Discord, the privileged Server Members Intent). Throws if the role does not exist.

string

Promise<NotificationsMember[]>

Notifications.roleMembers


send(channel, message): Promise<void>

Defined in: plugins/holocron-plugin-discord/src/capabilities/notifications.ts:330

Send a message. channel is provider-specific (Slack channel id, Discord webhook url-name, etc.); adapters resolve from config.

string

string

Promise<void>

Notifications.send


sendWithId(channel, message, options?): Promise<NotificationsPostedMessage>

Defined in: plugins/holocron-plugin-discord/src/capabilities/notifications.ts:344

Like send, but waits for Discord (?wait=true) and returns the message, so a thread can be started on it. It posts through the channel’s webhook, resolved as send does. When no webhook can be found for it (no alias, no URL, no defaultChannel and no default webhook: the AuthError the default webhook throws), it posts as the bot in the server’s channel of that name instead, which is what a machine without the channel’s webhook (a GitHub secret cannot be read back) has. Any other failure is not caught. The message carries the suppress-embeds flag unless options.suppressEmbeds is false.

string

string

NotificationsSendOptions

Promise<NotificationsPostedMessage>

Notifications.sendWithId


serverOwner(): Promise<{ id: string; isBot: boolean; name?: string; }>

Defined in: plugins/holocron-plugin-discord/src/capabilities/notifications.ts:2816

Who owns the server, and whether that is the provider’s own bot.

Promise<{ id: string; isBot: boolean; name?: string; }>

Notifications.serverOwner


signIn(): NotificationsSignIn

Defined in: plugins/holocron-plugin-discord/src/capabilities/notifications.ts:301

Sign a member in with Discord to learn which GitHub account they own. Asks only for identify and connections, reads the account Discord has verified, and revokes the token before returning: nothing about the sign-in is kept.

NotificationsSignIn

Notifications.signIn


startThread(message, name): Promise<{ id: string; }>

Defined in: plugins/holocron-plugin-discord/src/capabilities/notifications.ts:403

Starts a public thread on a message, as the bot. A 403 says the bot needs Create Public Threads in the channel.

NotificationsPostedMessage

string

Promise<{ id: string; }>

Notifications.startThread


transferServer(memberId): Promise<void>

Defined in: plugins/holocron-plugin-discord/src/capabilities/notifications.ts:2812

Hands the server to a member who has joined, so the bot no longer owns it.

string

Promise<void>

Notifications.transferServer


updateDiscussion(channel, key, patch): Promise<void>

Defined in: plugins/holocron-plugin-discord/src/capabilities/notifications.ts:1309

Changes a document’s post: its title, its tag, the state last synced, the pull request line.

string

string

DiscussionPatch

Promise<void>

Notifications.updateDiscussion


validateLayout(layout): string | undefined

Defined in: plugins/holocron-plugin-discord/src/capabilities/notifications.ts:1941

Check the provider-specific parts of the layout (colours, permission names, …) without touching the server, so setup can refuse a bad layout before it creates anything. Returns the first problem, or undefined when the layout is fine.

NotificationsLayout

string | undefined

Notifications.validateLayout


whoami(): Promise<{ target: string; } | null>

Defined in: plugins/holocron-plugin-discord/src/capabilities/notifications.ts:432

holocron doctor: the bot token is valid and can see the configured server. Null when no guildId is set – a post-only config has no bot to check. A layout without a guildId is a half-written provisioning config, so that fails instead of passing as post-only.

Promise<{ target: string; } | null>

Notifications.whoami