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
dataApplicationCommandPermissionsUpdateDataNoThe updated permissions
autoModerationActionExecution
Emitted whenever an auto moderation rule is triggered. This event requires the PermissionFlagsBits.ManageGuild permission.
NameTypeOptionalDescription
autoModerationActionExecutionAutoModerationActionExecutionNoThe data of the execution
autoModerationRuleCreate
Emitted whenever an auto moderation rule is created. This event requires the PermissionFlagsBits.ManageGuild permission.
NameTypeOptionalDescription
autoModerationRuleAutoModerationRuleNoThe created auto moderation rule
autoModerationRuleDelete
Emitted whenever an auto moderation rule is deleted. This event requires the PermissionFlagsBits.ManageGuild permission.
NameTypeOptionalDescription
autoModerationRuleAutoModerationRuleNoThe deleted auto moderation rule
autoModerationRuleUpdate
Emitted whenever an auto moderation rule gets updated. This event requires the PermissionFlagsBits.ManageGuild permission.
NameTypeOptionalDescription
oldAutoModerationRuleAutoModerationRule | nullNoThe auto moderation rule before the update
newAutoModerationRuleAutoModerationRuleNoThe auto moderation rule after the update
channelCreate
Emitted whenever a guild channel is created.
NameTypeOptionalDescription
channelGuildChannelNoThe channel that was created
channelDelete
Emitted whenever a channel is deleted.
NameTypeOptionalDescription
channelDMChannel | GuildChannelNoThe 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
channelTextBasedChannelsNoThe channel that the pins update occurred in
timeDateNoThe time of the pins update
channelUpdate
Emitted whenever a channel is updated - e.g. name change, topic change, channel type change.
NameTypeOptionalDescription
oldChannelDMChannel | GuildChannelNoThe channel before the update
newChannelDMChannel | GuildChannelNoThe channel after the update
debug
Emitted for general debugging information.
NameTypeOptionalDescription
infostringNoThe debug information
emojiCreate
Emitted whenever a custom emoji is created in a guild.
NameTypeOptionalDescription
emojiGuildEmojiNoThe emoji that was created
emojiDelete
Emitted whenever a custom emoji is deleted in a guild.
NameTypeOptionalDescription
emojiGuildEmojiNoThe emoji that was deleted
emojiUpdate
Emitted whenever a custom emoji is updated in a guild.
NameTypeOptionalDescription
oldEmojiGuildEmojiNoThe old emoji
newEmojiGuildEmojiNoThe new emoji
entitlementCreate
Emitted whenever an entitlement is created.
NameTypeOptionalDescription
entitlementEntitlementNoThe 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
entitlementEntitlementNoThe entitlement that was deleted
entitlementUpdate
Emitted whenever an entitlement is updated - i.e. when a user's subscription renews.
NameTypeOptionalDescription
oldEntitlementEntitlement | nullNoThe entitlement before the update
newEntitlementEntitlementNoThe 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
errorErrorNoThe error encountered
guildAuditLogEntryCreate
Emitted whenever a guild audit log entry is created.
NameTypeOptionalDescription
auditLogEntryGuildAuditLogsEntryNoThe entry that was created
guildGuildNoThe guild where the entry was created
guildAvailable
Emitted whenever a guild becomes available.
NameTypeOptionalDescription
guildGuildNoThe guild that became available
guildBanAdd
Emitted whenever a member is banned from a guild.
NameTypeOptionalDescription
banGuildBanNoThe ban that occurred
guildBanRemove
Emitted whenever a member is unbanned from a guild.
NameTypeOptionalDescription
banGuildBanNoThe ban that was removed
guildCreate
Emitted whenever the client joins a guild.
NameTypeOptionalDescription
guildGuildNoThe created guild
guildDelete
Emitted whenever a guild kicks the client or the guild is deleted/left.
NameTypeOptionalDescription
guildGuildNoThe guild that was deleted
guildIntegrationsUpdate
Emitted whenever a guild integration is updated
NameTypeOptionalDescription
guildGuildNoThe guild whose integrations were updated
guildMemberAdd
Emitted whenever a user joins a guild.
NameTypeOptionalDescription
memberGuildMemberNoThe member that has joined a guild
guildMemberAvailable
Emitted whenever a member becomes available.
NameTypeOptionalDescription
memberGuildMemberNoThe member that became available
guildMemberRemove
Emitted whenever a member leaves a guild, or is kicked.
NameTypeOptionalDescription
memberGuildMemberNoThe 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>NoThe members in the chunk
guildGuildNoThe guild related to the member chunk
chunkGuildMembersChunkNoProperties of the received chunk
guildMemberUpdate
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
Emitted whenever a guild scheduled event is created.
NameTypeOptionalDescription
guildScheduledEventGuildScheduledEventNoThe created guild scheduled event
guildScheduledEventDelete
Emitted whenever a guild scheduled event is deleted.
NameTypeOptionalDescription
guildScheduledEventGuildScheduledEventNoThe deleted guild scheduled event
guildScheduledEventUpdate
Emitted whenever a guild scheduled event gets updated.
NameTypeOptionalDescription
oldGuildScheduledEventGuildScheduledEvent | nullNoThe guild scheduled event object before the update
newGuildScheduledEventGuildScheduledEventNoThe guild scheduled event object after the update
guildScheduledEventUserAdd
Emitted whenever a user subscribes to a guild scheduled event
NameTypeOptionalDescription
guildScheduledEventGuildScheduledEventNoThe guild scheduled event
userUserNoThe user who subscribed
guildScheduledEventUserRemove
Emitted whenever a user unsubscribes from a guild scheduled event
NameTypeOptionalDescription
guildScheduledEventGuildScheduledEventNoThe guild scheduled event
userUserNoThe user who unsubscribed
guildUnavailable
Emitted whenever a guild becomes unavailable, likely due to a server outage.
NameTypeOptionalDescription
guildGuildNoThe guild that has become unavailable
guildUpdate
Emitted whenever a guild is updated - e.g. name change.
NameTypeOptionalDescription
oldGuildGuildNoThe guild before the update
newGuildGuildNoThe guild after the update
interactionCreate
Emitted when an interaction is created.
NameTypeOptionalDescription
interactionBaseInteractionNoThe interaction which was created
inviteCreate
Emitted when an invite is created. This event requires the PermissionFlagsBits.ManageChannels permission for the channel.
NameTypeOptionalDescription
inviteInviteNoThe invite that was created
inviteDelete
Emitted when an invite is deleted. This event requires the PermissionFlagsBits.ManageChannels permission for the channel.
NameTypeOptionalDescription
inviteInviteNoThe invite that was deleted
messageCreate
Emitted whenever a message is created.
NameTypeOptionalDescription
messageMessageNoThe created message
messageDelete
Emitted whenever a message is deleted.
NameTypeOptionalDescription
messageMessageNoThe deleted message
messageDeleteBulk
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
messagePollVoteAdd
Emitted whenever a user votes in a poll.
NameTypeOptionalDescription
pollAnswerPollAnswerNoThe answer that was voted on
userIdSnowflakeNoThe id of the user that voted
messagePollVoteRemove
Emitted whenever a user removes their vote in a poll.
NameTypeOptionalDescription
pollAnswerPollAnswerNoThe answer where the vote was removed
userIdSnowflakeNoThe id of the user that removed their vote
messageReactionAdd
Emitted whenever a reaction is added to a cached message.
NameTypeOptionalDescription
messageReactionMessageReactionNoThe reaction object
userUserNoThe user that applied the guild or reaction emoji
detailsMessageReactionEventDetailsNoDetails of adding the reaction
messageReactionRemove
Emitted whenever a reaction is removed from a cached message.
NameTypeOptionalDescription
messageReactionMessageReactionNoThe reaction object
userUserNoThe user whose emoji or reaction emoji was removed
detailsMessageReactionEventDetailsNoDetails of removing the reaction
messageReactionRemoveAll
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
Emitted when a bot removes an emoji reaction from a cached message.
NameTypeOptionalDescription
reactionMessageReactionNoThe reaction that was removed
messageUpdate
Emitted whenever a message is updated - e.g. embed or content change.
NameTypeOptionalDescription
oldMessageMessageNoThe message before the update
newMessageMessageNoThe message after the update
presenceUpdate
Emitted whenever a guild member's presence (e.g. status, activity) is changed.
NameTypeOptionalDescription
oldPresencePresence | nullNoThe presence before the update, if one at all
newPresencePresenceNoThe presence after the update
ready
Emitted when the client becomes ready to start working.
NameTypeOptionalDescription
clientClientNoThe client
roleCreate
Emitted whenever a role is created.
NameTypeOptionalDescription
roleRoleNoThe role that was created
roleDelete
Emitted whenever a guild role is deleted.
NameTypeOptionalDescription
roleRoleNoThe role that was deleted
roleUpdate
Emitted whenever a guild role is updated.
NameTypeOptionalDescription
oldRoleRoleNoThe role before the update
newRoleRoleNoThe role after the update
shardDisconnect
Emitted when a shard's WebSocket disconnects and will no longer reconnect.
NameTypeOptionalDescription
eventCloseEventNoThe WebSocket close event
idnumberNoThe shard id that disconnected
shardError
Emitted whenever a shard's WebSocket encounters a connection error.
NameTypeOptionalDescription
errorErrorNoThe encountered error
shardIdnumberNoThe shard that encountered this error
shardReady
Emitted when a shard turns ready.
NameTypeOptionalDescription
idnumberNoThe shard id that turned ready
unavailableGuildsSet<Snowflake> | nullNoSet of unavailable guild ids, if any
shardReconnecting
Emitted when a shard is attempting to reconnect or re-identify.
NameTypeOptionalDescription
idnumberNoThe shard id that is attempting to reconnect
shardResume
Emitted when a shard resumes successfully.
NameTypeOptionalDescription
idnumberNoThe shard id that resumed
replayedEventsnumberNoThe amount of replayed events
stageInstanceCreate
Emitted whenever a stage instance is created.
NameTypeOptionalDescription
stageInstanceStageInstanceNoThe created stage instance
stageInstanceDelete
Emitted whenever a stage instance is deleted.
NameTypeOptionalDescription
stageInstanceStageInstanceNoThe deleted stage instance
stageInstanceUpdate
Emitted whenever a stage instance gets updated - e.g. change in topic or privacy level
NameTypeOptionalDescription
oldStageInstanceStageInstance | nullNoThe stage instance before the update
newStageInstanceStageInstanceNoThe stage instance after the update
stickerCreate
Emitted whenever a custom sticker is created in a guild.
NameTypeOptionalDescription
stickerStickerNoThe sticker that was created
stickerDelete
Emitted whenever a custom sticker is deleted in a guild.
NameTypeOptionalDescription
stickerStickerNoThe sticker that was deleted
stickerUpdate
Emitted whenever a custom sticker is updated in a guild.
NameTypeOptionalDescription
oldStickerStickerNoThe old sticker
newStickerStickerNoThe new sticker
threadCreate
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
Emitted whenever a thread is deleted.
NameTypeOptionalDescription
threadThreadChannelNoThe 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>NoThe threads that were synced
guildGuildNoThe 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>NoThe members that were added
removedMembersCollection<Snowflake, ThreadMember>NoThe members that were removed
threadThreadChannelNoThe thread where members got updated
threadMemberUpdate
Emitted whenever the client user's thread member is updated.
NameTypeOptionalDescription
oldMemberThreadMemberNoThe member before the update
newMemberThreadMemberNoThe member after the update
threadUpdate
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
Emitted whenever a user starts typing in a channel.
NameTypeOptionalDescription
typingTypingNoThe 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
oldUserUserNoThe user before the update
newUserUserNoThe user after the update
voiceStateUpdate
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
Emitted for general warnings.
NameTypeOptionalDescription
infostringNoThe warning
webhooksUpdate
Emitted whenever a channel has its webhooks changed.
NameTypeOptionalDescription
channelTextChannel | NewsChannel | VoiceChannel | StageChannel | ForumChannel | MediaChannelNoThe 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 | MediaChannelNoThe 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
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
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
guildGuildResolvableNoThe 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
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.
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
inviteInviteResolvableNoInvite code or URL
optionsClientFetchInviteOptionsYesOptions for fetching the invite
Deprecated
fetchPremiumStickerPacks():ReturnType<Client['fetchStickerPacks']>
Use 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
idSnowflakeNoThe sticker's id
fetchStickerPacks(options):Promise<StickerPack>
Obtains the list of available sticker packs.
Returns
A collection of sticker packs, or a single sticker pack if a packId was provided
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);
Example
client.fetchStickerPacks({ packId: '751604115435421716' })
.then(pack => console.log(`Sticker pack name: ${pack.name}`))
.catch(console.error);
client.fetchStickerPacks({ packId: '751604115435421716' })
.then(pack => console.log(`Sticker pack name: ${pack.name}`))
.catch(console.error);
NameTypeOptionalDescription
options{ packId: Snowflake }NoOptions for fetching sticker packs
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
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.
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
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
Example
client.login('my token');
client.login('my token');
NameTypeOptionalDescription
tokenstringYesToken of the account to log in with
off(event, listener):this
NameTypeOptionalDescription
eventEventNoNone
listener(...args: ClientEvents[Event]) => voidNoNone
on(event, listener):this
NameTypeOptionalDescription
eventEventNoNone
listener(...args: ClientEvents[Event]) => voidNoNone
once(event, listener):this
NameTypeOptionalDescription
eventEventNoNone
listener(...args: ClientEvents[Event]) => voidNoNone
removeAllListeners(event?):this
NameTypeOptionalDescription
eventEventYesNone
toJSON():unknown