mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-17 12:03:31 +01:00
feat(ClientPresence): allow setting activity state (#9743)
* feat(ClientPresence): allow setting activity state * fix: add to map * feat: use name as fallback state
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const { GatewayOpcodes } = require('discord-api-types/v10');
|
const { GatewayOpcodes, ActivityType } = require('discord-api-types/v10');
|
||||||
const { Presence } = require('./Presence');
|
const { Presence } = require('./Presence');
|
||||||
const { DiscordjsTypeError, ErrorCodes } = require('../errors');
|
const { DiscordjsTypeError, ErrorCodes } = require('../errors');
|
||||||
|
|
||||||
@@ -51,11 +51,18 @@ class ClientPresence extends Presence {
|
|||||||
if (typeof activity.name !== 'string') {
|
if (typeof activity.name !== 'string') {
|
||||||
throw new DiscordjsTypeError(ErrorCodes.InvalidType, `activities[${i}].name`, 'string');
|
throw new DiscordjsTypeError(ErrorCodes.InvalidType, `activities[${i}].name`, 'string');
|
||||||
}
|
}
|
||||||
activity.type ??= 0;
|
|
||||||
|
activity.type ??= ActivityType.Playing;
|
||||||
|
|
||||||
|
if (activity.type === ActivityType.Custom && !activity.state) {
|
||||||
|
activity.state = activity.name;
|
||||||
|
activity.name = 'Custom Status';
|
||||||
|
}
|
||||||
|
|
||||||
data.activities.push({
|
data.activities.push({
|
||||||
type: activity.type,
|
type: activity.type,
|
||||||
name: activity.name,
|
name: activity.name,
|
||||||
|
state: activity.state,
|
||||||
url: activity.url,
|
url: activity.url,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -63,6 +70,7 @@ class ClientPresence extends Presence {
|
|||||||
data.activities.push(
|
data.activities.push(
|
||||||
...this.activities.map(a => ({
|
...this.activities.map(a => ({
|
||||||
name: a.name,
|
name: a.name,
|
||||||
|
state: a.state ?? undefined,
|
||||||
type: a.type,
|
type: a.type,
|
||||||
url: a.url ?? undefined,
|
url: a.url ?? undefined,
|
||||||
})),
|
})),
|
||||||
|
|||||||
@@ -99,6 +99,7 @@ class ClientUser extends User {
|
|||||||
* Options for setting activities
|
* Options for setting activities
|
||||||
* @typedef {Object} ActivitiesOptions
|
* @typedef {Object} ActivitiesOptions
|
||||||
* @property {string} name Name of the activity
|
* @property {string} name Name of the activity
|
||||||
|
* @property {string} [state] State of the activity
|
||||||
* @property {ActivityType} [type] Type of the activity
|
* @property {ActivityType} [type] Type of the activity
|
||||||
* @property {string} [url] Twitch / YouTube stream URL
|
* @property {string} [url] Twitch / YouTube stream URL
|
||||||
*/
|
*/
|
||||||
@@ -150,6 +151,7 @@ class ClientUser extends User {
|
|||||||
* Options for setting an activity.
|
* Options for setting an activity.
|
||||||
* @typedef {Object} ActivityOptions
|
* @typedef {Object} ActivityOptions
|
||||||
* @property {string} name Name of the activity
|
* @property {string} name Name of the activity
|
||||||
|
* @property {string} [state] State of the activity
|
||||||
* @property {string} [url] Twitch / YouTube stream URL
|
* @property {string} [url] Twitch / YouTube stream URL
|
||||||
* @property {ActivityType} [type] Type of the activity
|
* @property {ActivityType} [type] Type of the activity
|
||||||
* @property {number|number[]} [shardId] Shard Id(s) to have the activity set on
|
* @property {number|number[]} [shardId] Shard Id(s) to have the activity set on
|
||||||
|
|||||||
3
packages/discord.js/typings/index.d.ts
vendored
3
packages/discord.js/typings/index.d.ts
vendored
@@ -4323,8 +4323,9 @@ export type ActivitiesOptions = Omit<ActivityOptions, 'shardId'>;
|
|||||||
|
|
||||||
export interface ActivityOptions {
|
export interface ActivityOptions {
|
||||||
name: string;
|
name: string;
|
||||||
|
state?: string;
|
||||||
url?: string;
|
url?: string;
|
||||||
type?: Exclude<ActivityType, ActivityType.Custom>;
|
type?: ActivityType;
|
||||||
shardId?: number | readonly number[];
|
shardId?: number | readonly number[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user