mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13: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';
|
||||
|
||||
const { GatewayOpcodes } = require('discord-api-types/v10');
|
||||
const { GatewayOpcodes, ActivityType } = require('discord-api-types/v10');
|
||||
const { Presence } = require('./Presence');
|
||||
const { DiscordjsTypeError, ErrorCodes } = require('../errors');
|
||||
|
||||
@@ -51,11 +51,18 @@ class ClientPresence extends Presence {
|
||||
if (typeof activity.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({
|
||||
type: activity.type,
|
||||
name: activity.name,
|
||||
state: activity.state,
|
||||
url: activity.url,
|
||||
});
|
||||
}
|
||||
@@ -63,6 +70,7 @@ class ClientPresence extends Presence {
|
||||
data.activities.push(
|
||||
...this.activities.map(a => ({
|
||||
name: a.name,
|
||||
state: a.state ?? undefined,
|
||||
type: a.type,
|
||||
url: a.url ?? undefined,
|
||||
})),
|
||||
|
||||
@@ -99,6 +99,7 @@ class ClientUser extends User {
|
||||
* Options for setting activities
|
||||
* @typedef {Object} ActivitiesOptions
|
||||
* @property {string} name Name of the activity
|
||||
* @property {string} [state] State of the activity
|
||||
* @property {ActivityType} [type] Type of the activity
|
||||
* @property {string} [url] Twitch / YouTube stream URL
|
||||
*/
|
||||
@@ -150,6 +151,7 @@ class ClientUser extends User {
|
||||
* Options for setting an activity.
|
||||
* @typedef {Object} ActivityOptions
|
||||
* @property {string} name Name of the activity
|
||||
* @property {string} [state] State of the activity
|
||||
* @property {string} [url] Twitch / YouTube stream URL
|
||||
* @property {ActivityType} [type] Type of the activity
|
||||
* @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 {
|
||||
name: string;
|
||||
state?: string;
|
||||
url?: string;
|
||||
type?: Exclude<ActivityType, ActivityType.Custom>;
|
||||
type?: ActivityType;
|
||||
shardId?: number | readonly number[];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user