mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-19 21:13:30 +01:00
types(ClientPresence): add type declarations and docs (#6450)
This commit is contained in:
@@ -4,6 +4,10 @@ const { Presence } = require('./Presence');
|
|||||||
const { TypeError } = require('../errors');
|
const { TypeError } = require('../errors');
|
||||||
const { ActivityTypes, Opcodes } = require('../util/Constants');
|
const { ActivityTypes, Opcodes } = require('../util/Constants');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents the client's presence.
|
||||||
|
* @extends {Presence}
|
||||||
|
*/
|
||||||
class ClientPresence extends Presence {
|
class ClientPresence extends Presence {
|
||||||
/**
|
/**
|
||||||
* @param {Client} client The instantiating client
|
* @param {Client} client The instantiating client
|
||||||
@@ -13,6 +17,11 @@ class ClientPresence extends Presence {
|
|||||||
super(client, Object.assign(data, { status: data.status ?? 'online', user: { id: null } }));
|
super(client, Object.assign(data, { status: data.status ?? 'online', user: { id: null } }));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the client's presence
|
||||||
|
* @param {PresenceData} presence The data to set the presence to
|
||||||
|
* @returns {ClientPresence}
|
||||||
|
*/
|
||||||
set(presence) {
|
set(presence) {
|
||||||
const packet = this._parse(presence);
|
const packet = this._parse(presence);
|
||||||
this._patch(packet);
|
this._patch(packet);
|
||||||
@@ -28,6 +37,12 @@ class ClientPresence extends Presence {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses presence data into a packet ready to be sent to Discord
|
||||||
|
* @param {PresenceData} presence The data to parse
|
||||||
|
* @returns {APIPresence}
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
_parse({ status, since, afk, activities }) {
|
_parse({ status, since, afk, activities }) {
|
||||||
const data = {
|
const data = {
|
||||||
activities: [],
|
activities: [],
|
||||||
|
|||||||
@@ -33,8 +33,8 @@ class ClientUser extends User {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ClientUser's presence
|
* Represents the client user's presence
|
||||||
* @type {Presence}
|
* @type {ClientPresence}
|
||||||
* @readonly
|
* @readonly
|
||||||
*/
|
*/
|
||||||
get presence() {
|
get presence() {
|
||||||
@@ -109,7 +109,7 @@ class ClientUser extends User {
|
|||||||
/**
|
/**
|
||||||
* Sets the full presence of the client user.
|
* Sets the full presence of the client user.
|
||||||
* @param {PresenceData} data Data for the presence
|
* @param {PresenceData} data Data for the presence
|
||||||
* @returns {Presence}
|
* @returns {ClientPresence}
|
||||||
* @example
|
* @example
|
||||||
* // Set the client user's presence
|
* // Set the client user's presence
|
||||||
* client.user.setPresence({ activities: [{ name: 'with discord.js' }], status: 'idle' });
|
* client.user.setPresence({ activities: [{ name: 'with discord.js' }], status: 'idle' });
|
||||||
@@ -131,7 +131,7 @@ class ClientUser extends User {
|
|||||||
* Sets the status of the client user.
|
* Sets the status of the client user.
|
||||||
* @param {PresenceStatusData} status Status to change to
|
* @param {PresenceStatusData} status Status to change to
|
||||||
* @param {number|number[]} [shardId] Shard id(s) to have the activity set on
|
* @param {number|number[]} [shardId] Shard id(s) to have the activity set on
|
||||||
* @returns {Presence}
|
* @returns {ClientPresence}
|
||||||
* @example
|
* @example
|
||||||
* // Set the client user's status
|
* // Set the client user's status
|
||||||
* client.user.setStatus('idle');
|
* client.user.setStatus('idle');
|
||||||
@@ -153,7 +153,7 @@ class ClientUser extends User {
|
|||||||
* Sets the activity the client user is playing.
|
* Sets the activity the client user is playing.
|
||||||
* @param {string|ActivityOptions} [name] Activity being played, or options for setting the activity
|
* @param {string|ActivityOptions} [name] Activity being played, or options for setting the activity
|
||||||
* @param {ActivityOptions} [options] Options for setting the activity
|
* @param {ActivityOptions} [options] Options for setting the activity
|
||||||
* @returns {Presence}
|
* @returns {ClientPresence}
|
||||||
* @example
|
* @example
|
||||||
* // Set the client user's activity
|
* // Set the client user's activity
|
||||||
* client.user.setActivity('discord.js', { type: 'WATCHING' });
|
* client.user.setActivity('discord.js', { type: 'WATCHING' });
|
||||||
@@ -169,7 +169,7 @@ class ClientUser extends User {
|
|||||||
* Sets/removes the AFK flag for the client user.
|
* Sets/removes the AFK flag for the client user.
|
||||||
* @param {boolean} afk Whether or not the user is AFK
|
* @param {boolean} afk Whether or not the user is AFK
|
||||||
* @param {number|number[]} [shardId] Shard Id(s) to have the AFK flag set on
|
* @param {number|number[]} [shardId] Shard Id(s) to have the AFK flag set on
|
||||||
* @returns {Presence}
|
* @returns {ClientPresence}
|
||||||
*/
|
*/
|
||||||
setAFK(afk, shardId) {
|
setAFK(afk, shardId) {
|
||||||
return this.setPresence({ afk, shardId });
|
return this.setPresence({ afk, shardId });
|
||||||
|
|||||||
19
typings/index.d.ts
vendored
19
typings/index.d.ts
vendored
@@ -398,6 +398,7 @@ type If<T extends boolean, A, B = null> = T extends true ? A : T extends false ?
|
|||||||
export class Client<Ready extends boolean = boolean> extends BaseClient {
|
export class Client<Ready extends boolean = boolean> extends BaseClient {
|
||||||
public constructor(options: ClientOptions);
|
public constructor(options: ClientOptions);
|
||||||
private actions: unknown;
|
private actions: unknown;
|
||||||
|
private presence: ClientPresence;
|
||||||
private _eval(script: string): unknown;
|
private _eval(script: string): unknown;
|
||||||
private _validateOptions(options: ClientOptions): void;
|
private _validateOptions(options: ClientOptions): void;
|
||||||
|
|
||||||
@@ -468,16 +469,24 @@ export class ClientApplication extends Application {
|
|||||||
public fetch(): Promise<ClientApplication>;
|
public fetch(): Promise<ClientApplication>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class ClientPresence extends Presence {
|
||||||
|
public constructor(client: Client, data: RawPresenceData);
|
||||||
|
private _parse(data: PresenceData): RawPresenceData;
|
||||||
|
|
||||||
|
public set(presence: PresenceData): ClientPresence;
|
||||||
|
}
|
||||||
|
|
||||||
export class ClientUser extends User {
|
export class ClientUser extends User {
|
||||||
public mfaEnabled: boolean;
|
public mfaEnabled: boolean;
|
||||||
|
public readonly presence: ClientPresence;
|
||||||
public verified: boolean;
|
public verified: boolean;
|
||||||
public edit(data: ClientUserEditData): Promise<this>;
|
public edit(data: ClientUserEditData): Promise<this>;
|
||||||
public setActivity(options?: ActivityOptions): Presence;
|
public setActivity(options?: ActivityOptions): ClientPresence;
|
||||||
public setActivity(name: string, options?: ActivityOptions): Presence;
|
public setActivity(name: string, options?: ActivityOptions): ClientPresence;
|
||||||
public setAFK(afk: boolean, shardId?: number | number[]): Presence;
|
public setAFK(afk: boolean, shardId?: number | number[]): ClientPresence;
|
||||||
public setAvatar(avatar: BufferResolvable | Base64Resolvable): Promise<this>;
|
public setAvatar(avatar: BufferResolvable | Base64Resolvable): Promise<this>;
|
||||||
public setPresence(data: PresenceData): Presence;
|
public setPresence(data: PresenceData): ClientPresence;
|
||||||
public setStatus(status: PresenceStatusData, shardId?: number | number[]): Presence;
|
public setStatus(status: PresenceStatusData, shardId?: number | number[]): ClientPresence;
|
||||||
public setUsername(username: string): Promise<this>;
|
public setUsername(username: string): Promise<this>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user