#How to set a bot's status to a game's player count?
52 messages · Page 1 of 1 (latest)
[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
hmm await seems to not be working!
You need to add async
(I believe: async (c) is correct)
?
I believe so.
oh well it still is giving me this error
var URL = await fetch("https://games.roblox.com/v1/games?universeIds=3561305983");
^^^^^
SyntaxError: await is only valid in async functions and the top level bodies of modules
Oh. Your set interval needs to be async instead
can you show me how to do that lol im not that good at js
I missed that you had it under setInterval
I believe you move the async before the "yellow" ()
Did that work?
kinda? it changed to
Ah... it's completely skipping over the setInterval..
oh
do you know how i could fix it 😅
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});
Also make sure ```js
var Players = URL.data.playing;
(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
hmm
its still this!
Okay, I suppose this could be cause of me.
URL.data.playing is undefined
Let me test some things..
well player count is constantly updating so
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;
}
ah its working thank you!
Your welcome! That array it returned didn't register into my mind until recently
lol
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
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
thank you so much!
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
got you