#topgg-api
1 messages · Page 170 of 1
ight done thanks thanks 
Great!
When I update the server count in my bot's page via API, the count shows correctly for like 1-2 hours and then again the server count shows a wrong number
Caching, you need to actively post aswell
is there a way to know which package needs a specific dependence without checking litilery each one
?
most packages list their dependancies on npm
woo new pfp 👀
old pfp
Oh you mean I have to autopost like every 30 minutes
Yeah, it only updates when you update it(auto posting)
I need to use the top.gg api to get notified who voted for my bot
How can I
Please can someone say the process
I dont see your bot posting server counts https://top.gg/bot/857935418993410049
what programming language?
Python
https://docs.top.gg/libraries/python/ middle section covers webhooks.
What is webhook
...
With that can I see who voted for my bot?
webhooks are a way for top.gg to send vote events to your program
as you can see in the example, its just an event
So can I do this
I think it's not joined any server before the approve
yep, and youll need to fill in the url and auth in the webhook section of your bot(edit page)
we never pull server count, even before approval.
we only get it from posting it, which it doesn't appear you are doing.
oh ok I am sorry I didn't understand you at first
Url means the invite link of the bot?
nope, webhooks are like websites, you need a url to the one in your code(using the ip instead of a domain is fine).
where are you hosting? vps, heroku, replit, home?
Replit
your url will look something like
YOURHEROKUPROJECTURL/dblwebhook
Where will I get this url
https://docs.replit.com/hosting/hosting-web-pages
the replit docs cover it
Right
So here my url is in top right
yeah this
https://i.imgur.com/cWnhVwC.png
Ok
then add /dblwebhook to the end, as thats the default path
And here you told something about aouth
yeah, the auth needs to be the same here, and on the page you fill the url in.
https://i.imgur.com/xvbkhpM.png
Which auth where to get
you are the one who decides it
Wdym
its like a password, you are the one who chooses what it is.
So can I keep any??
yeah, anything you want
could just smash on your keyboard
jpOWJe90rDA9-0JDPASkD0Sa
perfect 🙂
Ok
But in the code where to put url and where to put auth
in code you do not put the url.
the auth is set here. https://i.imgur.com/xvbkhpM.png
But then what about url. We discussed this much about url. Where to use that
go to your bots page, click "edit", click "webhooks"
Edit section shows this
try a different browser
I am already using chrome
um i have a question for you api devs '-'
why when i made my first bot i couldn't add it to my server?
but when i made my second bot with the exact same way it instantly got added to my server without any issues :/
https://i.imgur.com/IbuhOik.png
you have this on
yes od course .-.
actually i think i only have it on in my first bot i didn't pay attention to it in the second one
lemme recheck that
yes as i said
so i should turn it off then!
unbelivable!!! that was the problem o.o
thanks alot bro really appreciate that, you're a good person 🙂
Oh
happened to me too my first time lol..
youll need to post the count using the api. https://docs.top.gg
...
Can't stop wandering,What's this used for anyway, like what's the purpose of it's existance? .-.
refresh cache
oh?
console.log(client.guilds.cache.size)
Also you can use the library wrapper for it
try using the lib instead
Your token could be invalid, that's the only cause
we do have ratelimits, but they would return a different error
I'm probably just to stupid to find it, but how does the webhook data look like? Like in which format and what parameters are getting send out?
I saw you are sending an Vote Object, what does that Object contain?
Thanks ❤️
State your issue
am new to it so i need to get started
You can find whatever you need in the docs
but what is it used for
A simple API wrapper for top.gg written in Python. Contribute to top-gg/python-sdk development by creating an account on GitHub.
have the cache.size return in a log
you dont get ratelimited for making a single request
it's something with passing the client.guilds.cache.size on your end
Pass the body like "{ 'server_count': 'yourguildcount'}"
Help, my webhook is not working
const express = require("express");
const DBL = require('@top-gg/sdk');
const webhook = new DBL.Webhook('here is my auth');
app.get('/dblwebhook', async (req, res) => {
res.send(`Top.gg API is currently working!`)
});
app.post('/dblwebhook', webhook.middleware(), async (req) => {
let credits = req.vote.isWeekend ? 2000 : 1000;
const apiUser = await fetch(`https://discord.com/api/v8/users/${req.vote.user}`, {
headers: { Authorization: `Bot (My Token)` }
}).then(res => res.json());
const msg = new Discord.MessageEmbed()
.setAuthor('Voting System')
.setColor('#7289DA')
.setTitle(`${apiUser.username} Just Voted`)
.setDescription(`Thank you **${apiUser.username}#${apiUser.discriminator}** (${apiUser.id}) for voting ****!`)
Hook.send(msg);
const userSettings = await User.findOne({ discordId: req.vote.user })
if (!userSettings) return User.create({ discordId: req.vote.user, votes: 1, lastVoted: Date.now() });
That's what I have, and it doesn't work
If you know what the error is or something please mention me, while I will try to find out what happens
have you tested it using a request client for example?
Thanks to that I have found the error, it is not the fault of the top gg api it was the discord api, it is already solved, thanks 🙂
does vote.user return the user's id?
is there any method from which we can find indivuadual votes for the server just like as how u have for the indivual bot -vote
not via webooks but via the get method
Make a manual request with postman
If that works, your code is somewhat pushing wrong values
how to post server count on bot page?
Negative, it's an object that, as far as my memory goes, contains user username, discriminator, ID and maybe avatar hash.
Shiv, you're the one who typed the vote payload type
Oh actually, are we talking about the same vote here kekw
its actually still an id
check the docs smh
Months ago 
I don't remember much since then

oops
The get bot votes indeed have those attrs doe xd
OH
Any docs/article/guide about the bot vote webhook thing
@jaunty plank why does luca not return an invite URL on the API 
🤔 Id hope luca isnt tied to the api.
luca doesn't have an invite
Ah
When I do any other bot on the topgg-simulator it returns an invite link and that is used as the button href
but when I try with Luca, it doesn't return anything at all
it wasn't set an invite
You could use a oauth invite template and just add the id in there
Thats when there is an invite returned via the API (Quart puts it into the HTML)
Thats when its not
So I'll just make it check for r["invite"] being nothing
yep that worked ^^
hello
if (message.channel.id === "884057134671757362") {
let user = message.content.split('<')[1].trim();
bot.users.get(`${user}`).send("hello");
}
});```
anyone please help @everyone
it is not sending message to the user @everyone
dblapi
This channel is ONLY for the Top.gg API!
This channel is only for: suggestions/help/bugs to do with official API libraries and API docs found at: https://docs.top.gg
Any Off-Topic conversation may get deleted and muted.
If you need help with development about your bot or development in general, feel free to use #development.
@storm fossil
imagine trying to ping everyone
lmao
nvm figured it out
Why does the topgg API expose user search functionalities? What is the intended usage for that?
Better usage with webhooks for example, without any need of discord
Failed to post server count
Forbidden: Forbidden (status code: 403)
what should I do
Your auth is wrong
this is my code, but I don't wanna see other code line, just the names and the avatar of the last user who voted
$nomention
$httpGet[https://top.gg/api/bots/$botID/votes]
$httpAddHeader[Authorization;$getVar[authorization]]
Los usuarios que han votado son:
$httpResult
i am very sorry this is off-topic but Is Somehost.xyz Safe ?
yes
I use them for one of my bots
also worth asking in #development as this is not API support
means not even 1 minute downtime ?
maybe there is sometimes downtime but i've not had any in the 3 weeks i've used them
will still note towards this #development message
also this^^
everything thats free, means that you're essentially the product
no
ok...
lmao wth happened here?
how do i send a message to a user when the vote for my bot?
- Get the id from the vote webhook
- fetch the user from the id
- use in message
how to use somehost link in webhook section ?
i mean waht to put in webhook url
if i am hosting my bot from somehost
@tidal idol very very sorry for ping sir
you won't be able to use webhooks if using a free hosting service
you would need to pay to host with a VPS for something like that
Personally I just use https://integrately.com for that
Can somone tell me where i get the API token? I've once found it but not this time 😅
i mean the Top.gg API token
aah thats why it didnt worked until the bot got accepted
Is there a way to get the authorization token without having a public bot?
any idea why my bot wont send a dm to the user who voted? heres my code
const top = require('top.gg-core');
const topgg = new top.Client('secret');
const webhook = new top.Webhook('secret');
client.on('ready', () => {
console.log('Logged');
topgg.post({
servers: client.guilds.cache.size
});
setInterval(() => {
topgg.post({
servers: client.guilds.cache.size
});
}, 3600000);
});
topgg.on('posted', data => {
console.log(data);
});
webhook.login('/https://www.classify.cf/topggVote', '135');
webhook.on('vote', vote => {
console.log(`User id: ${vote.user}\nAll data: ${vote}`);
vote.user.send({ embeds: [new MessageEmbed().setTitle("Thanks for voting for me").setDescription(`\`\`\`fix\nRewards -\n- 3 SpaceScript\n- 2 Common Boxes\`\`\``)]}).catch(() => {})
const inventory = require("../models/inventory")
inventory.findOne({ User: message.author.id }, async (err, ata) => {
ata.SpaceScript += 3
ata.CommonBox += 2
})
});
What is top.gg-core
Btw i heard that replit.com files are public, so anyone can see my bot codes!!?
I want to learn more about this detail, like how they do it? Is there a way to prevent it? Any added information is very helpful and appreciated
yes
if they have your username then they can get it if your repl isnt hidden
and youll need hacker plan to hide your repl
oh wait this is api @vivid verge #development
Yeah not an official one
by not pinging the moderator role
Is there an official one ??
The Vote API says it sends a POST request but it sends a GET request
Also there is no data in the request 🤔
I remember this happening. For some reason I kept getting GET requests and maybe some other crap
Note the invalid HTTP method errors occurring in topggpy months ago
I do not use topggpy... It's a normal server built by flask
try use topggpy
I can not... The server has lots of other uses
The problem is that there is no data in request sent
But the Auth key is sent in headers
What's the difference between using a bot as a client in a server with:
@client.event
And using it as a bot with:
@bot.command
No one in YouTube ever said the reason why it Should be used as as a bot, i use my bot as a client so idk the difference in those two codes
That’s the IP topgg is using to send POST requests to your endpoint
Anything else isn’t topgg
correct
Thank you, now gimme a cookie
.-.
The ppl in #development are having quiet the discussion so i didn't want to interrupt them
I guess i'll be back later then
If you're busy here as well
There is no firewall on server
What’s ur issue?
That’s not the point
So what is it?
I require knowledge '-'
The access log you showed is no request sent by topgg
I mean if possible pls •-•
With Python?
When I clicked on test exact endpoint with exact Auth key (Which is a hashed key) was triggered on my server
Yeah but not with that IP you showed above?!
Not sure if the test script uses a different one but I would guess no
Yes '-'
Pls ping me if you decide to help me out as i'm still searching for the answers in the meanwhile outside discord
I don’t speak snakish
You have to be patient until somebody arrives being crazy enough to use python
Maybe @sullen nymph is around
I did vote my self and same thing happened 🤔
You hit test and this IP got logged?
Still doubt the request is coming from topgg
But maybe the test system is still broken
I’m not up to date
You might wanna check site-news channel
client and bot don't really matter cuz it's just a variable naming after all. If you meant the discord.Client or commands.Bot class, they're really the same thing essentially. Bot inherits Client with a command handler. There are no differences here when using topggpy except you can have multiple listeners for the same event with Bot
Thank you, this is the best explanation i got so far
Now it is using a new IP 🤔
Might just test if the endpoint is accessible
Do you got the webhook as well?
Or is this the only access log?
Did you even press the test button?
Press save before hitting the test button
It is saved... I tested again and another IP sent request 😦
It’s possible that test webhooks being sent from a different endpoint as I said before
I did vote once... I got same result
But regular webhooks if somebody actually votes are only coming from the IP mentioned in the docs
Hmm can’t test it myself right now
If you test it Ping me
the token and password is in your bot's edit page > webhooks
you can give me link
ty
Whats the code for the Server stats? because i tryed it and only got errors
please?
Last night I did test and it wasn't working either
@jovial kiln i already did it
What method are you calling
wait i maybe found the error
well, nvm i still got the problem
i added the top.gg token and the auth code
what i can try next to fix that?
i found it
"app.listen(80)" at the end was the problem
👍
@pastel raptor Would you mind ☝️
Scamoro
Did you think about explaining your issue?
^
looks like we will never know
Not our problem per se so 
I need help getting the server count on top.gg for my bot hosted on autocode
anyone know how to help?
dblservercount
To have your bot's server count displayed on Top.gg, please read the documentation on server/shard posting.
You can either post the server count yourself or use a library to do so.
Doubt It's possible with Autocode alone
I've tried the API but I'm extremely confused, how do I post it myself, that would be 32923983324 times easier 😅
What have you tried so far?
Not a lot because I'm confused
Do i need a HTTP request on my bot's server or something?
By just sending a POST request to topgg's endpoint, that's it, including the server count as body of course
I'm lost
How can I get closer...
I've tried them but I can't work out where to put what
Take a look at the API -> getting started
Heading to https://docs.top.gg/api/bot/#post-stats
Then I'd suggest looking into basic API use before posting stats on a site
You gotta create an interval, which repeats to post the server count to topgg every 30 min, for example
I don't think this is possible in autocode?
Use a lib to do http requests and send a POST request to this endpoint
Idk, that's something you need to find out if you're using that service
So I can use a HTTP request endpoint?
autocode lets you write javascript, right?
Yes!
I highly suggest looking into basic request making
This is where we're at...
Before jumping straight into making requests
you got any links to that?
Yup, basic javascript documentation
Another helpful thing is to see what an HTTP request looks like in text
@stone schooner gimme 1 sec I'll find some links for you
Example of an HTTP request in Node.js:
https://nodejs.dev/learn/making-http-requests-with-nodejs
What an HTTP request looks like as it goes through the pipes of the internet:
https://www.tutorialspoint.com/http/http_message_examples.htm
More formal explanation of an HTTP request:
https://www.ibm.com/docs/en/cics-ts/5.3?topic=protocol-http-requests
How to perform HTTP requests with Node.js using GET, POST, PUT and DELETE
HTTP - Message Examples, HTTP request to fetch hello.htm page from the web server running on tutorialspoint.com.
Is the hostname just top.gg/api?
oh ok
path is /api/{rest of the path}
Currently have this... there will be a lot wrong for now but it is what it is and it's as far as I've currently go
So can you see any console.log output with this platform?
The endpoint is https://top.gg/api and the resource is /bots/:bot_id/stats
Well it's not LITERALLY {rest of the path}
That was just example text
no i know
I just put that for now while I work out what rest of path should be
oh-
they are making a request
in the code
Am i doing this kind of right or no...
I can just click run in autocode
Ok, then I think for now, you're on the right path
add server count to my bot's top.gg page
So in the world of HTTP messages, there are many kinds of requests, but there are 4 MAIN ones everyone uses:
ok...
GET Requests get some data
POST Requests send some data
DELETE requests tell the server you want to delete something (a file, for example)
PUT Send data to the server, and tells it "hey this thing already exists, but can you update it with this new data?"
Ok sounds good
So to send the server count, you need to make a POST request
god... what an ugly syntax, if you can use a different lib than the native one
I agree, I dislike the stream API personally
Like that right?
Correct!
Now, the path in the docs says: /bots/:bot_id/stats
So if your bot id is 123, your path would be /api/bots/123/stats
so /api//bots/891665780050100235/stats ?
Yes, but without the double //
If that's your bot ID
yeah i didnt mean that
yes I have that
I just don't know exactly what to do with it but I have a basic Idea
So, in order to identify yourself to the server as the rightful owner of the bot, you need to put your auth token in the Headers
Has to be provided in the header
What are we saying is the header hang on I'm confused again
headers:
{
'Authorization': 'token'
}```
So just put that in the code before or after the path and method?
oh ok cool
The headers are part of your options
getting a syntax error?
So, going back to what an HTTP message looks like in text, an HTTP message, when travelling through the internet tubes, looks something like this:
POST /api/bots/123/stats HTTP/1.1
Host: top.gg
Authorization: {your token here}
Did you put ; at the end of the line?
fixed
They are part of your options.
Like the hostname or port etc.
add a , after 'POST'
commas separate fields in your options object
Oh
also in hostname
remove https:// and the / at the end
just top.gg
ok
Should it ne comma instead of semi-colon at the end of the authorization as well?
oh ok
like in english: "Jim, Lisa, and Saharsh went to the movies"
no , after "saharsh" because his is the last name in the list
here's what I have, looks right or no?
your explanations are really helpful and I really appreciate them
😄
Ok sounds good!
1 sec let me confirm something
Ok!
I'm sure it's jason 
So, you need to construct your data object @stone schooner
Ok
So you wanna send the stats of the bot.
In the docs, the field is a number (or array of numbers) called server_count
yes
So your data object will look like:
{
server_count: 12345
}
or whatever the number is
Ok
Err nope
no?
that's in JSON
Should there be a way for it to adjust that number itself based on the bots server count
In JSON yes, Javascript doesn't require the "" to construct an object
I have a script adjusting it's status with a server count so that should be possible right?
Yes, so from what I understand, autocode allows you to basically create a very small server
I would define the body just so, but you can do it differently if you like to
body: JSON.stringify({ "server_count": guilds })
I think so...
So where does the first script run? The one that counts the total # of servers?
@restive otter ^
its a scheduler in autocode
This is what I have (Idk what the bottom bit is it's whatever)
so just before req.end(), you want to do:
I get that, is there a better way to perform that?
autocode is decent enough, it seems, I just have never personally used it
OH WAIT
back up 1 sec
you need to set your content-type header too
In order to post the accurate server count, it would sense, as I said before, the use a lib like node-fetch or even this native one, putting it into your bot script, create an interval of posting the count, using cached guild size as guild count
oooh ok, I'll pretend I know what that is for now 😅
So because you're sending JSON to the server, you need to let the server know that the text you're sending it is JSON formatted
oooh ok
You do this by adding a header that looks like: Content-Type: "application/json"
ok on it!
Additionally, it looks like in the node.js API, you ALSO have to send the Content-Length header
This tells the server how MUCH data you're sending
the content type is part of the header
Also you'll need to put "" around it, like "Content-type"
also before you think why is he coding in light mode, you can't change it and it bothers me just as much 😅 🥲
Javascript is interpretting Content-Type as "a variable named Content Minus a variable named Type"
Lol my computer faces a window and light mode is nicer when there's more ambient light
this?
Yeah, now put it underneath headers next to Authorization
ah ok... wait like in the same curly brackets?
yep
like this?
exactly
why does one have " and the other has ' ?
In javascript, theyre the same thing
oh ok makes sense
You can switch them interchangeably. Some people will tell you to always do '
so it doesn't actually matter?
There's a special one with `
It's a style choice
Style matters, but it doesn't change the output of the program
ok... what next?
So now you need to tell the API how big your data is
I'm used to HTML and CSS - so much more simple 😅
What's your code look like now?
Ok, so for your server_count, you'll need to do 2 things:
- give that object a name by putting
const data =before the first{bracket - MOVE that entire block to BEFORE the
optionsobject
ok...
WHY we do that will make sense in just a minute
so what shall I write
wait its not 9 its 94
then 94
const https = require('https')
const data = {
server_count: 94
}
const options = {
hostname: 'top.gg',
port: 443,
path: '/api/bots/891665780050100235/stats',
method: 'POST',
headers:
@stray pawn do i got it right?
uh oh...
everyone disappeared
anyone there who could help me finish this...
Can you show the full part up until and including where you send the request?
Sorry, ran to the bathroom
idk how to do that, is there like an npm dependency I can use, and if so how would I integrate it?
What is that and what does it do...
It does a lot of this boilerplate stuff for you
SDK - Software Development Kit. In this case, a package that contains functions and a system for you to work with Top.gg easily
Yup, Shortround explained it in simpler terms
Ok what am I doing next...
Instead of handling HTTP requests manually, you just call a method from the package's object and work with the response
Download the npm package, implement it in your bot. There should be examples
Doing what you wanna do, it'll basically be:
ok... is visibly very confused
const api = new Api({your token});
await api.postStats({
serverCount: 28199,
shardCount: 1
})
that simple?
wait does it still need all the stuff we already did or is it just that?
it does most of that for you
that's the point of the SDK
If you're willing to throw your code away, you should use the SDK
Yeah
This thing?
I have the latest version installed now so what should my code look like?
const Topgg = require(`@top-gg/sdk`)
const api = new Topgg.Api('Your top.gg token')
That's all the code that should go in it?
then after that
For the most part other than posting stats
Note: there's an additional package to do that for you automatically
await api.postStats({
serverCount: {your stats}
})
For this, see: https://github.com/top-gg/node-sdk/#auto-posting-stats
const https = require('https')
const data = {
server_count: 94
}
const options = {
hostname: 'top.gg',
port: 443,
path: '/api/bots/891665780050100235/stats',
method: 'POST',
headers:
{
"Content-Type": "application/json",
'Authorization': 'Token'
}
}
const req = https.request(options, res => {
console.log(`statusCode: ${res.statusCode}`)
res.on('data', d => {
process.stdout.write(d)
})
})
req.on('error', error => {
console.error(error)
})
req.end()
This is what I have what can I delete
Yeah you can delete all that ^
Yup
all?!?!
added this
await api.postStats({
serverCount: {your stats}
})
Just this now?
oh ok
Preferably you want to have access to your ciient object to fetch guild count from it
ok how are we doing that?
The closest thing I have is this scheduler :
using djs?
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN}); // make API request
let servers = await lib.discord.guilds['@0.1.0'].list({
limit: 200,
});
let result = await lib.discord.users['@0.1.1'].me.status.update({
activity_name: `/help on ${servers.length === 200 ? servers.length + '+' : servers.length} servers`, // required
activity_type: 'LISTENING',
status: 'ONLINE',
});
discord,js yeah
What is that package even
what package?
Thats how autocode injects env variables
yeah
Oh you mean require lib
https://discord.js.org/#/docs/main/stable/class/Client?scrollTo=guilds
then use cache.size
Yeah, the lib package and the way it functions
What we doing with this app?
Nothing, just showing the require(lib) thing in autocode's example app
ohhhhh ok
autocodes been around for awhile
Has anyone made a node-based botbuilder
Where to from here?
Haven't heard of it up until now lol
like unreal blueprints?
run your code
constantly getting bots submitted using autocode.
Some of the most unreliable bots 👀
LMAO
ayyyyyyy
My bot is reliable... I think 😅
How do you know that people aren’t sending fake server counts 🧐
I guess we'll never know...
its mostly just users adding random packages from autocodes package list, not understanding/making it work.
We can always just manually check ^_^
True
If there is a massive increase then it’s probs worth checking
How can I make it so that it actually finds the current server count rather than manually updating?
Oh god- I just hit 100 servers
What did you write your bot in?
Can someone show an example of how to write this out?
its discord.js but I'm still early in my beginner days using mostly snippets and customising them to add improved usability
objectName.guilds?
yes, and objectName would be the name of your client object.
and the client object is...
the bot client?
I kind of get this kind of don't
my clientid?
It looks like autocode provides the discordjs client for you?
oh as in lib.discord.
Do like guilds.size
since it looks like guilds gives you their IDs
guilds.size will give you total guilds
You may need to alter this approach if you get a lot of users
yeah, looks like they dont give access to cache.
https://autocode.com/lib/discord/guilds/
this is wrong though, right?
yeah
Actually, don't think this will work either.
What did i do
first, do this again at the top:
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
this gives a copy paste example of getting the count https://autocode.com/lib/discord/guilds/
or well the list
then just using .size
oh yes of course the library, forgot about that
no bloody clue
it appears to be the version of the library
(I asked myself the same ever since I saw it)
how do I not limit the count?
remove the limit entirely
I think just don't provide a limit
// Using Node.js 14.x +
// use "lib" package from npm
const lib = require('lib')({token: null /* link an account to create an identity */});
// make API request
let result = await lib.discord.guilds['@0.1.0'].list({
limit: 100
});
THis is what we have
what do I do with it...
it might help to just use the tool they gave you
the end is just .list()
you need to add .size, then just use the variable in place of 100
.size to where?
on list()
so list.size?
list needs to be a function
that, youll also need to () around the awaited promise. otherwise it wont work
ok...
so how do I then do the brackets?
surely its not this simple?
I just suggest dropping into learning js first
^
Its kind of hard to explain it if you don't understand some of the terms.
You'll need to put the awaited promise in parenthesis so the .size can function.
Then using the result variable in place of the 100.
If I paste the code can you show me?
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
let result = await lib.discord.guilds['@0.1.0'].list().size;
const Topgg = require(`@top-gg/sdk`)
const api = new Topgg.Api('Token')
(await api.postStats({
serverCount: 100
}))
We don't allow spoonfeeding here, it hurts new developers.
https://www.freecodecamp.org/news/async-await-and-promises/
Covers promises.
https://www.w3schools.com/js/js_variables.asp covers using variables.
would this do it
Nope. Result isn't a function, it's a variable.
Check the above links for more information
ok I'm lost on what the function is I'll try to find it
lib.discord.guilds['@0.1.0'].list().size; is it this
api.postStats or maybe this?
What's the question?
What a function is? Or what a variable is.
I dont see you using a function currently. Just a variable(which you are trying to use like a function)
oh-
https://www.w3schools.com/js/js_functions.asp looking at this very confused
You have no use for that right now. You want to use a variable.
Let or const works in this case.
Which you are already doing. You just need to use it
Yep. And you are already doing that.
You just need to use it
Ok where will I find how to use it
This covers using variables.
this?
Yep
let result = await lib.discord.guilds['@0.1.0'].list().size; so we need to use this?
How do I use the ServerCount API?
where the variable is result
Language?
Node.js
this?
Then?
Yep. Then just add parenthesis around the awaited promise
(await ... list())
That page covers posting your server count
like that? but the semi-colon on the outside?
Add the ) before .size
Size isn't part of the promise
Under?
Perfect
so that should all work now?
Should work fine now
How do I make it the playing status?
shall I set my server count to 0 and then run it like this to test?
Ah that's a question for #development
You dont need the api for making it your bot status
I would if you want to be sure
Ok.
Still not working
When you set it to 0?
Try setting it to 1
is it because it's not defined in my code?
it wont let me set a number since making the adaptations to make it work
nevermind it did
its just wen its set as result
console.log(result)
Somewhere below the definition line
this?
because that didn't work
print out?
log the value of result
I really really suggest looking into js first because you're missing the basics of debugging
I've got very minimal JS knowledge but docs get me so confused on w3schools because their doesn't seem to be many real world uses as examples
I usually build websites and just use bootstrap for JavaScript
all of the words used on w3schools are real words and the way developers communicate to each other.
https://www.idtech.com/blog/coding-terminology-list
kek
i misread

