const bot = require('./../bot');
const influx = require('./../../influx');
const request = require('request-promise-native');
let ingame;
let guild;
const updateIngame = async function(){
  if(!guild && !ingame)return;
  
  let playing = await request('http://localhost/v0/discord/online');
  playing = JSON.parse(playing);
  /*
  let playing = guild.members.filterArray(function (m) {
        if (m.presence.game && m.presence.game.name)
            if (m.presence.game.name.toLowerCase().includes("battlefield 2"))
                return m;
    });
  playing = playing.map(m => m.user.id);
  */
  //console.log(playing);
  let toRemove = ingame.members.filter(function (m){
      if(!playing.includes(m.user.id))
      {
        console.log("Not playing : "+ m.user.id)
        return m;
      }
    });
  await Promise.all(toRemove.map(async function(m){
      await m.removeRole(ingame);
   }));
   await Promise.all(playing.map(async function(m){
      if(m === "")return;
      const user = await bot.fetchUser(m);
      if(!user)return;
      const member = await guild.fetchMember(user);
      if(!member)return;
      if(!member.roles.get(ingame.id))
        await member.addRole(ingame);
   }));
  influx.writePoints([
          {
            measurement: 'statistics',
            fields: { count: playing.length},
            tags: {type:'ingame'}
          }
        ]).catch(console.log);
};
bot.on('ready',()=>{
    guild =  bot.guilds.get("184536578654339072");
    ingame = guild.roles.get("322233107489226764");
});
setInterval(updateIngame,5000)
/**
bot.on('presenceUpdate',async function(om,m){
    if(m.guild.id != guild.id) return;
    if (om.presence.game && om.presence.game.name)
            if (om.presence.game.name.toLowerCase().includes("battlefield 2"))
                await m.removeRole(ingame);
    if (m.presence.game && m.presence.game.name)
            if (m.presence.game.name.toLowerCase().includes("battlefield 2"))
                await m.addRole(ingame);
});
*/

@@ -1029,32 +1029,42 @@
 f(!user)return;%0A
+     try%7B%0A
       const memb
@@ -1193,32 +1193,126 @@
 ddRole(ingame);%0A
+     %7D%0A     catch((e)=%3E%7B%0A       console.log(user.tag+%22 is not a member of the guild%22)%0A     %7D)%0A
    %7D));%0A  influx

Create ingame.js