class Client
extends
BaseClientexport class Client<Ready extends boolean = boolean> extends BaseClient
The main hub for interacting with the Discord API, and the starting point for any bot.
Constructors
options: ClientOptions)
constructor(If<Ready, ClientApplication> application :
The application of this bot
ChannelManager channels :
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.
readonlyBaseGuildEmojiManager emojis :
All custom emojis that the client has access to, mapped by their ids
GuildManager guilds :
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
Omit<ClientOptions, 'intents'> & { intents: IntentsBitField } options :
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)
ShardClientUtil | null shard :
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
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.
How long it has been since the client last entered the Ready state in milliseconds
If<Ready, ClientUser> user :
User that the client is logged in as
UserManager users :
All of the User objects that have been cached at any point, mapped by their ids
ClientVoiceManager voice :
The voice manager of the client
WebSocketManager ws :
The WebSocket manager of the client
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
autoModerationActionExecution(autoModerationActionExecution: AutoModerationActionExecution)
Emitted whenever an auto moderation rule is triggered. This event requires the PermissionFlagsBits permission.
autoModerationRuleCreate(autoModerationRule: AutoModerationRule)
Emitted whenever an auto moderation rule is created. This event requires the PermissionFlagsBits permission.
autoModerationRuleDelete(autoModerationRule: AutoModerationRule)
Emitted whenever an auto moderation rule is deleted. This event requires the PermissionFlagsBits permission.
autoModerationRuleUpdate(oldAutoModerationRule: AutoModerationRulenewAutoModerationRule: AutoModerationRule)
Emitted whenever an auto moderation rule gets updated. This event requires the PermissionFlagsBits permission.
channelCreate(channel: GuildChannel)
Emitted whenever a guild channel is created.
channelDelete(channel: DMChannel | GuildChannel)
Emitted whenever a channel is deleted.
channelPinsUpdate(channel: TextBasedChannelstime: Date)
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.
channelUpdate(oldChannel: DMChannel | GuildChannelnewChannel: DMChannel | GuildChannel)
Emitted whenever a channel is updated - e.g. name change, topic change, channel type change.
debug(info: string)
Emitted for general debugging information.
emojiCreate(emoji: GuildEmoji)
Emitted whenever a custom emoji is created in a guild.
emojiDelete(emoji: GuildEmoji)
Emitted whenever a custom emoji is deleted in a guild.
emojiUpdate(oldEmoji: GuildEmojinewEmoji: GuildEmoji)
Emitted whenever a custom emoji is updated in a guild.
error(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.
guildAuditLogEntryCreate(auditLogEntry: GuildAuditLogsEntryguild: Guild)
Emitted whenever a guild audit log entry is created.
guildAvailable(guild: Guild)
Emitted whenever a guild becomes available.
guildBanAdd(ban: GuildBan)
Emitted whenever a member is banned from a guild.
guildBanRemove(ban: GuildBan)
Emitted whenever a member is unbanned from a guild.
guildCreate(guild: Guild)
Emitted whenever the client joins a guild.
guildDelete(guild: Guild)
Emitted whenever a guild kicks the client or the guild is deleted/left.
guildIntegrationsUpdate(guild: Guild)
Emitted whenever a guild integration is updated
guildMemberAdd(member: GuildMember)
Emitted whenever a user joins a guild.
guildMemberAvailable(member: GuildMember)
Emitted whenever a member becomes available.
guildMemberRemove(member: GuildMember)
Emitted whenever a member leaves a guild, or is kicked.
Emitted whenever a chunk of guild members is received (all members come from the same guild).
guildMemberUpdate(oldMember: GuildMembernewMember: GuildMember)
Emitted whenever a guild member changes - i.e. new role, removed role, nickname.
guildScheduledEventCreate(guildScheduledEvent: GuildScheduledEvent)
Emitted whenever a guild scheduled event is created.
guildScheduledEventDelete(guildScheduledEvent: GuildScheduledEvent)
Emitted whenever a guild scheduled event is deleted.
guildScheduledEventUpdate(oldGuildScheduledEvent: GuildScheduledEventnewGuildScheduledEvent: GuildScheduledEvent)
Emitted whenever a guild scheduled event gets updated.
guildScheduledEventUserAdd(guildScheduledEvent: GuildScheduledEventuser: User)
Emitted whenever a user subscribes to a guild scheduled event
guildScheduledEventUserRemove(guildScheduledEvent: GuildScheduledEventuser: User)
Emitted whenever a user unsubscribes from a guild scheduled event
guildUnavailable(guild: Guild)
Emitted whenever a guild becomes unavailable, likely due to a server outage.
interactionCreate(interaction: BaseInteraction)
Emitted when an interaction is created.
inviteCreate(invite: Invite)
Emitted when an invite is created. This event requires the PermissionFlagsBits permission for the channel.
inviteDelete(invite: Invite)
Emitted when an invite is deleted. This event requires the PermissionFlagsBits permission for the channel.
messageCreate(message: Message)
Emitted whenever a message is created.
messageDelete(message: Message)
Emitted whenever a message is deleted.
messageDeleteBulk(messages: Collection<Snowflake, Message>channel: GuildTextBasedChannel)
Emitted whenever messages are deleted in bulk.
messageReactionAdd(messageReaction: MessageReactionuser: User)
Emitted whenever a reaction is added to a cached message.
messageReactionRemove(messageReaction: MessageReactionuser: User)
Emitted whenever a reaction is removed from a cached message.
messageReactionRemoveAll(message: Messagereactions: Collection<(string|Snowflake), MessageReaction>)
Emitted whenever all reactions are removed from a cached message.
messageReactionRemoveEmoji(reaction: MessageReaction)
Emitted when a bot removes an emoji reaction from a cached message.
Emitted whenever a message is updated - e.g. embed or content change.
Emitted whenever a guild member's presence (e.g. status, activity) is changed.
ready(client: Client)
Emitted when the client becomes ready to start working.
roleCreate(role: Role)
Emitted whenever a role is created.
roleDelete(role: Role)
Emitted whenever a guild role is deleted.
shardDisconnect(event: CloseEventid: number)
Emitted when a shard's WebSocket disconnects and will no longer reconnect.
Emitted whenever a shard's WebSocket encounters a connection error.
shardReconnecting(id: number)
Emitted when a shard is attempting to reconnect or re-identify.
stageInstanceCreate(stageInstance: StageInstance)
Emitted whenever a stage instance is created.
stageInstanceDelete(stageInstance: StageInstance)
Emitted whenever a stage instance is deleted.
stageInstanceUpdate(oldStageInstance: StageInstancenewStageInstance: StageInstance)
Emitted whenever a stage instance gets updated - e.g. change in topic or privacy level
stickerCreate(sticker: Sticker)
Emitted whenever a custom sticker is created in a guild.
stickerDelete(sticker: Sticker)
Emitted whenever a custom sticker is deleted in a guild.
Emitted whenever a custom sticker is updated in a guild.
threadCreate(thread: ThreadChannelnewlyCreated: boolean)
Emitted whenever a thread is created or when the client user is added to a thread.
threadDelete(thread: ThreadChannel)
Emitted whenever a thread is deleted.
threadListSync(threads: Collection<Snowflake, ThreadChannel>guild: Guild)
Emitted whenever the client user gains access to a text or news channel that contains threads
threadMembersUpdate(addedMembers: Collection<Snowflake, ThreadMember>removedMembers: Collection<Snowflake, ThreadMember>thread: ThreadChannel)
Emitted whenever members are added or removed from a thread. This event requires the GatewayIntentBits privileged gateway intent.
threadMemberUpdate(oldMember: ThreadMembernewMember: ThreadMember)
Emitted whenever the client user's thread member is updated.
threadUpdate(oldThread: ThreadChannelnewThread: ThreadChannel)
Emitted whenever a thread is updated - e.g. name change, archive state change, locked state change.
typingStart(typing: Typing)
Emitted whenever a user starts typing in a channel.
Emitted whenever a user's details (e.g. username) are changed. Triggered by the Discord gateway events UserUpdate, GuildMemberUpdate, and PresenceUpdate.
voiceStateUpdate(oldState: VoiceStatenewState: VoiceState)
Emitted whenever a member changes voice state - e.g. joins/leaves a channel, mutes/unmutes.
warn(info: string)
Emitted for general warnings.
webhooksUpdate(channel: TextChannel | NewsChannel | VoiceChannel | StageChannel | ForumChannel | MediaChannel)
Emitted whenever a channel has its webhooks changed.
deprecated webhookUpdate(channel: TextChannel | NewsChannel | VoiceChannel | StageChannel | ForumChannel | MediaChannel)
Use webhooksUpdate instead.
Emitted whenever a channel has its webhooks changed.
deleteWebhookid: Snowflakeoptions?: WebhookDeleteOptions) : Promise<void> (
Deletes a webhook.
emitEvent extends keyof ClientEvents
>(event: Event...args: ClientEvents[Event]) : boolean <
Event extends keyof ClientEvents
fetchGuildPreviewguild: GuildResolvable) : Promise<GuildPreview> (
Obtains a guild preview from Discord, available for all guilds the bot is in and all Discoverable guilds.
fetchGuildTemplatetemplate: GuildTemplateResolvable) : Promise<GuildTemplate> (
Obtains a template from Discord.
client.fetchGuildTemplate('https://discord.new/FKvmczH2HyUf')
.then(template => console.log(`Obtained template with code: ${template.code}`))
.catch(console.error);
fetchGuildWidgetguild: GuildResolvable) : Promise<Widget> (
Obtains the widget data of a guild from Discord, available for guilds with the widget enabled.
fetchInviteinvite: InviteResolvableoptions?: ClientFetchInviteOptions) : Promise<Invite> (
Obtains an invite from Discord.
client.fetchInvite('https://discord.gg/djs')
.then(invite => console.log(`Obtained invite with code: ${invite.code}`))
.catch(console.error);
deprecated fetchPremiumStickerPacksReturnType<Client['fetchStickerPacks']> () :
Use fetchStickerPacks instead.
Obtains the list of available sticker packs.
Obtains a sticker from Discord.
client.fetchSticker('id')
.then(sticker => console.log(`Obtained sticker with name: ${sticker.name}`))
.catch(console.error);
fetchStickerPacksPromise<Collection<Snowflake, StickerPack>> () :
Obtains the list of available sticker packs.
client.fetchStickerPacks()
.then(packs => console.log(`Available sticker packs are: ${packs.map(pack => pack.name).join(', ')}`))
.catch(console.error);
fetchVoiceRegionsPromise<Collection<string, VoiceRegion>> () :
Obtains the available voice regions from Discord.
client.fetchVoiceRegions()
.then(regions => console.log(`Available regions are: ${regions.map(region => region.name).join(', ')}`))
.catch(console.error);
Obtains a webhook from Discord.
client.fetchWebhook('id', 'token')
.then(webhook => console.log(`Obtained webhook with name: ${webhook.name}`))
.catch(console.error);
generateInviteoptions?: InviteGenerationOptions) : string (
Generates a link that can be used to invite the bot to a guild.
const link = client.generateInvite({
scopes: [OAuth2Scopes.ApplicationsCommands],
});
console.log(`Generated application invite link: ${link}`);
const link = client.generateInvite({
permissions: [
PermissionFlagsBits.SendMessages,
PermissionFlagsBits.ManageGuild,
PermissionFlagsBits.MentionEveryone,
],
scopes: [OAuth2Scopes.Bot],
});
console.log(`Generated bot invite link: ${link}`);
isReadythis is Client<true> () :
Returns whether the client has logged in, indicative of being able to access properties such as user
and application
.
Logs the client in, establishing a WebSocket connection to Discord.
client.login('my token');
Returns: Token of the account used