Status Checking

I am starting this project from scratch and a new dev, I am wondering how I can make my bot (from my user id) obtain my presence and status and print it. For example, if i am on Do not Disturb and I am listening to spotify. it will print:
teenxdom: dnd, listening to spotify
teenxdom: dnd, listening to spotify
17 Replies
d.js toolkit
d.js toolkit6mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
d.js docs
d.js docs6mo ago
:property: GuildMember#presence @14.15.3 The presence of this guild member
Mark
Mark6mo ago
all of the data you want is included in a member's presence data, linked above. it requires the privileged GuildPresences intent to access
teenxdom
teenxdomOP6mo ago
Alright thank you it keeps saying my presence is undefined
Mark
Mark6mo ago
Show code
teenxdom
teenxdomOP6mo ago
let me find it agian
const { Client, GatewayIntentBits} = require('discord.js');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildPresences,
],
});


const channelId = '1242672359760990258';
const messageId = '1257535916067786752';

async function checkStatus() {
const userId = '240066558829920256';
try {
const channel = await client.channels.fetch(channelId);
const message = await channel.messages.fetch(messageId);
const author = message.author;
const status = message.author.presence
console.log(`${status}`)
console.log(`The author of the message with ID ${messageId} is ${author.tag}`);
} catch (error) {
console.error('Error fetching message:', error);
}
}

client.once('ready', () => {
console.log('Bot is ready!');
checkStatus();
setInterval(checkStatus, 6000);
});

// Replace with your bot token
const token = 'example';
client.login(token);
const { Client, GatewayIntentBits} = require('discord.js');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildPresences,
],
});


const channelId = '1242672359760990258';
const messageId = '1257535916067786752';

async function checkStatus() {
const userId = '240066558829920256';
try {
const channel = await client.channels.fetch(channelId);
const message = await channel.messages.fetch(messageId);
const author = message.author;
const status = message.author.presence
console.log(`${status}`)
console.log(`The author of the message with ID ${messageId} is ${author.tag}`);
} catch (error) {
console.error('Error fetching message:', error);
}
}

client.once('ready', () => {
console.log('Bot is ready!');
checkStatus();
setInterval(checkStatus, 6000);
});

// Replace with your bot token
const token = 'example';
client.login(token);
@Mark
Amgelo
Amgelo6mo ago
* channels are cached, you don't need to fetch them * you're using message.author, which returns a User. as Mark linked, the presence data is in the GuildMember instead. use Message#member do consider that member will be null if the message wasn't sent on a guild
teenxdom
teenxdomOP6mo ago
It was sent in a guild Do I do message.member.presence?
Amgelo
Amgelo6mo ago
yeah, I think that'll work
teenxdom
teenxdomOP6mo ago
Alright I’ll try that soon
Amgelo
Amgelo6mo ago
if not you could try force fetching it but I don't recall if that was needed for presences
teenxdom
teenxdomOP6mo ago
Idek how to do that
d.js docs
d.js docs6mo ago
:method: GuildMember#fetch @14.15.3 Fetches this GuildMember.
teenxdom
teenxdomOP6mo ago
i got message.member.presence.status to show dnd but i cant figure out how to show the activity which in this case is spotify if i do message.member.presence.activity it says undefined wait i got it its activityies
teenxdom
teenxdomOP6mo ago
do you know how i would make it filter to only do 1 of the activities and that being the first one.
No description
d.js docs
d.js docs6mo ago
:mdn: Array The Array object, as with arrays in other programming languages, enables storing a collection of multiple items under a single variable name, and has members for performing common array operations.
teenxdom
teenxdomOP6mo ago
@Amgelo thank you so much, im just wondering is there anyway to get the details of an activity? for example if i want it to say Listening to spotify, then the track name
Want results from more Discord servers?
Add your server