Reputation: 83
I'm trying to create a command for my bot in Discord JS that when triggered, takes the command's mentioned user and retrieves their current game (If no game, then status) and sends a message saying Mentioned user has been playing Game for Time elapsed (And if possible, send the image of the game if it has one).
This is my current code:
module.exports = {
name: 'game',
aliases: ['gm', 'status'],
category: 'Commands',
utilisation: '{prefix}game',
execute(client, message) {
let msgMention = message.mentions.members.first() || message.guild.member(message.author)
console.log(msgMention.presence.activities[0])
message.channel.send(msgMention.presence.activities[0].name);
},
};
All it does with the .name
extension says name is undefined and if I remove .name
it says cannot send an empty message. Also, I mention myself currently playing a game that so shown publicly on my discord activity status. What can I do so it actually reads the name and time of the activity to then send it?
Upvotes: 2
Views: 325
Reputation: 61
You need the GUILD_PRESENCES
intent.
const { Client, Intents } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MEMBERS, Intents.FLAGS.GUILD_PRESENCES] });
Also btw I'd recommend using message.member
instead of message.guild.member(message.author)
let msgMention = message.mentions.members.first() || message.member
Upvotes: 2