I know they're real words its just using what it teaches in the real world
docs typically dont give real world examples specifically for what you are looking to do.
the knowledge you get from them is typically generic, as they cant cover every possible thing you want to do.
Yeah I get that
If you are looking for real world examples, probably best to spend time looking at github, but you'll still need theoretical knowledge like w3schools gives.
it's just like when I learnt HTML, CSS, and Bootstrap I was able to visualise things as they're more simple but of course Javascript is a programming language so operates a lot different
I FIXED IT!!!!
Ah, what was the issue?
.size needed to be .length
heck
it was that little causing that big of an issue
yeah its an array not a map 
we didnt read the autocode docs well enough
if I set that on a daily scheduler now, I can feed that through to top.gg daily at midnight with the latest, right?
If you want, it can be every hour too. our recommended time is 30 minutes.
Yeah it's just I have a 100000 monthly request limit so I'm being conservative of that 🤣
yeah
I've set it as hourly
same as the bot status
so the bot status and top.gg will always match
Not sure how autocode handles sharding, but once your bot increases in server count you may need to change your code.
oh-
Just when I thought I had it 🥲
You may not need to, I just dont know autocode's library at all so its pretty hard for me to help with that.
I get that, I'll ask the autocode team
mind if I screenshot this to show their support team so the understand?
sure np
no problem.
If you need anything else dont be afraid to ping me.
apparently i'll need to run the API more than once after reaching 1000 servers
ah, makes sense.
Do they provide shard ids?
I don’t think so, idk
how to make the number of servers visible?
dblservercount
To have your bot's server count displayed on Top.gg, please read the documentation on server/shard posting.
Why do I get GET Requests with exact Authorization but no vote data on my server for votes instead of POST Requests with vote data
This request is a real vote by myself not a test vote
I have a complex Auth on the endpoint and if Auth is not correct it will return 403 not 200
It's not you be able to guess the Auth
The only thing I can tell you is that this doesn't match the ip given on the docs
it is likely not top.gg making that request
Checked myself using a mock server from postman, only requests being these
first one is me using the test button, second one an actual vote,
Are you able to check what the request body of your request was?
The only explanation would be either you making the request yourself or something else making the request
You mean header? or the data?
It's empty... Completely empty
And there's nothing else making that request?
But header conatians the correct Auth key
I haven't share the Auth key with anyone so how it is correct?
Is it possible that cloudflare is removing the body??? As I have a worker redirecting requests to a custom port
This is the worker ```
addEventListener('fetch', event => {
event.respondWith(changePort(event.request))
})
async function changePort(request) {
var newURL = new URL(request.url)
newURL.port = '2096'
return fetch(newURL, request)
}
add a dummy body saying "hello"
then try voting again
pretty sure that's what's making the request
I probably assume that the IP in your logs is a cloudflare worker IP then
also explains these scraping reports, as people might abuse workers for scraping
Hmm, Seems it is the worker 🤔
what's the purpose of that worker? To redirect a non-port request (domain) to a port request?
Hey hey @next pendant was your problem resolved by the way? Maybe you're having that issue aswell due to you using cloudflare workers perhaps
The host I have have several servers using different votes including 80 and 443 and I wanted my domain redirect to another port (2096) so I used the worker
@rain heart just to let you know if sth similar happened 😂
I am using flask on my server, And I was trying to get the data with request.args and request.form and both of them were empty... But after a lot of digging I found out top.gg sends the data as json and it is in request.get_json()
only one is possible, you could have that one send 2 webhooks though
this is stripping all the additional data from the request except for the url
basically what they realized afterwards
you need to use
const newRequest = new Request(request)
const newUrl = new URL(request.url)
newUrl.port = ...
newRequest.url = newUrl
why are you even using a worker for this though? Just use a subdomain and point it to the right IP
use a reverse proxy like caddy and forward the domain you need to the correct process/port
Hi, my webhooks are setup as described in the docs. Webhook is setup as follows on top.gg
http://example.com:5001/dblwebhook
and the code running is as follows
const { AutoPoster } = require('topgg-autoposter')
const ap = AutoPoster(tgg, manager)
const Topgg = require("@top-gg/sdk")
const express = require("express")
const app = express()
const webhook = new Topgg.Webhook(tgg)
ap.on('posted', () => {
console.log('Posted stats to Top.gg!')
})
app.post("/dblwebhook", webhook.listener(vote => {
console.log("Stuff")
console.log(vote)
}))
app.listen(5001, () => {
console.log(`Example app listening at http://localhost:5001`)
})```
however when i send a test, i get no response inside the webhook listener. but if i remove the webhook.listener and just read the response manually i do get response json, just not usable.
@rain heart
Is your auth the same between the code and on top.gg?
if by auth you mean the top.gg token, then yes they are the same as on the website
test your webhook with postman or reqbin then
testing using reqbin with my tgg token as the "Bearer Token" gives me 403 Forbidden
so i send a json object structured like this to my endpoint
{"api-key": "insertTokenHere"}
i've tried different keys such as "key","apikey","api" with no luck. 403
That is not how you do it
Wait webhooks or api requests?
webhooks
Webhooks don't use the api token
It's the auth that needs to be the same
This needs to be filled in with whatever you have in the tgg variable
Thank you that works
my bot was offline for 6 months. It got negative reviews. But now it's working fine, but other chatbots ( in less servers, less votes compared to mine) are in the top because they have positive reviews
i've been sending test webhooks and they've been working fine, then suddenly they're not so fine. Anyone know what causes this?
Ratelimit?
Nevermind, waited a bit then refreshed the page and it works again. Weird.
that's not an official library, consider using official ones to get help here
otherwise contact that apis support
official library is ?
refer to pins
@rain heart
again refer to pins
yes, by either using the webhook library mentioned on the pins or manually making it with a webserver
I'm currently at work so I wont be able to help
Hey, I tried to post my bot stats but i got ```json
{ "error": "Unauthorized" }
My code is: ```js
fetch(`https://top.gg/api/bots/:botid/stats`, { method: "post", body: JSON.stringify({ server_count: client.guilds.cache.size }) }).then(res => res.json()).then(data => console.log(data))
What headers should I add (Ignore the content-type)
read the docs
k
hello get this error
code are correct dude
First of all
Can you describe your issue in details? What have you tried so far? What does your code look like? What's the command supposed to do and when?
it returns the amount of votes on the API
Total or monthly?
both
yes but how (i have no idea about topgg api)\
alright thanks :)
The BotData type contains monthly_points and points keys/fields
I believe you got enough common sense to make do with just that

