#How to set a bot's status to a game's player count?

52 messages · Page 1 of 1 (latest)

ebon gorgeBOT
#

• What's your exact discord.js npm list discord.js and node node -v version?
• Post the full error stack trace, not just the top part!
• Show your code!
• Explain what exactly your issue is.
• Not a discord.js issue? Check out #useful-servers.

left tartan
unique kindle
# left tartan [email protected] v19.8.1

Shockingly is not a discord.js question.
Though.. I believe: js var url = await fetch("yoururlhere"); url = await url.json(); var players = url.data.playing;
will return your player count and you can use it from there.

#

(I was lazy to copy the url; but replacing "yoururlhere"will do it

left tartan
unique kindle
#

You need to add async
(I believe: async (c) is correct)

left tartan
unique kindle
#

I believe so.

left tartan
unique kindle
#

Oh. Your set interval needs to be async instead

left tartan
#

can you show me how to do that lol im not that good at js

unique kindle
#

I missed that you had it under setInterval

#

I believe you move the async before the "yellow" ()

#

Did that work?

left tartan
#

kinda? it changed to

unique kindle
#

Ah... it's completely skipping over the setInterval..

left tartan
#

oh

unique kindle
#

As you see, myFunc() is called last

left tartan
#

do you know how i could fix it 😅

unique kindle
#

I have no idea what you could do there. Maybe have it as a function and have the set interval have the function inside of it

#
async function gamePlayers() {
  var URL = await fetch("https://games.roblox.com/v1/games?universeIds=3561305983");
  URL = await URL.json();
  var Players = URL.data.playing;
  return Players;
}
var Players = await gamePlayers();
#

^ asuming you do this once and async (c) is there

#

or the setInterval has

setInterval(() => {
var Players = gamePlayers();
client.user.setActivity({
  name: "Impresso Espresso with " + Players,
  type: ActivityType.Watching,
}), 60000});
unique kindle
#

(As you made var url -> var URL)

#

yeesh I made a lot of typos

#

Personally I don't see how you could have it set in the interval

#

I guess you could have a case where if js !Players you have a different status

left tartan
#

hmm

left tartan
unique kindle
#

Okay, I suppose this could be cause of me.

#

URL.data.playing is undefined

#

Let me test some things..

left tartan
unique kindle
#

My mistake, it returns an array, thus ```js
URL.data[0].playing;

#

Bingo.

#

you can still have it as an set interval as well

#

My set interval I used

  setInterval(async () => {
    var Players = await gamePlayers();
    await client.user.setActivity({
    name: "Impresso Espresso with " + Players,
    type: ActivityType.Watching
}), 60000});
#

the function

async function gamePlayers() {
  var URL = await fetch("https://games.roblox.com/v1/games?universeIds=3561305983");
  URL = await URL.json();
  var Players = URL.data[0].playing;
  return Players;
}
left tartan
#

ah its working thank you!

unique kindle
#

Your welcome! That array it returned didn't register into my mind until recently

left tartan
#

btw do you know how to check if the Players is equal to 0 so that way i can add an "s" on "Impresso Espresso with 0 player", or else it would change to just an empty string var

#

hopefully that makes sense

unique kindle
#
  setInterval(async () => {
    var Players = await gamePlayers();
    var playerText;
    if(Players == 0 || Players > 1) {
      playerText = " players.";
    } else {
      playerText = " player.";
    }
    await client.user.setActivity({
    name: "Impresso Espresso with " + Players + playerText,
    type: ActivityType.Watching
}), 60000});

Should do the trick!

#

@left tartan

unique kindle
#

No problem!

#

And while I was waiting on stuff like that, I can finally get info from Twisted's stuff to idk, do some stuff and have fun with it

left tartan
#

got you