mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
featt(ClientUser): allow options as first parameter to setActivity (#2890)
This commit is contained in:
@@ -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 });
|
||||
|
||||
@@ -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<Presence>}
|
||||
* @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 });
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
9
typings/index.d.ts
vendored
9
typings/index.d.ts
vendored
@@ -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<GroupDMChannel>;
|
||||
public setActivity(name: string, options?: { url?: string, type?: ActivityType | number }): Promise<Presence>;
|
||||
public setActivity(options?: ActivityOptions): Promise<Presence>;
|
||||
public setActivity(name: string, options?: ActivityOptions): Promise<Presence>;
|
||||
public setAFK(afk: boolean): Promise<Presence>;
|
||||
public setAvatar(avatar: BufferResolvable | Base64Resolvable): Promise<ClientUser>;
|
||||
public setPresence(data: PresenceData): Promise<Presence>;
|
||||
|
||||
Reference in New Issue
Block a user