Ill ask if i have questions
if you dont mind
Sure thing, feel free to ask here
O shiv, 1.4 hasn't been published 
alright, i got it! thanks!!
As in real time thanks message?
yes
A simple API wrapper for top.gg written in Python. Contribute to top-gg/python-sdk development by creating an account on GitHub.
was kinda hoping that webhooks werent involved
since ive never used webhooks
how do they work?
Topggpy abstracts it for you there
It's basically just a REST API, but Top.GG is the client and you're the server
yea, but ill have to add topgg webhook to servers right?
What servers do you mean?
Err, no, it's not related to Discord's webhooks
ohh alright
wait what
ill check the docs and try
hopefully ill get it
Didn't we talk about this kekw
Yes, try seeing the examples, feel free to ask
Alright seems not
.. i dont get it
Wanna take the credit?
Eh sure, manually release?
Yup
Or can I just do the commands from the workflow
I don't think the secret was updated
What you don't get?
is there a way without webhooks?
Webhooks are a way of receiving information from Top.gg in real-time. On your machine, all you need is an open port (if you have a firewall running) and Internet connection
The only way to achieve that is by fetching recent votes data on an interval and checking what's changed since the last time
ah, so webhook it is
Only works for a set of users
Mainly just check if you have a firewall running and if yes, open TCP port X and your URL will be http://your.machine's.ip.address:yourporthere/route
Routes should be fairly clear when using WebhookManager provided by topggpy. It abstracts most of the stuff you'd do to get a webhook running
I wish it was a WS so that I don't need to open any port 
@bot.event
async def on_dbl_vote(data):
"""An event that is called whenever someone votes for the bot on Top.gg."""
if data["type"] == "test":
# this is roughly equivalent to
# return await on_dbl_test(data) in this case
return bot.dispatch('dbl_test', data)
print(f"Received a vote:\n{data}")```
God WS would be so great
so this is what im supposed to use, right?
That's the event that topggpy will dispatch yes
Sort of. The if there just dispatches another event for you to handle test requests
yes i got that
You need the WebhookManager as well though
But, otherwise, yeah, on_dbl_vote receives all bot votes and handles them however you want to
what do i put in here?