From ea0e06f9802fb57b41f471413b39ccd09546bb67 Mon Sep 17 00:00:00 2001 From: SpaceEEC Date: Thu, 10 Jun 2021 18:05:27 +0200 Subject: [PATCH] fix(ClientPresence): produce valid activities for set presences (#5799) --- src/structures/ClientPresence.js | 16 +++++++++------- src/structures/ClientUser.js | 2 +- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/structures/ClientPresence.js b/src/structures/ClientPresence.js index f32577b47c45..faf753dc824d 100644 --- a/src/structures/ClientPresence.js +++ b/src/structures/ClientPresence.js @@ -35,11 +35,7 @@ class ClientPresence extends Presence { since: typeof since === 'number' && !Number.isNaN(since) ? since : null, status: status || this.status, }; - if (activities === null) { - data.activities = null; - return data; - } - if (activities && activities.length) { + if (activities?.length) { for (const [i, activity] of activities.entries()) { if (typeof activity.name !== 'string') throw new TypeError('INVALID_TYPE', `activities[${i}].name`, 'string'); if (!activity.type) activity.type = 0; @@ -50,8 +46,14 @@ class ClientPresence extends Presence { url: activity.url, }); } - } else if ((status || afk || since) && this.activities.length) { - data.activities.push(...this.activities); + } else if (!activities && (status || afk || since) && this.activities.length) { + data.activities.push( + ...this.activities.map(a => ({ + name: a.name, + type: ActivityTypes.indexOf(a.type), + url: a.url ?? undefined, + })), + ); } return data; diff --git a/src/structures/ClientUser.js b/src/structures/ClientUser.js index 77fc783e3e90..79eae6463bc2 100644 --- a/src/structures/ClientUser.js +++ b/src/structures/ClientUser.js @@ -161,7 +161,7 @@ class ClientUser extends Structures.get('User') { * client.user.setActivity('discord.js', { type: 'WATCHING' }); */ setActivity(name, options = {}) { - if (!name) return this.setPresence({ activities: null, shardID: options.shardID }); + if (!name) return this.setPresence({ activities: [], shardID: options.shardID }); const activity = Object.assign({}, options, typeof name === 'object' ? name : { name }); return this.setPresence({ activities: [activity], shardID: activity.shardID });