diff --git a/src/structures/ClientPresence.js b/src/structures/ClientPresence.js index adba78f3e..90d1cb4a2 100644 --- a/src/structures/ClientPresence.js +++ b/src/structures/ClientPresence.js @@ -8,7 +8,7 @@ class ClientPresence extends Presence { super(client, Object.assign(data, { status: 'online', user: { id: null } })); } - async setClientPresence(presence) { + async set(presence) { const packet = await this._parse(presence); this.patch(packet); this.client.ws.send({ op: OPCodes.STATUS_UPDATE, d: packet }); diff --git a/src/structures/ClientUser.js b/src/structures/ClientUser.js index 8d35765d9..05d0794f8 100644 --- a/src/structures/ClientUser.js +++ b/src/structures/ClientUser.js @@ -97,7 +97,7 @@ class ClientUser extends Structures.get('User') { * .catch(console.error); */ setPresence(data) { - return this.client.presence.setClientPresence(data); + return this.client.presence.set(data); } /** @@ -123,12 +123,18 @@ class ClientUser extends Structures.get('User') { return this.setPresence({ status }); } + /** + * Options for setting an activity + * @typedef ActivityOptions + * @type {Object} + * @property {string} [url] Twitch stream URL + * @property {ActivityType|number} [type] Type of the activity + */ + /** * Sets the activity the client user is playing. - * @param {?string} name Activity being played - * @param {Object} [options] Options for setting the activity - * @param {string} [options.url] Twitch stream URL - * @param {ActivityType|number} [options.type] Type of the activity + * @param {string|ActivityOptions} [name] Activity being played, or options for setting the activity + * @param {ActivityOptions} [options] Options for setting the activity * @returns {Promise} * @example * // Set the client user's activity @@ -136,11 +142,11 @@ class ClientUser extends Structures.get('User') { * .then(presence => console.log(`Activity set to ${presence.game.name}`)) * .catch(console.error); */ - setActivity(name, { url, type } = {}) { + setActivity(name, options = {}) { if (!name) return this.setPresence({ activity: null }); - return this.setPresence({ - activity: { name, type, url }, - }); + + const activity = Object.assign({}, options, typeof name === 'object' ? name : { name }); + return this.setPresence({ activity }); } /** diff --git a/typings/index.d.ts b/typings/index.d.ts index 6a2fe4bf1..2a570ec57 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -260,11 +260,18 @@ declare module 'discord.js' { public connectToWebSocket(token: string, resolve: Function, reject: Function): void; } + export interface ActivityOptions { + name?: string; + url?: string; + type?: ActivityType | number; + } + export class ClientUser extends User { public mfaEnabled: boolean; public verified: boolean; public createGroupDM(recipients: GroupDMRecipientOptions[]): Promise; - public setActivity(name: string, options?: { url?: string, type?: ActivityType | number }): Promise; + public setActivity(options?: ActivityOptions): Promise; + public setActivity(name: string, options?: ActivityOptions): Promise; public setAFK(afk: boolean): Promise; public setAvatar(avatar: BufferResolvable | Base64Resolvable): Promise; public setPresence(data: PresenceData): Promise;