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 :
The options the client was instantiated with
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
Inherited from: BaseClient
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
offEvent extends keyof ClientEvents
>(event: Eventlistener: (...args: ClientEvents[Event]) => void) : this <
Event extends keyof ClientEvents
onEvent extends keyof ClientEvents
>(event: Eventlistener: (...args: ClientEvents[Event]) => void) : this <
Event extends keyof ClientEvents
onceEvent extends keyof ClientEvents
>(event: Eventlistener: (...args: ClientEvents[Event]) => void) : this <
Event extends keyof ClientEvents
removeAllListenersEvent extends keyof ClientEvents
>(event?: Event) : this <
Event extends keyof ClientEvents
toJSONunknown () :
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
autoModerationActionExecutionautoModerationActionExecution: AutoModerationActionExecution) (
Emitted whenever an auto moderation rule is triggered. This event requires the PermissionFlagsBits.ManageGuild permission.
autoModerationRuleCreateautoModerationRule: AutoModerationRule) (
Emitted whenever an auto moderation rule is created. This event requires the PermissionFlagsBits.ManageGuild permission.
autoModerationRuleDeleteautoModerationRule: AutoModerationRule) (
Emitted whenever an auto moderation rule is deleted. This event requires the PermissionFlagsBits.ManageGuild permission.
autoModerationRuleUpdateoldAutoModerationRule: AutoModerationRulenewAutoModerationRule: AutoModerationRule) (
Emitted whenever an auto moderation rule gets updated. This event requires the PermissionFlagsBits.ManageGuild permission.
channelCreatechannel: GuildChannel) (
Emitted whenever a guild channel is created.
channelDeletechannel: DMChannel | GuildChannel) (
Emitted whenever a channel is deleted.
channelPinsUpdatechannel: 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.
channelUpdateoldChannel: DMChannel | GuildChannelnewChannel: DMChannel | GuildChannel) (
Emitted whenever a channel is updated - e.g. name change, topic change, channel type change.
debuginfo: string) (
Emitted for general debugging information.
emojiCreateemoji: GuildEmoji) (
Emitted whenever a custom emoji is created in a guild.
emojiDeleteemoji: GuildEmoji) (
Emitted whenever a custom emoji is deleted in a guild.
emojiUpdateoldEmoji: GuildEmojinewEmoji: GuildEmoji) (
Emitted whenever a custom emoji is updated in a guild.
entitlementCreateentitlement: Entitlement) (
Emitted whenever an entitlement is created.
entitlementDeleteentitlement: Entitlement) (
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.
entitlementUpdateoldEntitlement: EntitlementnewEntitlement: Entitlement) (
Emitted whenever an entitlement is updated - i.e. when a user's subscription renews.
errorerror: 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.
guildAuditLogEntryCreateauditLogEntry: GuildAuditLogsEntryguild: Guild) (
Emitted whenever a guild audit log entry is created.
guildAvailableguild: Guild) (
Emitted whenever a guild becomes available.
guildBanAddban: GuildBan) (
Emitted whenever a member is banned from a guild.
guildBanRemoveban: GuildBan) (
Emitted whenever a member is unbanned from a guild.
guildCreateguild: Guild) (
Emitted whenever the client joins a guild.
guildDeleteguild: Guild) (
Emitted whenever a guild kicks the client or the guild is deleted/left.
guildIntegrationsUpdateguild: Guild) (
Emitted whenever a guild integration is updated
guildMemberAddmember: GuildMember) (
Emitted whenever a user joins a guild.
guildMemberAvailablemember: GuildMember) (
Emitted whenever a member becomes available.
guildMemberRemovemember: 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).
guildMemberUpdateoldMember: GuildMembernewMember: GuildMember) (
Emitted whenever a guild member changes - i.e. new role, removed role, nickname.
guildScheduledEventCreateguildScheduledEvent: GuildScheduledEvent) (
Emitted whenever a guild scheduled event is created.
guildScheduledEventDeleteguildScheduledEvent: GuildScheduledEvent) (
Emitted whenever a guild scheduled event is deleted.
guildScheduledEventUpdateoldGuildScheduledEvent: GuildScheduledEventnewGuildScheduledEvent: GuildScheduledEvent) (
Emitted whenever a guild scheduled event gets updated.
guildScheduledEventUserAddguildScheduledEvent: GuildScheduledEventuser: User) (
Emitted whenever a user subscribes to a guild scheduled event
guildScheduledEventUserRemoveguildScheduledEvent: GuildScheduledEventuser: User) (
Emitted whenever a user unsubscribes from a guild scheduled event
guildUnavailableguild: Guild) (
Emitted whenever a guild becomes unavailable, likely due to a server outage.
interactionCreateinteraction: BaseInteraction) (
Emitted when an interaction is created.
inviteCreateinvite: Invite) (
Emitted when an invite is created. This event requires the PermissionFlagsBits.ManageChannels permission for the channel.
inviteDeleteinvite: Invite) (
Emitted when an invite is deleted. This event requires the PermissionFlagsBits.ManageChannels permission for the channel.
messageCreatemessage: Message) (
Emitted whenever a message is created.
messageDeletemessage: Message) (
Emitted whenever a message is deleted.
messageDeleteBulkmessages: Collection<Snowflake, Message>channel: GuildTextBasedChannel) (
Emitted whenever messages are deleted in bulk.
messagePollVoteAddpollAnswer: PollAnsweruserId: Snowflake) (
Emitted whenever a user votes in a poll.
messagePollVoteRemovepollAnswer: PollAnsweruserId: Snowflake) (
Emitted whenever a user removes their vote in a poll.
messageReactionAddmessageReaction: MessageReactionuser: User) (
Emitted whenever a reaction is added to a cached message.
messageReactionRemovemessageReaction: MessageReactionuser: User) (
Emitted whenever a reaction is removed from a cached message.
messageReactionRemoveAllmessage: Messagereactions: Collection<(string|Snowflake), MessageReaction>) (
Emitted whenever all reactions are removed from a cached message.
messageReactionRemoveEmojireaction: 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.
readyclient: Client) (
Emitted when the client becomes ready to start working.
roleCreaterole: Role) (
Emitted whenever a role is created.
roleDeleterole: Role) (
Emitted whenever a guild role is deleted.
shardDisconnectevent: CloseEventid: number) (
Emitted when a shard's WebSocket disconnects and will no longer reconnect.
Emitted whenever a shard's WebSocket encounters a connection error.
shardReconnectingid: number) (
Emitted when a shard is attempting to reconnect or re-identify.
stageInstanceCreatestageInstance: StageInstance) (
Emitted whenever a stage instance is created.
stageInstanceDeletestageInstance: StageInstance) (
Emitted whenever a stage instance is deleted.
stageInstanceUpdateoldStageInstance: StageInstancenewStageInstance: StageInstance) (
Emitted whenever a stage instance gets updated - e.g. change in topic or privacy level
stickerCreatesticker: Sticker) (
Emitted whenever a custom sticker is created in a guild.
stickerDeletesticker: Sticker) (
Emitted whenever a custom sticker is deleted in a guild.
Emitted whenever a custom sticker is updated in a guild.
threadCreatethread: ThreadChannelnewlyCreated: boolean) (
Emitted whenever a thread is created or when the client user is added to a thread.
threadDeletethread: ThreadChannel) (
Emitted whenever a thread is deleted.
threadListSyncthreads: Collection<Snowflake, ThreadChannel>guild: Guild) (
Emitted whenever the client user gains access to a text or news channel that contains threads
threadMembersUpdateaddedMembers: Collection<Snowflake, ThreadMember>removedMembers: Collection<Snowflake, ThreadMember>thread: ThreadChannel) (
Emitted whenever members are added or removed from a thread. This event requires the GatewayIntentBits.GuildMembers privileged gateway intent.
threadMemberUpdateoldMember: ThreadMembernewMember: ThreadMember) (
Emitted whenever the client user's thread member is updated.
threadUpdateoldThread: ThreadChannelnewThread: ThreadChannel) (
Emitted whenever a thread is updated - e.g. name change, archive state change, locked state change.
typingStarttyping: 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.
voiceStateUpdateoldState: VoiceStatenewState: VoiceState) (
Emitted whenever a member changes voice state - e.g. joins/leaves a channel, mutes/unmutes.
warninfo: string) (
Emitted for general warnings.
webhooksUpdatechannel: TextChannel | NewsChannel | VoiceChannel | StageChannel | ForumChannel | MediaChannel) (
Emitted whenever a channel has its webhooks changed.
deprecated webhookUpdatechannel: TextChannel | NewsChannel | VoiceChannel | StageChannel | ForumChannel | MediaChannel) (
Use webhooksUpdate instead.
Emitted whenever a channel has its webhooks changed.