0

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 Answers1

0

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

newbNox
  • 1,000
  • 2
  • 15
  • 25
  • Thank you, it worked! But it only works before the game is running, not while is running, do you know how can I fix that? – Hector Diaz Feb 06 '22 at 23:06
  • I'm not sure what you mean by that? – newbNox Feb 07 '22 at 04:36
  • Let's say someone is already playing and then I run the bot, it doesn't work. But if I run the bot before that user starts playing, then the bot does work. – Hector Diaz Feb 07 '22 at 06:54
  • `presenceUpdate` event is only triggered when presence is updated, so if the bot starts up and someone is playing already, the event won't trigger. If you want to check if users are playing for example already when you start up the bot, you should utilise the `ready` event which is triggered once bot is booted up, and for example loop through all members and check if they are playing – newbNox Feb 07 '22 at 07:02