#topgg-api
1 messages · Page 142 of 1
const Topgg = require('@top-gg/sdk')
const api = new Topgg.Api('my topgg token')
setInterval(() => {
api.postStats({
serverCount: client.guilds.cache.size,
shardId: client.shard.ids[0],
shardCount: client.options.shardCount
})
}, 1800000)
``` can someone tell my why tf I got ratelimited?
should I increase the interval to 3600000?
what's the ratelimit error you're getting
my server count is not showing on my bot's page i used the updated code but still don't work this is the code:
from discord.ext import commands
import dbl
class TopGG(commands.Cog):
def __init__(self, client):
self.client = client
self.token = '' # set this to your DBL token
self.dblpy = dbl.DBLClient(self.client, self.token, autopost=True)
@commands.Cog.listener()
async def on_guild_post(self):
print("Server count posted successfully")
def setup(client):
client.add_cog(TopGG(client))
How do I set up the voting query command with Discord.js?
How does someone vote for My Bot send him a thank you note for voting for the bot
gg
you're testing with a discord webhook url?
where deh fak is my api key
read pins
can someone pls help me out?
my bot is approved
When will my bot be approved?
ty
is the only thing we can receive are votes?
Like does the api support comments etc..
someone please tell me how can i use webhook for vote logs.
I tried almost everything thing but can't get log on channel.
code sample:
@commands.Cog.listener()
async def on_dbl_vote(self, data):
chan = self.client.get_channel(channel_id)
user = self.client.get_user(int(data['user']))
await chan.send(f"<@{user}> has voted!")
Why did you ping a community manager?
Did you test the webhook?
Even I need help regarding the same thing. I’ve been trying it from weeks. And still I’m not able to understand dblpy. I used discordlists for updating server count.
do you have to pay for the api
No, you don't
Hey
-api
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.
Change channels please
To what
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.
What is that
once again, change channels
Hello
-api
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.
last warning
-m @mortal wasp decided to continue off-topic conversations in #topgg-api after multiple warnings | 12h
🤐 Muted valentino5972#3736 (@mortal wasp)
@night ingot @rain heart I can't find the issue .. Why you are not answering our questions ?
because you should wait for someone who can explain it. As I don't know python
The docs are the fastest you can get
If you want fast answers without waiting, then https://dblpy.readthedocs.io/en/latest/ or https://docs.top.gg
https://top.gg/api/bots/:id
sends unauthorised instead of bot data when trying to fetch it, but if I visit the site via browser, it shows me bot data.. how to get bot data via fetch then?
🤔
Which is set on your browser by default (when logged in)
with the Authorization header, yes
429 Too many requests (sorry for taking too long to respond, next time ping me pls)
What is the best way to setup a webhook for the voting?
how exactly does it tell you? in a json form or in html?
Console error
just a simple 429 too many requests? nothing with html or anything?
then most likely ratelimited from top.gg, wait an hour
if nothing changes, a full day
In the interval?
nah just don't do nothing in regards to the api, take out your server count interval and wait an hour
Hm k
Read #site-status
Hey just wondering if anyone was able to add voting to their bot while having it sharded 😅 Struggling to find out how to do it
Anyone? An another alternative is hosting the webhook on my local network, but idk what to port forward etc
you will forward the port you specifiy yourself
@barren kestrel Use a random port from the range 9000-65000
allow incoming TCP connections for this port in your firewall
and forward the port (TCP) to your device
but if you don't got a static IP address it may get difficult
you will likely create your own DDNS or use a public service if it really needs to be hosted from home
Ye so. What I mean is what ip do I forward. In my router menu, it doesn’t allow me to paste my public ip. Tells me to use a lab
Lan*
And also how do I find available poets
Ports
This is so confusing
you will have to use your public IP of course... there's no IP forwarding, just port forwarding, the port you can freely CHOOSE
Ok
That is my publix
Ik
But
I can’t paste that in my forward menu
It says to port forward an ip or something
yes forward the port the a device which got a local IP assigned by your router
probably 192.168.x.x
the webhook is sending a package to your public IP, your router accepts the incoming package (because you allowed TCP package on that port) and will forward it to your local device
the local device the webhook service is running on
and to find the local device the router needs it's LAN IP
depending on the router it might be a good idea to assign a static (local) IP address to the device
if your router supports this
Ye but what do I put for the x.x
that actual local device IP
Where do I get that
take a look into your router, it should have a LIST of all connected devices
dunno what router you have
Netgear nighthawk
R7960P
I’m on the list of attached devices
Do I find my device ip
In that list
you should yes
ok
ok so
depends on the router always
in my router port fodwaring menu
i says
service name
and an option
rn its at ftp
Then next to it is the server address
Whi9hc I copyed and pasted from my laptop on the attached devioces menu
don't choose a prexisting service
can you actually add an own?
Protocol is TCP, port the one you choose (from 9000-65000)
Wdym. I have two options
Service name
and Server IP address
gimme a screenshot of it
add custom one, yes
ok
lets enter a service name, for example topgg webhook
choose TCP only not TCP/UDP
external starting AND ending port is the port you wanna choose, e.g. 9111
whatever you like
same like internal port
and instead of enter the devices IP you can CHOOSE it
Ill do 5000
no
Protocol is TCP, port the one you choose (from 9000-65000)
not from a range < 9000
so
9500, 9005, 9555 whatever you like
k
19555
and then choose the device and save it
guessing the device is Windows?
you need to accept internal connections on that port now in the firewall
one second, lemme get a command line runner
AWWW FUCK
a typo
hold on
netsh advfirewall firewall add rule name="topgg webhook" dir=in action=allow protocol=TCP localport=19555 enable=yes profile=any
open the windows command prompt and enter this
you will probably need to open the command prompt as admin
you can later view that entry in the firewall app
response should be OK
@barren kestrel
powershell?
Ok
Ill do that
nope
in system32
right
the directory
I cant do it rn as Im away from host pc, but I will do ASAP
oh alright
just hit your Windows icon in the taskbar and start typing CMD without pressing something
netsh advfirewall firewall add rule name="Topgg webhook" dir=in action=allow protocol=TCP localport=19555 enable=yes profile=any
ok
yes to identify the firewall record
ok
you will be able to see it later in the list
you can later open your firewall app on your device Windows Defender Firewall with Advanced Security > select INCOMING RULES on the left list > sort by name > see your record
ok. and then do I just run it in my code and test?
yes you generate it IF your bot is approved already
@plucky lance I just now after running that in my command prompt, I add to code right?
I have my code already
k
This is my code: ```import discord
from discord.ext import commands, tasks
import dbl
class TopGG(commands.Cog):
def init(self, bot):
self.bot = bot
@tasks.loop(minutes=30)
async def update_stats(self):
"""This function runs every 30 minutes to automatically update your server count."""
await self.bot.wait_until_ready()
try:
server_count = len(self.bot.guilds)
await self.dblpy.post_guild_count(server_count)
print('Posted server count ({})'.format(server_count))
except Exception as e:
print('Failed to post server count\n{}: {}'.format(type(e).__name__, e))
@commands.Cog.listener()
async def on_dbl_vote(self, data):
user = data['user']
embed = discord.Embed(description="New Vote! Voter: {}".format(user))
channel = self.bot.get_channel(int(822973544412741632))
await channel.send(embed=embed)
def setup(bot):
bot.add_cog(TopGG(bot))This is what happens when someone votes:Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x7fbd44abb910>```
Any ideas?
you saw the OK in your command prompt?
havent tried yet sorry, i will do when I get back
oh yeah forgot that part, lemme know later
Where do you even have your webhook that runs to receive the event
lol elite noob
wdym? its in my code?
Ok doing it rn
pretty sure he talked to the guy above us, providing snake code
ohh
I got the ok
so I now add to code?.
Now I'm able to hack into your system... already downloading any credit card information

joking
ik
well yeah, now make sure to add your public ip to topgg and the port
ok
you will probably also need to specify that port in the code again
the code for the webhook service
@plucky lance
const express = require('express')
const app = express() // Your express app
const webhook = new Topgg.Webhook(config.topggwebhookauth)
const dwebhook = stuff
app.post('/dblwebhook', webhook.middleware(), (req, res) => {
// req.vote is your vote object e.g
console.log(req.vote.user) // 221221226561929217
dwebhook.send(`<@${req.vote.user}> has voted for News Agent on top.gg!`)
});
app.listen(19555)```
well never worked with express, can't help u with that
but it seems to be right, I guess
Ok but is my ip part right?
yes, your public IP address not the internal LAN address
k
@plucky lance No error, and it doesnt work
press save before using test
Did
might still be an issue
js
ye its in docs
lemme look
np
doesn't work :c
well your side is configurated well
do you even have a public IP v4?
make sure it's an actual IPv4 not v6
hmm imma not sure about express tbh
Its the exact code in the docs as well
if you router successfully forwards the port it should be ok
one second
ok
is it possible to know who upvoted my bot with only a token?
uh no, you need webhook auth
but if you have a token yes
ok
a top.gg token
you would need webhook url, webhook auth, and top.gg token
@vivid nest
@barren kestrel To check if the port is opened up open a Windows command prompt from outside your network and enter telnet your-public-ip 19555 and see what u get
Yes thank you
Says it doesnt know what telnet is
o h wait im installin rn
On the external device: click on the windows icon > enter windows features > scroll down > tick the checkbox for telnet > wait until installation is done
yes ty
can also be done from a Linux device of course
doesn't need to be an external Windows device
or even more easy https://www.yougetsignal.com/tools/open-ports/
@plucky lance
that's bad, that means your router didn't forward the port
eEEk
do you probably need to activate the rule?
or is the checkbox just to delete the rule?
ow wrong link... meant the image below
wdym
the box is to
there's a little checkbox infront of the rule
edit or delete
oh ok
ye
the internal device IP is correct?
in the first place try to restart the router and test it out
Ok
yes
Ill update firmware and restart
80?
also for the firewall rule
yeah 80 is the default webserver port (HTTP)
you can edit the firewall rule
here
remove rule?
where is the page for getting ur bot's api token again
Double click your rule > protocolls and ports > change 19555 to 80
what do I look for
your bots edit page > webhooks
but whats the rule name
your firewall rule name we choosed
How can I read this 172.18.0.1 - - [21/Mar/2021 16:33:29] "POST / HTTP/1.1" 405 -
ok
thanks
netsh advfirewall firewall add rule name="Topgg webhook" dir=in action=allow protocol=TCP localport=19555 enable=yes profile=any
it used to be in some api page so I got confused
rule name="Topgg webhook"
k
changed toi 80
now changing to code
then u[dating frimware and restarting
and the router
aye
just to make sure, the actual code is on the device?
you forwarded the port to
what do i hav eto put in webhook_path
yesd
it is on the device I forwadeded
the IP and path to the public IP the code is running and which path is it listening
Updating firmware
#topgg-api message
like it this example it would be app.post('/dblwebhook'
that doesn't fix issues with port forwarding but isn't a bad idea anyways
if port 80 isn't opened up after a restart of your router then Houston we got a problem
Yep
Wdym my that
Also router restarting rn
I replied to somebody else
aye
ay retsrarted router
now to test
🤞
Oh shoot
im dumb
@plucky lance
I did this on my norm pc and not my host pc 🤦
forgot to allow the port forwars tuff
what
its now showing up on my firwall section
yes
alright
Topgg Webhook isnt showing up
it's not in incoming rules?
thought it was there a mins ago you edited the firewall rule
Ok now it is
one minute
im fixjng
IT STILL SAYS CLOSED
I ENABLED
AND IT SHOWS ON FIREWALL
AND ON ROUTER-LOGIN
@plucky lance
well then you're basically fucked, your ISP is filtering the ports
don't think it's the routers fault, netgear isn't building bad stuff
noe
im dumbo
and did the wrong ip c:
@plucky lance Lets start from step 1
Ok that step done
Next I do ther firewall
netsh advfirewall firewall add rule name="topgg" dir=in action=allow protocol=TCP localport=80 enable=yes profile=any
god damn I will slap you, I'm telling you
CHOOSE the RIGHT device in your router the CODE is running ON
then ON that device add the FIREWALL rule
that's it
your public IP address remains the same of course
I did but it still says cannot connect
@plucky lance
It shows on firweall
Is that right
ok idk what to do
this isnt working
yeah like I said, all incoming package will pass your ISP first, then your router, then your device
your ISP might drop some package he doesn't like or he thinks you don't need
how do I fix that
Like tyhis
thats why
lets do something big
random
you will probably need to contact your ISP and question him about it or just host the code on a public device
like a dedicated server / VM
netsh advfirewall firewall add rule name="topgg" dir=in action=allow protocol=TCP localport=19555 enable=yes profile=any
yes
don't always add new firewall rules
Oh I deleted the old ones
edit the rule like I told you
so thats why im adding
simply editing it is enough, it's active in the moment you're saving it
Eek ok ill just make it this last time
Ok it shows up
@plucky lance
YES
its open
what I had to do
was
first chnage the port to that
you remember I said before use ports > 9000
looks like I was right
then in my code I needed to listen to it first, then run my bot, then check
only then it listens yes
ty
let me try again now
as long as the code really is on the device the firewall rule is set, it should now work
@plucky lance Doesnt send
saved before clicking the test button?
did the telnet check work?
@barren kestrel if so you may wanna join #support and ask if somebody can send u a webhook to test it out and see the response (even if it fails)
Haven’t tried
Ok
Can you xD?
The bot is “News Agent”
well then, I can't send u a webhook
You can test
If you vote for the bot
:/
But it’s fine
I’ll try
It’s probs code
If the test button didn't work you won't receive one I guess
that means you need to debug why
is there a precise guide on how to get the if a person votes for your bot API in discord.py
that requires to send a webhook to your endpoint FROM external and see the debug log
(the response)
ok
since the port is open there will be an error
can someone teach me how to use the Vote for bot API with discord.py
read the docs in the first place
the topgg api isn't working for me as no errors are thrown. I am trying to show the count of servers my bot is in but on the page it shows N/A
here's the code:
from discord.ext import commands
import dbl
class TopGG(commands.Cog):
def __init__(self, client):
self.client = client
self.token = '' # set this to your DBL token
self.dblpy = dbl.DBLClient(self.client, self.token, autopost=True)
@commands.Cog.listener()
async def on_guild_post(self):
print("Server count posted successfully")
def setup(client):
client.add_cog(TopGG(client))
Did you put your token?
Or did you just plain copy and paste it without reading what you’re supposed to do
i put my token
i removed it here tho so no one can use it lol
i copied it from the github and added my token
???
hi
where is any suggestion posted?
Include in the voting endpoint, the date of the vote that a person makes
I will be redoing the webhook code tomorrow morning.
So I’ll see if it works
Also do you know how I can say... when a user votes, do something
Hey, so my firewall blocks POST access to my bot for voting, so is there any other way to gain POST because I can't bypass the firewall of the compound where I live.
Don't self host ez
if you can't bypass the firewall then no, not really
Ok, thanks.
dont selfhost webhook tbh
Unless you couldn't care less about reliability
Can anyone explain this to me?
from discord.ext import commands
import dbl
class TopGG(commands.Cog):
"""
This example uses dblpy's webhook system.
In order to run the webhook, at least webhook_port must be specified (number between 1024 and 49151).
"""
def __init__(self, bot):
self.bot = bot
self.token = 'dbl_token' # set this to your DBL token
self.dblpy = dbl.DBLClient(self.bot, self.token, webhook_path='/dblwebhook', webhook_auth='password', webhook_port=5000)
@commands.Cog.listener()
async def on_dbl_vote(self, data):
"""An event that is called whenever someone votes for the bot on top.gg."""
print("Received an upvote:", "\n", data, sep="")
@commands.Cog.listener()
async def on_dbl_test(self, data):
"""An event that is called whenever someone tests the webhook system for your bot on top.gg."""
print("Received a test upvote:", "\n", data, sep="")
def setup(bot):
bot.add_cog(TopGG(bot))
Does the dbl handle hosting of the webhook?
So I still need a working url for callback?
You need to host the webhook yourself
The SDK hosts a Webserver internally.
The URL is just http://ip:port/path
Thanks, @green roost That explains a lot, so If I leave out the webhook_path, it will be just ip/:port/?
No I believe the default path is /dblwebhook
You can manually set the path to / if you want.
Alright but I’m still not sure if your ISP is blocking the traffic without actually testing it - sending a webhook to your IP to see what the result is
@plucky lance I'm gonna make a tunnel, cause unfortunately my ISP use CGNAT, and I haven't bought a static IP so I can't open ports
the problem i have now is this
Well u mean DSLite that’s what the most ISPs use today
Even if that means you don’t have a public IPv4 you could try to enter the IPv6 on topgg and see if it supports it
But I expect the traffic is still sorted out
As long as u don’t have a business connection/contract with ur ISP - speaking about your internet connection- that may won’t change
I've already set everything up with ngrok
But can't save the url
Does my bot need to be approved for this?
Is it necessary to host it at home?
Isn’t there a VM/dedicated server you can use?
I'm developing it currently, but yeah it will be hosted so no problem there
Well your bot has to be online 24/7 to get approved because it can happen at any time.
Kk, thanks for the info
Regardless that fact a bot which isn’t online 24/7 doesn’t really make sense at all 
What's your issue?
This doesn't work
I added my token but it shows N/A on my bots page
That's my issue
@night ingot
Does it work if you remove the listener?
I don't use the listener in mine, but I don't feel like it should make a difference
Ight lemme try
A listener requires to be able to read incoming connections
Did you even add a rule in your firewall for incoming connections on your specified port?
Yes
Nope
Then at home I guess
Still don't work @night ingot
Testing/hosting at home is hassle
Strange, and you tried leaving it on for a while? Since it only posts every 30 minutes
Yes
You need to make sure your ISP isn’t blocking your traffic/ports, you have an actual public IPv4, you forwarded the ports in your router etc.
Yes I have
If one these things isn’t setup properly you won’t be able to receive a webhook
I did everything correctly
If you want to, you could swap to the manual way of posting server counts. That way you can see if any errors happen when it tries to post it
@plucky lance @plucky lance @plucky lance
https://gyazo.com/efe080fee5185cec04e39d5efe7c4e69 this happens when i use manual
@night ingot
Is that the method from the docs?
Oh you wanna post your bot stats only? Thought you wanna receive a webhook.
yes
hello how do i do the webhook think for the upvotes i created a new one in my server copied url tried to save but it says problem while saving
yup
bot stats only
Oh my bad. Than opening ports etc. isn’t required
Try the one from here https://docs.top.gg/libraries/python/
That one looks outdated
That one was from the github
Hm, strange
i tried the one from the docs before
They're different
still didn't work
Hmm how do i listen to web hooks? I am using a rasp pi 4
Depends on what language you're using
Can i do it without port forwarding?
wut do i do abt dis?
To be honest, I don't really know. I can't see why it wouldn't post it
Setup a webhook listener (service), open up the required ports on your device and there you go
Port forwarding is required as well if you host at home as well as a public IPv4 address
(guessing IPv6 won’t be supported)
😔
Without port forwarding, the port won't be open to the public net, therefore you can't receive webhooks from anywhere other than your local network
wut do i do now just wait until the api is fixed?
Damn gotta expose my rasp to the internet then 
Well the API works fine
I guess you could keep asking and see if someone who knows would reply
I’m able to send the stats at any time
Not necessarily, only traffic through that port
i'd rather not waste my time
And top.gg has a feature to add an authorization to the webhook so that you know it's from us
that's just pylint issue as far as I'm aware, the update_stats method is decorated with tasks.loop, so it must be a Loop object which has start and cancel method.
O didn't know abt that nice
Even if the port is opened up nobody will know which service is behind
And make sure to choose a port from range > 9000-65000
@plucky lance Any idea how I could say, once a user has voted.... do something
Cause python has something like that
But js doesnt
Im making a lb.
well you can easy create an instance of your Discord client (bot) and send a message to the user who has voted
Then I thought, why don't I do, once the webhook receives data, then add to the db, and that is what I'm doing with the webhook.
Well how?
I want to say
Once a user votes for my bot, then do something
just including djs and login the client like u're doing in your main bot
You need to setup a web server to receive post requests from topgg
how would I do that. Thats the thing
Use express
@barren kestrel https://docs.top.gg/resources/webhooks/#bot-webhooks
The webhook includes the user id
the py event isn't doing something else
you're basically getting a few informations about the vote, incl. the actual user id
a
You can take that user id and send him a message or what ever you like
But there's no info about the guilds the user is in of course, voting at topgg does only share your Discord user id
If you wanna send the user a DM for example, you will need to search your bots cache or try to fetch the user and if you got a positive result, send him a message
How can i set up my dbl on python.
Because i have some code using the on_dbl_vote event.
But i have the feeling i need to mention my auth code. where i do that?
@plucky lance It says my port is open, on that website and when I test it doesnt work
yeah I do remember that but I'm actually not sure if the issue is coming from topgg
I dont think so, since I can successfully receive webhooks if I'm testing it
so then what could be wrong/
I'm not exactly sure
my code
token
remove
cough
calm down, tokens can be regen
we dont want that
yeah, webhook topgg token
yeah the topgg API token
const express = require('express')
const app = express() // Your express app
const webhook = new Topgg.Webhook(config.topggwebhookauth)
app.post('/dblwebhook', webhook.middleware(), (req, res) => {
dwebhook.send(`<@${req.vote.user}> has voted for News Agent on top.gg!`)
});
app.listen(19555)```
even that can be abused
No i mean that part was only a wevbhook
not any top.gg stuff
I did that right
any as I said yesterday without actual sending a webhook to YOU from EXTERNAL I can not figure the issue out
If you don't wanna share your public IP you need to test it yourself
Send a webhook from OUTSITE your network to your endpoint (public IP, port 19555 as I can see)
and log the result and watch what happens
You may will receive an error code or information on the SENDER side why the RECIPIENT can't be reached
Ok hpow can I do that
Just send a webhook using JS, PHP etc. to your endpoint
But from outsite your network of course
I could send u one like I said but it would require to share your public IP...
privatly of course
How can I do that
in PHP using cURL for example, XMLHttpRequest for JS
yeah I explained that above already
But how do I do it?
I get the english but not the code
I want to say
Once a user votes, log them into the db
I have the db part
Yeah receiving the webhook from topgg includes the Discord user id; you gonna save that into your DB
SO I have to use a webhook
Ye
I just want in plain js
when user votes log them into db
Python has something like that
You can also do an API request getting the last 1000 votes
The response is an array of users who vote
[
{
"username": "Xetera",
"id": "140862798832861184",
"avatar": "a_1241439d430def25c100dd28add2d42f"
}
]
including their username and id
you can save this into your db
@plucky lance Ok but how do I use that in djs
and if the id exists already update the row or ignore the insert
you don't need djs for it
that's raw JS
using a lib to do curl requests for you
for example https://www.npmjs.com/package/node-fetch
Like this is so complicated to just get one single thing
lemme send you an example
ok
Also if I host my webhook on repl, and send a test, it spams the user multiple times
Idk why
fetch('https://top.gg/api/bots/<bot_id>/votes', { method: "GET", headers: { "Content-Type": "application/json", "Authorization": <dbl_token> } })
.then(res => res.json())
.then(json => console.log(json));
using the node-fetch lib
Yes because you need to response with HTTP code 200 (success) after successfully receiving the webhook
ok
this has nothing to do with discordjs
k
you gonna implement the code in a file which contains your DATABASE lib
and then save the received data in your database
wdym by that
my db will be json.sqlite
sqlite not json, right?
alright, never use json as db
ok
.sqlite is the extension
well then create a new project, index.js, whatever.js putting the node fetch code in it and the response you got from it will be saved in your db
ok
all you do in your new file/project is to send a request to the API using fetch and work with the response
in your case, saving the user ids from the response in your db
since it's always viewing the last 1000 voters make sure to ignore the insert if the user id is already found in your database
dunno how quickdb handles that, never worked with it
ok im doing the quickdb code rn
regarding that just on more note, you should be able to use repl to send a webhook to your endpoint (in your network)
with the example code I provided above for example and log the process to see if you're able to receive the webhook
ok so I can use that in repl?
@plucky lance do yk why the server count don't work for me?
can help you out with php, js etc. but not with py, sorry
I don't speak snakish 
All you have to do is to POST a stringified JSON body the topgg API incl. { "server_count": xxx }
for example using https://docs.python.org/3/howto/urllib2.html
Anyone know how to add a status to a bot in discord.py
the content types need to be json and your dbl token
more a question for discord.py / whatever lib you use
they all have discord servers for support
take a look into #development
that too
Alright, great
You can implement this into your bot for example, posting the server count inside the ready event
Adding an interval to repeat the post proccess any XXX time, for example each hour or 30 mins
Less doesn't really make sense; that said keep an eye on the API limits not to abuse them
how can i add the offline/online status of my bot on topgg
py?
there's no status you can set on topgg
That's the actual status of the bot, I guess
im not getting anything through when i test the webhook, do you know what i might be doing wrong?
the route is /topgg
i have it set to this on the site
and process.env.TOPGG is this
Hosted the webhook service at home?
!rang
its on a vps
with a cname attached to it
the site works fine
im just not getting anything printed on the console
does it need to be hosted on port 80?
since you didn't add a port the host it has to, yes
requires to allow incoming connections on port 80 TCP in your firewall
alright
thank you anyway :)
np
who loves goanimate and vyond and legacy video maker (lvm clones) me yes
who loves goanimate and vyond and legacy video maker (lvm clones) me yes
Why does he spam when some one vote?
You need to run an own webhook service in your environment
The public address or DNS will be your topgg webhook URL
hi does the on_dbl_vote actually works on dblpy? If it does, may I have an example of what you did?
I don't see why not
on_dbl_vote doesnt seem to work
guild post is working jsut fine
but in another cog the on_dbl vote does nothing when a vote is registered
even though it should print the data for the vote
Is your webhook functional?
Did you test it?
Hello, I would like to know if anyone has a reliable solution to be able to put APIs on shards, for example the API of top.gg, because otherwise there are the same two APIs on the same ports and the bot crashes (which makes sense)
Well you wouldn’t call it shards but the easiest way to do it is to use a load balancer to route the incoming API request to one of your instances/nodes.
For example multiple webservers running on the default port 80 can be the target of the load balancer
They need to run on different physical locations or at least on a host with multiple NICs
If not load balancing doesn’t make any sense at all
Ah ok I see, thank you for your solution
What's the best way of getting when a user votes for a server?
using webhooks
Or calling the API if doesn’t need be a "live" event
well it has to be a live event
Than what Hope said
basically I want to give users a role when they vote
there's a webhook section for servers
Well wasn’t even aware of that; good to know
oh thanks
wait, can I use the java library for this?
or do I have to learn spring to make my own api?
because it says it requires me to add a bot id
which isn't an option for me since my bot is private (made only for my server)
I don't think the current Java library has Webhook support, there's a few libraries on github specifically for webhooks
oh so spring would be the best approach
thank you
regarding my second question, do I need to add a bot to top.gg to do this?
for server webhooks, no
yeah something that still needs to be updated
but you should be able to find the settings on your server info section of your server page settings
fuck u
?
import dbl
from discord.ext import commands, tasks
import asyncio
import logging
class TopGG(commands.Cog):
"""Handles interactions with the top.gg API"""
def __init__(self, bot):
self.bot = bot
self.token = '' # set this to your DBL token
self.dblpy = dbl.DBLClient(self.bot, self.token)
# The decorator below will work only on discord.py 1.1.0+
# In case your discord.py version is below that, you can use self.bot.loop.create_task(self.update_stats())
@tasks.loop(minutes=5.0)
async def update_stats(self):
print("update")
"""This function runs every 30 minutes to automatically update your server count"""
logger.info('Attempting to post server count')
try:
await self.dblpy.post_guild_count()
logger.info('Posted server count ({})'.format(self.dblpy.guild_count()))
except Exception as e:
logger.exception('Failed to post server count\n{}: {}'.format(type(e).__name__, e))
# if you are not using the tasks extension, put the line below
await asyncio.sleep(300)
def setup(bot):
global logger
logger = logging.getLogger('bot')
bot.add_cog(TopGG(bot))
this wont work
still says N/A
any errors?
no unfortunately
then you most likely didn't run it, add a few debug lines
ok
it doesnt print
nothing
weird
this api doesn't work for a lot of people
can I just send a https post to the api?
yes
How would I include how many servers my bot is in?
Hi i need help using webhooks
use the autopost one and make sure to copy your token and press save that was my issue that's most likely is your's also
which webhook?
I fixed with autopost that is not manual
ok
I didnt quite get this documentation I need help to show server count
hi
No problem I got it
Oh
What is the meaning of shards?
Hey how i can fix that ?
How ?
I'm a bit confused on what the webhook api does?
Ah, okay, so when i try and test it, it says sent the test message but I never received it.
on my webhook
how to check if a member voted for my bot I can't find enough information for discord.py in the docs
ah, hm lemme double check.
I want to check if a member already voted , not only if someone votes
The server count comes up in the bot page but when I refresh the page it disappears how can I fix it
import dbl
import discord
from discord.ext import commands, tasks
import asyncio
import logging
class TopGG(commands.Cog):
"""Handles interactions with the top.gg API"""
def __init__(self, bot):
self.bot = bot
self.token = 'dbl_token' # set this to your DBL token
self.dblpy = dbl.DBLClient(self.bot, self.token, webhook_path='/dblwebhook', webhook_auth='password', webhook_port=5000)
# The decorator below will work only on discord.py 1.1.0+
# In case your discord.py version is below that, you can use self.bot.loop.create_task(self.update_stats())
@tasks.loop(minutes=30.0)
async def update_stats(self):
"""This function runs every 30 minutes to automatically update your server count"""
logger.info('Attempting to post server count')
try:
await self.dblpy.post_guild_count()
logger.info('Posted server count ({})'.format(self.dblpy.guild_count()))
except Exception as e:
logger.exception('Failed to post server count\n{}: {}'.format(type(e).__name__, e))
# if you are not using the tasks extension, put the line below
await asyncio.sleep(1800)
@commands.Cog.listener()
async def on_dbl_vote(self, data):
logger.info('Received an upvote')
print(data)
def setup(bot):
global logger
logger = logging.getLogger('bot')
bot.add_cog(TopGG(bot))
How to get which member voted in on_dbl_vote ?
@Mantaro
Is there any alternative to this url , I want to do this same thing but by dblpy https://top.gg/api//bots/805030662183845919/check?userId=
Just make a request to it
hey, i have in index.js
const express = require('express')
const Topgg = require('@top-gg/sdk')
const app = express()
const webhook = new Topgg.Webhook('process.env.TOPGG')
app.post('/web', webhook.middleware(), (req, res) => {
console.log(req.vote.user)
bot.channels.cache.get("812602214954565672").send(`<@${req.vote.user}> has voted for me on top.gg!`)
});
app.listen(5000)
``` but idk why the bot dont log/send any message when someone votes
im hosting the bot with heroku
not my pc
ok
I have a doubt the server count comes up in the bot page but when I refresh the page it disappears how can I fix it
in this or in the code
k
8080 didnt worked
but i have a question before trying 8000
my webhook url need to be like this?
as i host with heroku, it needs my ip in it too?
idk where i can find my heroku url 🙄
Heroku has docs for it
Is the discord bots analytics thing accurate coz in that it is showing 3 votes but in my bot page it is only showing 1 vote
nope searched everything and nothing about heroku url
I’m confused on how this works. Will it send when it’s voted and stuff to a discord channel?
I am getting {"error":"Unauthorized"} on accessing url f"https://top.gg/api//bots/805030662183845919/check?userId=488643992628494347" by requests python
Have you sent the token in your authorization header with it?
token?
i only did exactly access this same link
in web browser it didn't require a token
in the link?
Ok , thanks
same error
send your code on how you do it
How to show the number of bot servers on the site
def uservoted(member:discord.Member):
link = f"https://top.gg/api//bots/805030662183845919/check?userId={member.id}"
headerstoken={"authorization":"MyTokenHere"}
f= requests.get(link,headers=headerstoken)
ftext=f.text
print(ftext)
myfile=json.loads(ftext)
votereceived=False
if myfile['voted']>=1:
votereceived=True
return votereceived
is javascript ??
..
@marsh cedar if you use discord.py, use aiohttp instead of requests
You can bool() the voted key to work with boolean directly, but you got the gist of it
P.S. iirc requests has .json() method on responses
Is something wrong in this??
