How can I get the activities
from interaction.options
? If I use interaction.options.getUser
, I receive the following error:
cannot read properties of undefined (reading 'activities')
Here is my code:
const user = interaction.options.getUser('target');
const activity = user.presence.activities.type;
User
s don't have a presence
property, only GuildMember
s have. What you can do is to fetch
the member by its ID first:
const user = interaction.options.getUser('target');
const member = await interaction.guild.members.fetch(user);
And then, you can get the activities
:
const activities = member.presence?.activities;
activities
returns an array of Activity
, so you'll need to grab the first one for example to log its type
:
console.log(activities[0]?.type)
Please note that you'll need to have the GUILDS
, GUILD_MEMBERS
, and GUILD_PRESENCES
intents enabled!