How can I get what a user is playing on discord?

987 Views Asked by At

I'm trying to make a bot (as a joke) that kicks a user when they're playing an specific game, I've been trying to use presence, but can't figure it out.

client.on('presenceUpdate', (oldPresence, newPresence) => {
let member = newPresence.member;

if (newPresence != null){
    if (newPresence == 'osu!'){
     member.kick();
    }
}
});

This is very barebones, but I need to now what to do next.

1

There are 1 best solutions below

4
newbNox On

First of all newPresence does not return game value as you are trying to do with newPresence == 'osu!', so it will turn out false everything, also newPresence is not string so that is wrong also..

To check what games user is playing or their activity you would need to check

if(newPresence.activities[0].type == 'PLAYING'){
    if(newPresence.activities[0].name == 'osu!'){
        //do stuff
    }
}

The above code is a sample, probs won't even work but you need to check stuff, for example activities might be even null if there is no activity. Please check docs of DiscordJS to better understand presences