Skip to content

Commit

Permalink
fix(ClientPresence): produce valid activities for set presences (#5799)
Browse files Browse the repository at this point in the history
  • Loading branch information
SpaceEEC committed Jun 10, 2021
1 parent 68f7aeb commit ea0e06f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
16 changes: 9 additions & 7 deletions src/structures/ClientPresence.js
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/structures/ClientUser.js
Expand Up @@ -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 });
Expand Down

0 comments on commit ea0e06f

Please sign in to comment.