fix: Class constructor Activity cannot be invoked without 'presence'

#1203
This commit is contained in:
Elysia
2024-07-04 14:23:02 +07:00
parent 1540ff2ba3
commit f7bb7a4bdd
2 changed files with 7 additions and 1 deletions

View File

@@ -189,7 +189,7 @@ class ClientUserSettingManager extends BaseManager {
a => ![ActivityTypes.CUSTOM, 'CUSTOM'].includes(a.type), a => ![ActivityTypes.CUSTOM, 'CUSTOM'].includes(a.type),
); );
if (data.custom_status) { if (data.custom_status) {
const custom = new CustomStatus(); const custom = new CustomStatus(this.client);
custom.setState(data.custom_status.text); custom.setState(data.custom_status.text);
let emoji; let emoji;
if (data.custom_status.emoji_id) { if (data.custom_status.emoji_id) {

View File

@@ -175,6 +175,9 @@ class Presence extends Base {
*/ */
class Activity { class Activity {
constructor(presence, data) { constructor(presence, data) {
if (!(presence instanceof Presence)) {
throw new Error("Class constructor Activity cannot be invoked without 'presence'");
}
/** /**
* The presence of the Activity * The presence of the Activity
* @type {Presence} * @type {Presence}
@@ -628,6 +631,7 @@ class CustomStatus extends Activity {
* @param {CustomStatus|CustomStatusOptions} [data={}] CustomStatus to clone or raw data * @param {CustomStatus|CustomStatusOptions} [data={}] CustomStatus to clone or raw data
*/ */
constructor(client, data = {}) { constructor(client, data = {}) {
if (!client) throw new Error("Class constructor CustomStatus cannot be invoked without 'client'");
super('presence' in client ? client.presence : client, { super('presence' in client ? client.presence : client, {
name: 'Custom Status', name: 'Custom Status',
type: ActivityTypes.CUSTOM, type: ActivityTypes.CUSTOM,
@@ -677,6 +681,7 @@ class RichPresence extends Activity {
* @param {RichPresence} [data={}] RichPresence to clone or raw data * @param {RichPresence} [data={}] RichPresence to clone or raw data
*/ */
constructor(client, data = {}) { constructor(client, data = {}) {
if (!client) throw new Error("Class constructor RichPresence cannot be invoked without 'client'");
super('presence' in client ? client.presence : client, { type: 0, ...data }); super('presence' in client ? client.presence : client, { type: 0, ...data });
this.setup(data); this.setup(data);
} }
@@ -984,6 +989,7 @@ class SpotifyRPC extends RichPresence {
* @param {SpotifyRPC} [options] Options for the Spotify RPC * @param {SpotifyRPC} [options] Options for the Spotify RPC
*/ */
constructor(client, options = {}) { constructor(client, options = {}) {
if (!client) throw new Error("Class constructor SpotifyRPC cannot be invoked without 'client'");
super(client, { super(client, {
name: 'Spotify', name: 'Spotify',
type: ActivityTypes.LISTENING, type: ActivityTypes.LISTENING,