1

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);
Ituriel
  • 75
  • 2
  • 9
  • have you tried to `console.log(member.presence.activities)` to see if the member actually has an activity? – Worthy Alpaca Jan 22 '21 at 19:24
  • Yes. it is returning an empty array, even if I have an activity displayed on discord... – Ituriel Jan 22 '21 at 20:34
  • that looks like an issue with privileged intents. See if [this](https://stackoverflow.com/questions/64739350/discord-js-bot-welcomes-member-assign-a-role-and-send-them-a-dm/64739684#64739684) helps you – Worthy Alpaca Jan 22 '21 at 23:04

1 Answers1

0

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?

Joe Moore
  • 2,031
  • 2
  • 8
  • 29
  • I already tried to console.log(memberActivities), but it's not returning 'user has no activity set', and it's still giving the 'cannot send empty message'. I really don't know what's wrong. – Ituriel Jan 22 '21 at 20:32