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(data)
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
dataApplicationCommandPermissionsUpdateDataNoThe updated permissions
autoModerationActionExecution(autoModerationActionExecution)
Emitted whenever an auto moderation rule is triggered. This event requires the permission.
NameTypeOptionalDescription
autoModerationActionExecutionAutoModerationActionExecutionNoThe data of the execution
autoModerationRuleCreate(autoModerationRule)
Emitted whenever an auto moderation rule is created. This event requires the permission.
NameTypeOptionalDescription
autoModerationRuleAutoModerationRuleNoThe created auto moderation rule
autoModerationRuleDelete(autoModerationRule)
Emitted whenever an auto moderation rule is deleted. This event requires the permission.
NameTypeOptionalDescription
autoModerationRuleAutoModerationRuleNoThe deleted auto moderation rule
autoModerationRuleUpdate(oldAutoModerationRule, newAutoModerationRule)
Emitted whenever an auto moderation rule gets updated. This event requires the permission.
NameTypeOptionalDescription
oldAutoModerationRuleAutoModerationRuleNoThe auto moderation rule before the update
newAutoModerationRuleAutoModerationRuleNoThe auto moderation rule after the update
channelCreate(channel)
Emitted whenever a guild channel is created.
NameTypeOptionalDescription
channelGuildChannelNoThe channel that was created
channelDelete(channel)
Emitted whenever a channel is deleted.
NameTypeOptionalDescription
channelDMChannelGuildChannelNoThe channel that was deleted
channelPinsUpdate(channel, time)
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
channelTextBasedChannelsNoThe channel that the pins update occurred in
timeDateNoThe time of the pins update
channelUpdate(oldChannel, newChannel)
Emitted whenever a channel is updated - e.g. name change, topic change, channel type change.
NameTypeOptionalDescription
oldChannelDMChannelGuildChannelNoThe channel before the update
newChannelDMChannelGuildChannelNoThe channel after the update
debug(info)
Emitted for general debugging information.
NameTypeOptionalDescription
infostringNoThe debug information
emojiCreate(emoji)
Emitted whenever a custom emoji is created in a guild.
NameTypeOptionalDescription
emojiGuildEmojiNoThe emoji that was created
emojiDelete(emoji)
Emitted whenever a custom emoji is deleted in a guild.
NameTypeOptionalDescription
emojiGuildEmojiNoThe emoji that was deleted
emojiUpdate(oldEmoji, newEmoji)
Emitted whenever a custom emoji is updated in a guild.
NameTypeOptionalDescription
oldEmojiGuildEmojiNoThe old emoji
newEmojiGuildEmojiNoThe new emoji
error(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
errorErrorNoThe error encountered
guildAuditLogEntryCreate(auditLogEntry, guild)
Emitted whenever a guild audit log entry is created.
NameTypeOptionalDescription
auditLogEntryGuildAuditLogsEntryNoThe entry that was created
guildGuildNoThe guild where the entry was created
guildAvailable(guild)
Emitted whenever a guild becomes available.
NameTypeOptionalDescription
guildGuildNoThe guild that became available
guildBanAdd(ban)
Emitted whenever a member is banned from a guild.
NameTypeOptionalDescription
banGuildBanNoThe ban that occurred
guildBanRemove(ban)
Emitted whenever a member is unbanned from a guild.
NameTypeOptionalDescription
banGuildBanNoThe ban that was removed
guildCreate(guild)
Emitted whenever the client joins a guild.
NameTypeOptionalDescription
guildGuildNoThe created guild
guildDelete(guild)
Emitted whenever a guild kicks the client or the guild is deleted/left.
NameTypeOptionalDescription
guildGuildNoThe guild that was deleted
guildIntegrationsUpdate(guild)
Emitted whenever a guild integration is updated
NameTypeOptionalDescription
guildGuildNoThe guild whose integrations were updated
guildMemberAdd(member)
Emitted whenever a user joins a guild.
NameTypeOptionalDescription
memberGuildMemberNoThe member that has joined a guild
guildMemberAvailable(member)
Emitted whenever a member becomes available.
NameTypeOptionalDescription
memberGuildMemberNoThe member that became available
guildMemberRemove(member)
Emitted whenever a member leaves a guild, or is kicked.
NameTypeOptionalDescription
memberGuildMemberNoThe member that has left/been kicked from the guild
guildMembersChunk(members, guild, chunk)
Emitted whenever a chunk of guild members is received (all members come from the same guild).
NameTypeOptionalDescription
membersCollection<Snowflake, GuildMember>NoThe members in the chunk
guildGuildNoThe guild related to the member chunk
chunkGuildMembersChunkNoProperties of the received chunk
guildMemberUpdate(oldMember, newMember)
Emitted whenever a guild member changes - i.e. new role, removed role, nickname.
NameTypeOptionalDescription
oldMemberGuildMemberNoThe member before the update
newMemberGuildMemberNoThe member after the update
guildScheduledEventCreate(guildScheduledEvent)
Emitted whenever a guild scheduled event is created.
NameTypeOptionalDescription
guildScheduledEventGuildScheduledEventNoThe created guild scheduled event
guildScheduledEventDelete(guildScheduledEvent)
Emitted whenever a guild scheduled event is deleted.
NameTypeOptionalDescription
guildScheduledEventGuildScheduledEventNoThe deleted guild scheduled event
guildScheduledEventUpdate(oldGuildScheduledEvent, newGuildScheduledEvent)
Emitted whenever a guild scheduled event gets updated.
NameTypeOptionalDescription
oldGuildScheduledEventGuildScheduledEventNoThe guild scheduled event object before the update
newGuildScheduledEventGuildScheduledEventNoThe guild scheduled event object after the update
guildScheduledEventUserAdd(guildScheduledEvent, user)
Emitted whenever a user subscribes to a guild scheduled event
NameTypeOptionalDescription
guildScheduledEventGuildScheduledEventNoThe guild scheduled event
userUserNoThe user who subscribed
guildScheduledEventUserRemove(guildScheduledEvent, user)
Emitted whenever a user unsubscribes from a guild scheduled event
NameTypeOptionalDescription
guildScheduledEventGuildScheduledEventNoThe guild scheduled event
userUserNoThe user who unsubscribed
guildUnavailable(guild)
Emitted whenever a guild becomes unavailable, likely due to a server outage.
NameTypeOptionalDescription
guildGuildNoThe guild that has become unavailable
guildUpdate(oldGuild, newGuild)
Emitted whenever a guild is updated - e.g. name change.
NameTypeOptionalDescription
oldGuildGuildNoThe guild before the update
newGuildGuildNoThe guild after the update
interactionCreate(interaction)
Emitted when an interaction is created.
NameTypeOptionalDescription
interactionBaseInteractionNoThe interaction which was created
inviteCreate(invite)
Emitted when an invite is created. This event requires the permission for the channel.
NameTypeOptionalDescription
inviteInviteNoThe invite that was created
inviteDelete(invite)
Emitted when an invite is deleted. This event requires the permission for the channel.
NameTypeOptionalDescription
inviteInviteNoThe invite that was deleted
messageCreate(message)
Emitted whenever a message is created.
NameTypeOptionalDescription
messageMessageNoThe created message
messageDelete(message)
Emitted whenever a message is deleted.
NameTypeOptionalDescription
messageMessageNoThe deleted message
messageDeleteBulk(messages, channel)
Emitted whenever messages are deleted in bulk.
NameTypeOptionalDescription
messagesCollection<Snowflake, Message>NoThe deleted messages, mapped by their id
channelGuildTextBasedChannelNoThe channel that the messages were deleted in
messageReactionAdd(messageReaction, user)
Emitted whenever a reaction is added to a cached message.
NameTypeOptionalDescription
messageReactionMessageReactionNoThe reaction object
userUserNoThe user that applied the guild or reaction emoji
messageReactionRemove(messageReaction, user)
Emitted whenever a reaction is removed from a cached message.
NameTypeOptionalDescription
messageReactionMessageReactionNoThe reaction object
userUserNoThe user whose emoji or reaction emoji was removed
messageReactionRemoveAll(message, reactions)
Emitted whenever all reactions are removed from a cached message.
NameTypeOptionalDescription
messageMessageNoThe message the reactions were removed from
reactionsCollection<(string|Snowflake), MessageReaction>NoThe cached message reactions that were removed.
messageReactionRemoveEmoji(reaction)
Emitted when a bot removes an emoji reaction from a cached message.
NameTypeOptionalDescription
reactionMessageReactionNoThe reaction that was removed
messageUpdate(oldMessage, newMessage)
Emitted whenever a message is updated - e.g. embed or content change.
NameTypeOptionalDescription
oldMessageMessageNoThe message before the update
newMessageMessageNoThe message after the update
presenceUpdate(oldPresence, newPresence)
Emitted whenever a guild member's presence (e.g. status, activity) is changed.
NameTypeOptionalDescription
oldPresencePresenceNoThe presence before the update, if one at all
newPresencePresenceNoThe presence after the update
ready(client)
Emitted when the client becomes ready to start working.
NameTypeOptionalDescription
clientClientNoThe client
roleCreate(role)
Emitted whenever a role is created.
NameTypeOptionalDescription
roleRoleNoThe role that was created
roleDelete(role)
Emitted whenever a guild role is deleted.
NameTypeOptionalDescription
roleRoleNoThe role that was deleted
roleUpdate(oldRole, newRole)
Emitted whenever a guild role is updated.
NameTypeOptionalDescription
oldRoleRoleNoThe role before the update
newRoleRoleNoThe role after the update
shardDisconnect(event, id)
Emitted when a shard's WebSocket disconnects and will no longer reconnect.
NameTypeOptionalDescription
eventCloseEventNoThe WebSocket close event
idnumberNoThe shard id that disconnected
shardError(error, shardId)
Emitted whenever a shard's WebSocket encounters a connection error.
NameTypeOptionalDescription
errorErrorNoThe encountered error
shardIdnumberNoThe shard that encountered this error
shardReady(id, unavailableGuilds)
Emitted when a shard turns ready.
NameTypeOptionalDescription
idnumberNoThe shard id that turned ready
unavailableGuildsSet<Snowflake>NoSet of unavailable guild ids, if any
shardReconnecting(id)
Emitted when a shard is attempting to reconnect or re-identify.
NameTypeOptionalDescription
idnumberNoThe shard id that is attempting to reconnect
shardResume(id, replayedEvents)
Emitted when a shard resumes successfully.
NameTypeOptionalDescription
idnumberNoThe shard id that resumed
replayedEventsnumberNoThe amount of replayed events
stageInstanceCreate(stageInstance)
Emitted whenever a stage instance is created.
NameTypeOptionalDescription
stageInstanceStageInstanceNoThe created stage instance
stageInstanceDelete(stageInstance)
Emitted whenever a stage instance is deleted.
NameTypeOptionalDescription
stageInstanceStageInstanceNoThe deleted stage instance
stageInstanceUpdate(oldStageInstance, newStageInstance)
Emitted whenever a stage instance gets updated - e.g. change in topic or privacy level
NameTypeOptionalDescription
oldStageInstanceStageInstanceNoThe stage instance before the update
newStageInstanceStageInstanceNoThe stage instance after the update
stickerCreate(sticker)
Emitted whenever a custom sticker is created in a guild.
NameTypeOptionalDescription
stickerStickerNoThe sticker that was created
stickerDelete(sticker)
Emitted whenever a custom sticker is deleted in a guild.
NameTypeOptionalDescription
stickerStickerNoThe sticker that was deleted
stickerUpdate(oldSticker, newSticker)
Emitted whenever a custom sticker is updated in a guild.
NameTypeOptionalDescription
oldStickerStickerNoThe old sticker
newStickerStickerNoThe new sticker
threadCreate(thread, newlyCreated)
Emitted whenever a thread is created or when the client user is added to a thread.
NameTypeOptionalDescription
threadThreadChannelNoThe thread that was created
newlyCreatedbooleanNoWhether the thread was newly created
threadDelete(thread)
Emitted whenever a thread is deleted.
NameTypeOptionalDescription
threadThreadChannelNoThe thread that was deleted
threadListSync(threads, guild)
Emitted whenever the client user gains access to a text or news channel that contains threads
NameTypeOptionalDescription
threadsCollection<Snowflake, ThreadChannel>NoThe threads that were synced
guildGuildNoThe guild that the threads were synced in
threadMembersUpdate(addedMembers, removedMembers, thread)
Emitted whenever members are added or removed from a thread. This event requires the privileged gateway intent.
NameTypeOptionalDescription
addedMembersCollection<Snowflake, ThreadMember>NoThe members that were added
removedMembersCollection<Snowflake, ThreadMember>NoThe members that were removed
threadThreadChannelNoThe thread where members got updated
threadMemberUpdate(oldMember, newMember)
Emitted whenever the client user's thread member is updated.
NameTypeOptionalDescription
oldMemberThreadMemberNoThe member before the update
newMemberThreadMemberNoThe member after the update
threadUpdate(oldThread, newThread)
Emitted whenever a thread is updated - e.g. name change, archive state change, locked state change.
NameTypeOptionalDescription
oldThreadThreadChannelNoThe thread before the update
newThreadThreadChannelNoThe thread after the update
typingStart(typing)
Emitted whenever a user starts typing in a channel.
NameTypeOptionalDescription
typingTypingNoThe typing state
userUpdate(oldUser, newUser)
Emitted whenever a user's details (e.g. username) are changed. Triggered by the Discord gateway events UserUpdate, GuildMemberUpdate, and PresenceUpdate.
NameTypeOptionalDescription
oldUserUserNoThe user before the update
newUserUserNoThe user after the update
voiceStateUpdate(oldState, newState)
Emitted whenever a member changes voice state - e.g. joins/leaves a channel, mutes/unmutes.
NameTypeOptionalDescription
oldStateVoiceStateNoThe voice state before the update
newStateVoiceStateNoThe voice state after the update
warn(info)
Emitted for general warnings.
NameTypeOptionalDescription
infostringNoThe warning
webhooksUpdate(channel)
Emitted whenever a channel has its webhooks changed.
NameTypeOptionalDescription
channelTextChannelNewsChannelVoiceChannelStageChannelForumChannelMediaChannelNoThe channel that had a webhook update
Deprecated
webhookUpdate(channel)
Use webhooksUpdate instead.
Deprecated
Emitted whenever a channel has its webhooks changed.
NameTypeOptionalDescription
channelTextChannelNewsChannelVoiceChannelStageChannelForumChannelMediaChannelNoThe 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:ShardClientUtil | null
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 User objects that have been cached at any point, mapped by their ids
The voice manager of the client
The WebSocket manager of the client
deleteWebhook(id, options?):Promise<void>
Deletes a webhook.
NameTypeOptionalDescription
idSnowflakeNoThe webhook's id
optionsWebhookDeleteOptionsYesOptions for deleting the webhook
destroy():Promise<void>
Logs out, terminates the connection to Discord, and destroys the client.
emit(event, ...args):boolean
NameTypeOptionalDescription
eventKNoNone
...argsClientEvents[K]NoNone
fetchGuildPreview(guild):Promise<GuildPreview>
Obtains a guild preview from Discord, available for all guilds the bot is in and all Discoverable guilds.
NameTypeOptionalDescription
guildGuildResolvableNoThe guild to fetch the preview for
fetchGuildTemplate(template):Promise<GuildTemplate>
Obtains a template from Discord.
NameTypeOptionalDescription
templateGuildTemplateResolvableNoTemplate code or URL
fetchGuildWidget(guild):Promise<Widget>
Obtains the widget data of a guild from Discord, available for guilds with the widget enabled.
NameTypeOptionalDescription
guildGuildResolvableNoThe guild to fetch the widget data for
fetchInvite(invite, options?):Promise<Invite>
Obtains an invite from Discord.
NameTypeOptionalDescription
inviteInviteResolvableNoInvite code or URL
optionsClientFetchInviteOptionsYesOptions 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.
NameTypeOptionalDescription
idSnowflakeNoThe sticker's id
fetchStickerPacks():Promise<Collection<Snowflake, StickerPack>>
Obtains the list of available sticker packs.
fetchVoiceRegions():Promise<Collection<string, VoiceRegion>>
Obtains the available voice regions from Discord.
fetchWebhook(id, token?):Promise<Webhook>
Obtains a webhook from Discord.
NameTypeOptionalDescription
idSnowflakeNoThe webhook's id
tokenstringYesToken for the webhook
generateInvite(options?):string
Generates a link that can be used to invite the bot to a guild.
NameTypeOptionalDescription
optionsInviteGenerationOptionsYesOptions 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
NameTypeOptionalDescription
tokenstringYesToken of the account to log in with
off(event, listener):this
NameTypeOptionalDescription
eventKNoNone
listener(...args: ClientEvents[K]) => Awaitable<void>NoNone
on(event, listener):this
NameTypeOptionalDescription
eventKNoNone
listener(...args: ClientEvents[K]) => Awaitable<void>NoNone
once(event, listener):this
NameTypeOptionalDescription
eventKNoNone
listener(...args: ClientEvents[K]) => Awaitable<void>NoNone
removeAllListeners(event?):this
NameTypeOptionalDescription
eventKYesNone
toJSON():unknown