Cannot access to user.presence.activities in discord.js

1.5k Views Asked by At

I am coding a discord.js bot, and I'm trying to get the activity of an user (games he is playing, spotify things, etc.).

When I take a look at the documentation, I see a Presence class, and a .activities property, that is supposed to return an array of the user's activities.

However, I get the "Cannot send empty message" when I run my code, with an activity running.

Here is my actual code:

let member = message.users.mention.first || message.author;

message.channel.send(member.presence.activities);
1

There are 1 best solutions below

1
On

It is likely that the user has no activity and so the member.presence.activities returns null, therefore resulting in the empty message error.

To catch this, it is simple:

let member = message.users.mention.first || message.author;

let memberActivies = member.presence.activities;
if (!memberActivities) return message.channel.send(':x: User has no activity set'); 

message.channel.send(memberActivities); //sends the activities

Also, if the activities param is an array, surely you would have to select from the array using the normal syntax arr[0] for example?