serverId as their first argument. When a handler does several things in one server, you pass the same id over and over. client.guild(serverId) returns a lightweight handle that binds the id once, so every call after it reads a little cleaner.
Bind the server once
Callclient.guild() with a serverId and keep the handle it returns. Each of its methods delegates to the identically named flat client method with the id already filled in.
Message.serverId is string | null, and guild() takes a string. Direct messages arrive on the same messageCreate event with a null serverId, so guard before you bind.
It is optional sugar
The two forms below do exactly the same thing.g.timeout(userId, 300) delegates straight to client.timeout(serverId, userId, 300).
serverId.
There is one exception. webhooks.post() does not mirror a Client method: it calls the SDK’s module-level webhook poster directly and needs no permission at all, because it posts to a URL a human already created.
The handle holds no state of its own. It fetches nothing when you create it, and it never goes stale. You can make a new one per handler without cost.
What the handle exposes
id is the serverId you passed. Every other member is a bound version of a flat client method. The semantics live in the linked guides, since the handle changes nothing about how each method behaves.
Identity
string
The
serverId this handle is bound to.Messaging
(channelId: string, text: string, opts?: SendOptions) => Promise<void>
Send an encrypted message into a channel in this server.
SendOptions is { groupId?, mentions?, replyTo? }. There is no positional groupId argument. See Sending messages.(channelId: string, opts?) => Promise<Message[]>
Read message history from a channel, oldest first. See Message history.
(channelId: string, card: CardMessage) => Promise<void>
Post a rich card. End-to-end encrypted, under the bot’s own identity, and it needs only
message_send. This is the embed lane to default to. See Rich cards.(channelId: string, post: UnencryptedWebhookPost) => Promise<void>
Post a rich embed through a webhook. Requires
manage_server. See Webhook embeds.send() and sendCard() are fire-and-forget. The promise resolves when the frame leaves the process, not when the server accepts it. A server-side denial arrives later on the sendRejected event, so a try/catch around the send will not see it.Moderation
(userId: string) => Promise<void>
Remove a member from this server.
(userId: string, reason?: string) => Promise<void>
Ban a member, with an optional reason capped at 256 characters.
(userId: string) => Promise<void>
Lift a ban.
(userId: string, seconds: number) => Promise<void>
Time a member out for a number of seconds.
0 lifts it.(userId: string) => Promise<void>
Clear an active timeout.
() => Promise<BanInfo[]>
List the server’s recorded bans.
Reads
() => Promise<Role[]>
List the server’s roles, with color, position, and member count.
() => Promise<Member[]>
List the server’s members. Currently out of service.
Channels and groups
(name: string, groupId: string, type?: number) => Promise<string>
Create a channel inside a group and resolve to its new id.
(channelId: string, groupId: string, name: string) => Promise<void>
Rename a channel.
(channelId: string, groupId: string) => Promise<void>
Delete a channel, along with its messages and pins.
(channelId: string, fromGroupId: string, toGroupId: string, order: number) => Promise<void>
Move a channel between groups and set its position.
(name: string) => Promise<string | undefined>
Create a channel group. Resolves to
undefined when the new group’s id could not be captured.(groupId: string, name: string) => Promise<void>
Rename a group.
(groupId: string) => Promise<void>
Delete a group and every channel inside it.
Webhooks
webhooks is a nested object on the handle, pre-bound to this server. Everything it posts is stored server-side as plaintext.
() => Promise<WebhookInfo[]>
Every webhook on the server. Never includes a token. Requires
manage_server.(channelId: string, name: string, opts?: { icon?: string; miniIcon?: string }) => Promise<WebhookMint>
Mint a webhook on a channel and return its one-time delivery URL. Requires
manage_server.(webhookId: string, changes) => Promise<void>
Rename, re-icon, or move a webhook. Requires
manage_server.(webhookId: string) => Promise<WebhookMint>
Mint a fresh token and return the new URL. This permanently invalidates the old one. Requires
manage_server.(webhookId: string) => Promise<void>
Delete a webhook. Requires
manage_server.(url: string, post: UnencryptedWebhookPost) => Promise<void>
Post to a webhook URL a human already created. No permission required, and the recommended path.
webhooks.post is preferred over minting.
Voice
(channelId: string, opts?: { groupId?: string; muted?: boolean; deafened?: boolean }) => Promise<VoiceConnection>
Join a voice channel and return the credential the server minted. Sends no media by itself.
() => Promise<void>
Ask the server to push a fresh voice roster snapshot for this server.
groupId rule.
Permissions and visibility
(permission: PermissionName) => boolean
Advisory check for a single permission in this server. Returns
false when no verdict has arrived yet.() => PermissionSet | undefined
The resolved permission set for this server, or
undefined if no verdict has arrived yet.() => string[]
The channel ids the bot may currently view in this server.
What the handle does not bind
The handle covers server-scoped methods only. Everything below stays on the flat client, so call it there rather than looking for it ong.
Putting it together
A moderation handler is where the handle earns its place. One bind, then several bound calls that never repeat the server id.Next
Moderation
Kicks, bans, and timeouts in full.
Channels and groups
Create, edit, and move channels and groups.
Sending messages
SendOptions, and why a send is fire-and-forget.
Client reference
Every flat method the handle binds.