Reputation: 41
i'm trying to create a bot that checks the activity status of a server's users and returns them. i'm having trouble actually retrieveing the activity status from the users and i don't even know if it's possible.
const Discord = require('discord.js');
const client = new Discord.Client();
const token ='nah';
const PREFIX = '//';
function Statuscheck() {
///Code for retrieval of the status check would go here
console.log('set');///So I know the timer works
}
client.on('ready', () =>{
console.log('Bot is running...');
})
client.on('ready', () =>{
setInterval(Statuscheck, 10000)//runs the check funtion evrey 10s to keep up to date
})
client.login(token);
Upvotes: 2
Views: 4281
Reputation: 2990
First of all, I do a for loop through all guilds on which the bot is on. In this loop I do another loop through all guildMembers. I push the status of every single guildMember
in a new Array which I add in an Object at the end of the loop.
Maybe this sounds really complicated but it isn't very complicated if you understand basics of Javascript.
(I wasn't sure if you want the status of the user (online/offline/dnd/idle) or the game status. If you want the game status, change the line status.push(m.user.presence.status)
to status.push(m.user.presence.game)
)
Try using the following code:
const Discord = require('discord.js');
const client = new Discord.Client();
const token = 'nah';
const PREFIX = '//';
async function statuscheck() {
const statusArray = {};
await client.guilds.array().forEach(async g => {
const status = [];
await g.members.array().forEach(m => {
status.push(m.user.presence.status);
});
statusArray[g.id] = status;
});
console.log('set'); // /So I know the timer works
return statusArray;
}
client.on('ready', () => {
console.log('Bot is running...');
});
client.on('ready', async client => {
setInterval(await statuscheck(client), 10000); // runs the check funtion evrey 10s to keep up to date
});
client.login(token);
Upvotes: 1