Home > Enterprise >  Im trying to make a discord bot that checks if a user is playing a specific game
Im trying to make a discord bot that checks if a user is playing a specific game

Time:01-23

I am using discord.js 14.7.1. I also cant find any fixes with the official documentation.

I tried using the presenceUpdate event put it somehow doesnt work.

CodePudding user response:

First you have to get the current user by fetching it with his specific ID. Afterwards you have to checkout the Discord.Js Documentation at Presence. Following the Activites you see the prop '.name' (The activity's name).

I don't know how you want to use the status, but i can provide you a example for checking the Status and Activity of the specific user for the bot login:

const Discord = require("discord.js");
const client = new Discord.Client();
const token = "";
client.on("ready", () => {
  console.log("ready");
  const guild = client.guilds.cache.get(GUILD_ID); // Replace with the ID of the guild
  guild.members
    .fetch(USER_ID) // Replace with the ID of the specific User
    .then((member) => {
      if (
        member.presence.activities &&
        member.presence.activities.state === "PLAYING"
      ) {
        console.log(
          `${member.user.tag} is currently playing ${member.presence.activities.name}`
        );
      } else if (member.presence.status) {
        console.log(
          `${member.user.tag} is not currently playing a game, Status: ${member.presence.status}`
        );
      } else {
        console.log(`${member.user.tag} is not currently playing a game`);
      }
    })
    .catch(console.error);
});

client.login(token);
  • Related