Client

export class Client<Ready extends boolean = boolean> extends BaseClient
export class Client<Ready extends boolean = boolean> extends BaseClient
The main hub for interacting with the Discord API, and the starting point for any bot.

Extends

BaseClient
NameConstraintsOptionalDefaultDescription
ReadybooleanYesbooleanNone
constructor(options)
NameTypeOptionalDescription
optionsClientOptionsNoNone
applicationCommandPermissionsUpdate
Emitted whenever permissions for an application command in a guild were updated. This includes permission updates for other applications in addition to the logged in client, check data.applicationId to verify which application the update is for
NameTypeOptionalDescription
dataApplicationCommandPermissionsUpdateDataNo
The updated permissions
autoModerationActionExecution
Emitted whenever an auto moderation rule is triggered. This event requires the PermissionFlagsBits.ManageGuild permission.
NameTypeOptionalDescription
autoModerationActionExecutionAutoModerationActionExecutionNo
The data of the execution
autoModerationRuleCreate
Emitted whenever an auto moderation rule is created. This event requires the PermissionFlagsBits.ManageGuild permission.
NameTypeOptionalDescription
autoModerationRuleAutoModerationRuleNo
The created auto moderation rule
autoModerationRuleDelete
Emitted whenever an auto moderation rule is deleted. This event requires the PermissionFlagsBits.ManageGuild permission.
NameTypeOptionalDescription
autoModerationRuleAutoModerationRuleNo
The deleted auto moderation rule
autoModerationRuleUpdate
Emitted whenever an auto moderation rule gets updated. This event requires the PermissionFlagsBits.ManageGuild permission.
NameTypeOptionalDescription
oldAutoModerationRuleAutoModerationRuleNo
The auto moderation rule before the update
newAutoModerationRuleAutoModerationRuleNo
The auto moderation rule after the update
channelCreate
Emitted whenever a guild channel is created.
NameTypeOptionalDescription
channelGuildChannelNo
The channel that was created
channelDelete
Emitted whenever a channel is deleted.
NameTypeOptionalDescription
channelDMChannel | GuildChannelNo
The channel that was deleted
channelPinsUpdate
Emitted whenever the pins of a channel are updated. Due to the nature of the WebSocket event, not much information can be provided easily here - you need to manually check the pins yourself.
NameTypeOptionalDescription
channelTextBasedChannelsNo
The channel that the pins update occurred in
timeDateNo
The time of the pins update
channelUpdate
Emitted whenever a channel is updated - e.g. name change, topic change, channel type change.
NameTypeOptionalDescription
oldChannelDMChannel | GuildChannelNo
The channel before the update
newChannelDMChannel | GuildChannelNo
The channel after the update
debug
Emitted for general debugging information.
NameTypeOptionalDescription
infostringNo
The debug information
emojiCreate
Emitted whenever a custom emoji is created in a guild.
NameTypeOptionalDescription
emojiGuildEmojiNo
The emoji that was created
emojiDelete
Emitted whenever a custom emoji is deleted in a guild.
NameTypeOptionalDescription
emojiGuildEmojiNo
The emoji that was deleted
emojiUpdate
Emitted whenever a custom emoji is updated in a guild.
NameTypeOptionalDescription
oldEmojiGuildEmojiNo
The old emoji
newEmojiGuildEmojiNo
The new emoji
entitlementCreate
Emitted whenever an entitlement is created.
NameTypeOptionalDescription
entitlementEntitlementNo
The entitlement that was created
entitlementDelete
Emitted whenever an entitlement is deleted. Entitlements are not deleted when they expire. This is only triggered when Discord issues a refund or deletes the entitlement manually.
NameTypeOptionalDescription
entitlementEntitlementNo
The entitlement that was deleted
entitlementUpdate
Emitted whenever an entitlement is updated - i.e. when a user's subscription renews.
NameTypeOptionalDescription
oldEntitlementEntitlementNo
The entitlement before the update
newEntitlementEntitlementNo
The entitlement after the update
error
Emitted when the client encounters an error. Errors thrown within this event do not have a catch handler, it is recommended to not use async functions as error event handlers. See the [Node.js docs](https://nodejs.org/api/events.html#capture-rejections-of-promises) for details.
NameTypeOptionalDescription
errorErrorNo
The error encountered
guildAuditLogEntryCreate
Emitted whenever a guild audit log entry is created.
NameTypeOptionalDescription
auditLogEntryGuildAuditLogsEntryNo
The entry that was created
guildGuildNo
The guild where the entry was created
guildAvailable
Emitted whenever a guild becomes available.
NameTypeOptionalDescription
guildGuildNo
The guild that became available
guildBanAdd
Emitted whenever a member is banned from a guild.
NameTypeOptionalDescription
banGuildBanNo
The ban that occurred
guildBanRemove
Emitted whenever a member is unbanned from a guild.
NameTypeOptionalDescription
banGuildBanNo
The ban that was removed
guildCreate
Emitted whenever the client joins a guild.
NameTypeOptionalDescription
guildGuildNo
The created guild
guildDelete
Emitted whenever a guild kicks the client or the guild is deleted/left.
NameTypeOptionalDescription
guildGuildNo
The guild that was deleted
guildIntegrationsUpdate
Emitted whenever a guild integration is updated
NameTypeOptionalDescription
guildGuildNo
The guild whose integrations were updated
guildMemberAdd
Emitted whenever a user joins a guild.
NameTypeOptionalDescription
memberGuildMemberNo
The member that has joined a guild
guildMemberAvailable
Emitted whenever a member becomes available.
NameTypeOptionalDescription
memberGuildMemberNo
The member that became available
guildMemberRemove
Emitted whenever a member leaves a guild, or is kicked.
NameTypeOptionalDescription
memberGuildMemberNo
The member that has left/been kicked from the guild
guildMembersChunk
Emitted whenever a chunk of guild members is received (all members come from the same guild).
NameTypeOptionalDescription
membersCollection<Snowflake, GuildMember>No
The members in the chunk
guildGuildNo
The guild related to the member chunk
chunkGuildMembersChunkNo
Properties of the received chunk
guildMemberUpdate
Emitted whenever a guild member changes - i.e. new role, removed role, nickname.
NameTypeOptionalDescription
oldMemberGuildMemberNo
The member before the update
newMemberGuildMemberNo
The member after the update
guildScheduledEventCreate
Emitted whenever a guild scheduled event is created.
NameTypeOptionalDescription
guildScheduledEventGuildScheduledEventNo
The created guild scheduled event
guildScheduledEventDelete
Emitted whenever a guild scheduled event is deleted.
NameTypeOptionalDescription
guildScheduledEventGuildScheduledEventNo
The deleted guild scheduled event
guildScheduledEventUpdate
Emitted whenever a guild scheduled event gets updated.
NameTypeOptionalDescription
oldGuildScheduledEventGuildScheduledEventNo
The guild scheduled event object before the update
newGuildScheduledEventGuildScheduledEventNo
The guild scheduled event object after the update
guildScheduledEventUserAdd
Emitted whenever a user subscribes to a guild scheduled event
NameTypeOptionalDescription
guildScheduledEventGuildScheduledEventNo
The guild scheduled event
userUserNo
The user who subscribed
guildScheduledEventUserRemove
Emitted whenever a user unsubscribes from a guild scheduled event
NameTypeOptionalDescription
guildScheduledEventGuildScheduledEventNo
The guild scheduled event
userUserNo
The user who unsubscribed
guildUnavailable
Emitted whenever a guild becomes unavailable, likely due to a server outage.
NameTypeOptionalDescription
guildGuildNo
The guild that has become unavailable
guildUpdate
Emitted whenever a guild is updated - e.g. name change.
NameTypeOptionalDescription
oldGuildGuildNo
The guild before the update
newGuildGuildNo
The guild after the update
interactionCreate
Emitted when an interaction is created.
NameTypeOptionalDescription
interactionBaseInteractionNo
The interaction which was created
inviteCreate
Emitted when an invite is created. This event requires the PermissionFlagsBits.ManageChannels permission for the channel.
NameTypeOptionalDescription
inviteInviteNo
The invite that was created
inviteDelete
Emitted when an invite is deleted. This event requires the PermissionFlagsBits.ManageChannels permission for the channel.
NameTypeOptionalDescription
inviteInviteNo
The invite that was deleted
messageCreate
Emitted whenever a message is created.
NameTypeOptionalDescription
messageMessageNo
The created message
messageDelete
Emitted whenever a message is deleted.
NameTypeOptionalDescription
messageMessageNo
The deleted message
messageDeleteBulk
Emitted whenever messages are deleted in bulk.
NameTypeOptionalDescription
messagesCollection<Snowflake, Message>No
The deleted messages, mapped by their id
channelGuildTextBasedChannelNo
The channel that the messages were deleted in
messageReactionAdd
Emitted whenever a reaction is added to a cached message.
NameTypeOptionalDescription
messageReactionMessageReactionNo
The reaction object
userUserNo
The user that applied the guild or reaction emoji
messageReactionRemove
Emitted whenever a reaction is removed from a cached message.
NameTypeOptionalDescription
messageReactionMessageReactionNo
The reaction object
userUserNo
The user whose emoji or reaction emoji was removed
messageReactionRemoveAll
Emitted whenever all reactions are removed from a cached message.
NameTypeOptionalDescription
messageMessageNo
The message the reactions were removed from
reactionsCollection<(string|Snowflake), MessageReaction>No
The cached message reactions that were removed.
messageReactionRemoveEmoji
Emitted when a bot removes an emoji reaction from a cached message.
NameTypeOptionalDescription
reactionMessageReactionNo
The reaction that was removed
messageUpdate
Emitted whenever a message is updated - e.g. embed or content change.
NameTypeOptionalDescription
oldMessageMessageNo
The message before the update
newMessageMessageNo
The message after the update
presenceUpdate
Emitted whenever a guild member's presence (e.g. status, activity) is changed.
NameTypeOptionalDescription
oldPresencePresenceNo
The presence before the update, if one at all
newPresencePresenceNo
The presence after the update
ready
Emitted when the client becomes ready to start working.
NameTypeOptionalDescription
clientClientNo
The client
roleCreate
Emitted whenever a role is created.
NameTypeOptionalDescription
roleRoleNo
The role that was created
roleDelete
Emitted whenever a guild role is deleted.
NameTypeOptionalDescription
roleRoleNo
The role that was deleted
roleUpdate
Emitted whenever a guild role is updated.
NameTypeOptionalDescription
oldRoleRoleNo
The role before the update
newRoleRoleNo
The role after the update
shardDisconnect
Emitted when a shard's WebSocket disconnects and will no longer reconnect.
NameTypeOptionalDescription
eventCloseEventNo
The WebSocket close event
idnumberNo
The shard id that disconnected
shardError
Emitted whenever a shard's WebSocket encounters a connection error.
NameTypeOptionalDescription
errorErrorNo
The encountered error
shardIdnumberNo
The shard that encountered this error
shardReady
Emitted when a shard turns ready.
NameTypeOptionalDescription
idnumberNo
The shard id that turned ready
unavailableGuildsSet<Snowflake>No
Set of unavailable guild ids, if any
shardReconnecting
Emitted when a shard is attempting to reconnect or re-identify.
NameTypeOptionalDescription
idnumberNo
The shard id that is attempting to reconnect
shardResume
Emitted when a shard resumes successfully.
NameTypeOptionalDescription
idnumberNo
The shard id that resumed
replayedEventsnumberNo
The amount of replayed events
stageInstanceCreate
Emitted whenever a stage instance is created.
NameTypeOptionalDescription
stageInstanceStageInstanceNo
The created stage instance
stageInstanceDelete
Emitted whenever a stage instance is deleted.
NameTypeOptionalDescription
stageInstanceStageInstanceNo
The deleted stage instance
stageInstanceUpdate
Emitted whenever a stage instance gets updated - e.g. change in topic or privacy level
NameTypeOptionalDescription
oldStageInstanceStageInstanceNo
The stage instance before the update
newStageInstanceStageInstanceNo
The stage instance after the update
stickerCreate
Emitted whenever a custom sticker is created in a guild.
NameTypeOptionalDescription
stickerStickerNo
The sticker that was created
stickerDelete
Emitted whenever a custom sticker is deleted in a guild.
NameTypeOptionalDescription
stickerStickerNo
The sticker that was deleted
stickerUpdate
Emitted whenever a custom sticker is updated in a guild.
NameTypeOptionalDescription
oldStickerStickerNo
The old sticker
newStickerStickerNo
The new sticker
threadCreate
Emitted whenever a thread is created or when the client user is added to a thread.
NameTypeOptionalDescription
threadThreadChannelNo
The thread that was created
newlyCreatedbooleanNo
Whether the thread was newly created
threadDelete
Emitted whenever a thread is deleted.
NameTypeOptionalDescription
threadThreadChannelNo
The thread that was deleted
threadListSync
Emitted whenever the client user gains access to a text or news channel that contains threads
NameTypeOptionalDescription
threadsCollection<Snowflake, ThreadChannel>No
The threads that were synced
guildGuildNo
The guild that the threads were synced in
threadMembersUpdate
Emitted whenever members are added or removed from a thread. This event requires the GatewayIntentBits.GuildMembers privileged gateway intent.
NameTypeOptionalDescription
addedMembersCollection<Snowflake, ThreadMember>No
The members that were added
removedMembersCollection<Snowflake, ThreadMember>No
The members that were removed
threadThreadChannelNo
The thread where members got updated
threadMemberUpdate
Emitted whenever the client user's thread member is updated.
NameTypeOptionalDescription
oldMemberThreadMemberNo
The member before the update
newMemberThreadMemberNo
The member after the update
threadUpdate
Emitted whenever a thread is updated - e.g. name change, archive state change, locked state change.
NameTypeOptionalDescription
oldThreadThreadChannelNo
The thread before the update
newThreadThreadChannelNo
The thread after the update
typingStart
Emitted whenever a user starts typing in a channel.
NameTypeOptionalDescription
typingTypingNo
The typing state
userUpdate
Emitted whenever a user's details (e.g. username) are changed. Triggered by the Discord gateway events UserUpdate, GuildMemberUpdate, and PresenceUpdate.
NameTypeOptionalDescription
oldUserUserNo
The user before the update
newUserUserNo
The user after the update
voiceStateUpdate
Emitted whenever a member changes voice state - e.g. joins/leaves a channel, mutes/unmutes.
NameTypeOptionalDescription
oldStateVoiceStateNo
The voice state before the update
newStateVoiceStateNo
The voice state after the update
warn
Emitted for general warnings.
NameTypeOptionalDescription
infostringNo
The warning
webhooksUpdate
Emitted whenever a channel has its webhooks changed.
NameTypeOptionalDescription
channelTextChannel | NewsChannel | VoiceChannel | StageChannel | ForumChannel | MediaChannelNo
The channel that had a webhook update
Deprecated
webhookUpdate
Use webhooksUpdate instead.
Deprecated
Emitted whenever a channel has its webhooks changed.
NameTypeOptionalDescription
channelTextChannel | NewsChannel | VoiceChannel | StageChannel | ForumChannel | MediaChannelNo
The channel that had a webhook update
application:If<Ready, ClientApplication>
The application of this bot
All of the BaseChannels that the client is currently handling, mapped by their ids - as long as sharding isn't being used, this will be *every * channel in *every * guild the bot is a member of. Note that DM channels will not be initially cached, and thus not be present in the Manager without their explicit fetching or use.
Readonly
All custom emojis that the client has access to, mapped by their ids
All of the guilds the client is currently handling, mapped by their ids - as long as sharding isn't being used, this will be *every * guild the bot is a member of
options:Omit<ClientOptions, 'intents'> & { intents: IntentsBitField }
The options the client was instantiated with
Readonly
readyAt:If<Ready, Date>
Time at which the client was last regarded as being in the Ready state (each time the client disconnects and successfully reconnects, this will be overwritten)
readyTimestamp:If<Ready, number>
Timestamp of the time the client was last Ready at
rest:REST
The REST manager of the client
Inherited from BaseClient
Shard helpers for the client (only if the process was spawned from a ShardingManager)
sweepers:Sweepers
The sweeping functions and their intervals used to periodically sweep caches
token:If<Ready, string, string | null>
Authorization token for the logged in bot. If present, this defaults to process.env.DISCORD_TOKEN when instantiating the client This should be kept private at all times.
Readonly
uptime:If<Ready, number>
How long it has been since the client last entered the Ready state in milliseconds
user:If<Ready, ClientUser>
User that the client is logged in as
All of the objects that have been cached at any point, mapped by their ids
The voice manager of the client
The WebSocket manager of the client
[Symbol.asyncDispose]():Promise<void>
deleteWebhook(id, options?):Promise<void>
Deletes a webhook.
NameTypeOptionalDescription
idSnowflakeNo
The webhook's id
optionsWebhookDeleteOptionsYes
Options for deleting the webhook
destroy():Promise<void>
Logs out, terminates the connection to Discord, and destroys the client.
emit(event, ...args):boolean
NameConstraintsOptionalDefaultDescription
Eventkeyof ClientEventsNoNone
NameTypeOptionalDescription
eventEventNoNone
...argsClientEvents[Event]NoNone
fetchGuildPreview(guild):Promise<GuildPreview>
Obtains a guild preview from Discord, available for all guilds the bot is in and all Discoverable guilds.
NameTypeOptionalDescription
guildGuildResolvableNo
The guild to fetch the preview for
fetchGuildTemplate(template):Promise<GuildTemplate>
Obtains a template from Discord.
Example
client.fetchGuildTemplate('https://discord.new/FKvmczH2HyUf')
.then(template => console.log(`Obtained template with code: ${template.code}`))
.catch(console.error);
client.fetchGuildTemplate('https://discord.new/FKvmczH2HyUf')
.then(template => console.log(`Obtained template with code: ${template.code}`))
.catch(console.error);
NameTypeOptionalDescription
templateGuildTemplateResolvableNo
Template code or URL
fetchGuildWidget(guild):Promise<Widget>
Obtains the widget data of a guild from Discord, available for guilds with the widget enabled.
NameTypeOptionalDescription
guildGuildResolvableNo
The guild to fetch the widget data for
fetchInvite(invite, options?):Promise<Invite>
Obtains an invite from Discord.
Example
client.fetchInvite('https://discord.gg/djs')
.then(invite => console.log(`Obtained invite with code: ${invite.code}`))
.catch(console.error);
client.fetchInvite('https://discord.gg/djs')
.then(invite => console.log(`Obtained invite with code: ${invite.code}`))
.catch(console.error);
NameTypeOptionalDescription
inviteInviteResolvableNo
Invite code or URL
optionsClientFetchInviteOptionsYes
Options for fetching the invite
Deprecated
fetchPremiumStickerPacks():ReturnType<Client['fetchStickerPacks']>
Use fetchStickerPacks instead.
Deprecated
Obtains the list of available sticker packs.
fetchSticker(id):Promise<Sticker>
Obtains a sticker from Discord.
Example
client.fetchSticker('id')
.then(sticker => console.log(`Obtained sticker with name: ${sticker.name}`))
.catch(console.error);
client.fetchSticker('id')
.then(sticker => console.log(`Obtained sticker with name: ${sticker.name}`))
.catch(console.error);
NameTypeOptionalDescription
idSnowflakeNo
The sticker's id
fetchStickerPacks():Promise<Collection<Snowflake, StickerPack>>
Obtains the list of available sticker packs.
Example
client.fetchStickerPacks()
.then(packs => console.log(`Available sticker packs are: ${packs.map(pack => pack.name).join(', ')}`))
.catch(console.error);
client.fetchStickerPacks()
.then(packs => console.log(`Available sticker packs are: ${packs.map(pack => pack.name).join(', ')}`))
.catch(console.error);
fetchVoiceRegions():Promise<Collection<string, VoiceRegion>>
Obtains the available voice regions from Discord.
Example
client.fetchVoiceRegions()
.then(regions => console.log(`Available regions are: ${regions.map(region => region.name).join(', ')}`))
.catch(console.error);
client.fetchVoiceRegions()
.then(regions => console.log(`Available regions are: ${regions.map(region => region.name).join(', ')}`))
.catch(console.error);
fetchWebhook(id, token?):Promise<Webhook>
Obtains a webhook from Discord.
Example
client.fetchWebhook('id', 'token')
.then(webhook => console.log(`Obtained webhook with name: ${webhook.name}`))
.catch(console.error);
client.fetchWebhook('id', 'token')
.then(webhook => console.log(`Obtained webhook with name: ${webhook.name}`))
.catch(console.error);
NameTypeOptionalDescription
idSnowflakeNo
The webhook's id
tokenstringYes
Token for the webhook
generateInvite(options?):string
Generates a link that can be used to invite the bot to a guild.
Example
const link = client.generateInvite({
scopes: [OAuth2Scopes.ApplicationsCommands],
});
console.log(`Generated application invite link: ${link}`);
const link = client.generateInvite({
scopes: [OAuth2Scopes.ApplicationsCommands],
});
console.log(`Generated application invite link: ${link}`);
Example
const link = client.generateInvite({
permissions: [
PermissionFlagsBits.SendMessages,
PermissionFlagsBits.ManageGuild,
PermissionFlagsBits.MentionEveryone,
],
scopes: [OAuth2Scopes.Bot],
});
console.log(`Generated bot invite link: ${link}`);
const link = client.generateInvite({
permissions: [
PermissionFlagsBits.SendMessages,
PermissionFlagsBits.ManageGuild,
PermissionFlagsBits.MentionEveryone,
],
scopes: [OAuth2Scopes.Bot],
});
console.log(`Generated bot invite link: ${link}`);
NameTypeOptionalDescription
optionsInviteGenerationOptionsYes
Options for the invite
isReady():this is Client<true>
Returns whether the client has logged in, indicative of being able to access properties such as user and application.
login(token?):Promise<string>
Logs the client in, establishing a WebSocket connection to Discord.
Returns
Token of the account used
Example
client.login('my token');
client.login('my token');
NameTypeOptionalDescription
tokenstringYes
Token of the account to log in with
off(event, listener):this
NameConstraintsOptionalDefaultDescription
Eventkeyof ClientEventsNoNone
NameTypeOptionalDescription
eventEventNoNone
listener(...args: ClientEvents[Event]) => voidNoNone
on(event, listener):this
NameConstraintsOptionalDefaultDescription
Eventkeyof ClientEventsNoNone
NameTypeOptionalDescription
eventEventNoNone
listener(...args: ClientEvents[Event]) => voidNoNone
once(event, listener):this
NameConstraintsOptionalDefaultDescription
Eventkeyof ClientEventsNoNone
NameTypeOptionalDescription
eventEventNoNone
listener(...args: ClientEvents[Event]) => voidNoNone
removeAllListeners(event?):this
NameConstraintsOptionalDefaultDescription
Eventkeyof ClientEventsNoNone
NameTypeOptionalDescription
eventEventYesNone
toJSON():unknown