Skip to content

Commit 9ed1b59

Browse files
authored
feat(ClientPresence): allow setting activity state (#9743)
* feat(ClientPresence): allow setting activity state * fix: add to map * feat: use name as fallback state
1 parent 0a9a3ed commit 9ed1b59

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

packages/discord.js/src/structures/ClientPresence.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
const { GatewayOpcodes } = require('discord-api-types/v10');
3+
const { GatewayOpcodes, ActivityType } = require('discord-api-types/v10');
44
const { Presence } = require('./Presence');
55
const { DiscordjsTypeError, ErrorCodes } = require('../errors');
66

@@ -51,18 +51,26 @@ class ClientPresence extends Presence {
5151
if (typeof activity.name !== 'string') {
5252
throw new DiscordjsTypeError(ErrorCodes.InvalidType, `activities[${i}].name`, 'string');
5353
}
54-
activity.type ??= 0;
54+
55+
activity.type ??= ActivityType.Playing;
56+
57+
if (activity.type === ActivityType.Custom && !activity.state) {
58+
activity.state = activity.name;
59+
activity.name = 'Custom Status';
60+
}
5561

5662
data.activities.push({
5763
type: activity.type,
5864
name: activity.name,
65+
state: activity.state,
5966
url: activity.url,
6067
});
6168
}
6269
} else if (!activities && (status || afk || since) && this.activities.length) {
6370
data.activities.push(
6471
...this.activities.map(a => ({
6572
name: a.name,
73+
state: a.state ?? undefined,
6674
type: a.type,
6775
url: a.url ?? undefined,
6876
})),

packages/discord.js/src/structures/ClientUser.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ class ClientUser extends User {
9999
* Options for setting activities
100100
* @typedef {Object} ActivitiesOptions
101101
* @property {string} name Name of the activity
102+
* @property {string} [state] State of the activity
102103
* @property {ActivityType} [type] Type of the activity
103104
* @property {string} [url] Twitch / YouTube stream URL
104105
*/
@@ -150,6 +151,7 @@ class ClientUser extends User {
150151
* Options for setting an activity.
151152
* @typedef {Object} ActivityOptions
152153
* @property {string} name Name of the activity
154+
* @property {string} [state] State of the activity
153155
* @property {string} [url] Twitch / YouTube stream URL
154156
* @property {ActivityType} [type] Type of the activity
155157
* @property {number|number[]} [shardId] Shard Id(s) to have the activity set on

packages/discord.js/typings/index.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4323,8 +4323,9 @@ export type ActivitiesOptions = Omit<ActivityOptions, 'shardId'>;
43234323

43244324
export interface ActivityOptions {
43254325
name: string;
4326+
state?: string;
43264327
url?: string;
4327-
type?: Exclude<ActivityType, ActivityType.Custom>;
4328+
type?: ActivityType;
43284329
shardId?: number | readonly number[];
43294330
}
43304331

0 commit comments

Comments
 (0)