#topgg-api
1 messages Β· Page 129 of 1
is a function or what
node-fetch takes a string as body
try removing the .then() bits
you gotta use JSON.stringify using node-fetch
oh yea that too
Thank you, I have already done this with other requests, so it was also necessary here x)
will be renamed to get_bot_votes in next version
alkr alr
hwo do i use get_bot_upvotes()
what parameters do I use?
Is anyone will tell me, how to request for server count api, like this
server_count = len(self.bot.guilds)
await self.dblpy.post_guild_count(server_count)```
you can put that in a loop
again
and it can update
We told you multiple times that you can't post server count with BDFD
surprise surprise using bot makers has its own restrictions
My other bot owner have d.js
Thanks
That's Python
^^
See pins for the library
Also i figured out how to get the voters, thanks @sullen nymph
hello hello
now i have to see if there is a built in discord.py checker i can use before commands are used
wait sp can we use this api to detect if a specific upvoted?
How do I use web hooks to give someone a role if their voted for the server? When I try I get error saying it can only be used in external services
@icy thistle show your error and code
im very confused on this webhook thing, anyone got a tutorial or something like that to guide people through it?
how can you send a dummy vote
use the "test" button on the webhooks page
kk
im not using thier webhook system though
if im not wrong you can just do it with thier api.on("vote")
um it didn't really work out btw
nothing happened
can someone help me with the top-gg/sdk
im using the api for it and im trying to get my client to display a message when someone votes
is it possible if im using the api().on()
or does it only work with webhooks()
please @ me if you know the answer
where is the api?
top-gg/sdk.Api()
@restive otter you need to use the webhook
API is solely for API requests to top.gg
oh ok then
And it's a vote event in any case
To handle differences between test and actual requests is up to you 
how would i create a webhook link so that it sends it to my vps and then my bot file?
a way so when user votes up your bot it gives them a role..
uh.
ping me if you know
o k
can i do with discord webhook?
nope
hey so, my webhook works, ive tested with postman, problem is that when i test it on top.gg's api it doesnt work
routes = web.RouteTableDef()
@routes.post('/webhook')
async def hello(request):
print(await request.read())
return web.Response(text='Successful!')
app = web.Application()
app.add_routes(routes)
web.run_app(app)
using aiohttp.web
when you test, are you testing on the same network/device as the webhook?
Webhook for vote ?
is there a function i can call that checks if a specific user has voted in the last 12 hours?
nvm i found it on the docs
how can total servers be seen on my bot page?
@gilded orchid what language are you using?
Node.js
@hearty lintel
k
const ap = AutoPoster('topggtoken', client) // your discord.js or eris client
// optional
ap.on('posted', () => { // ran when succesfully posted
console.log('Posted stats to top.gg')
})```
only this much at starting of my main file will post server count?
you need to define client before it of course
yes but thats it right?
should be, try it
yes it worked thank u
hello, how to auto give role to user who voted for my server on top.gg
after 12 hours i want to remove the role from the user and send dm to the user to vote again to get back the role
hoe do i make it send a message when someone votes
from aiohttp import web
routes = web.RouteTableDef()
@routes.post('/webhook')
async def hello(request):
print(await request.read())
return web.Response(text='Successful!')
app = web.Application()
app.add_routes(routes)
web.run_app(app)
Webhooks, give the user the role, make a scheduled task and remove the role after 12 hours, then dm them
Make sure that the user is on your server too
how do i make it send a message when someone votes
Just get a guild channel and let it send a message to it after a valid request came through the webhook
idk discord.js i only know dbd.js
and idk a single thing about this api
Read the docs from dbd.js
okay...
then where do i go
Read the webhooks section
okay
is there on for the servers
For the servers one, you'll need to make your own webhook
The dsl webhooks scheme is on the pinned messages aswell
Api
Hey, How to make vote messages? Ping me
hey so, my webhook works, ive tested with postman, problem is that when i test it on top.gg's api it doesnt work
i dont get how to use this webhook thing
routes = web.RouteTableDef()
@routes.post('/webhook')
async def hello(request):
print(await request.read())
return web.Response(text='Successful!')
app = web.Application()
app.add_routes(routes)
web.run_app(app)
i mean the vote notifs when someone voted webhook thing
did you enter the correct url?
your webhook url
Yeah
How to put out translater?
I copied directly from post
did you also change it?
Wdym
your webhook should be http://yourserverip:port/webhook in your case
replace yourserverip:port with the corresponding server ip and port
Yeah
server ip being the ip your bot is hosted on
I did
You need to save it before being able to use the test button
Oh
What Must i do with my bot api Key
Mk thanks
Your dbl api key
not bot key
read the documentation for your corresponding library
and the pinned messages here
In the future please donβt copy peopleβs code randomly, itβs insanely obvious you copied it considering you code in js but that code below is in python
I have read the docs. How Can i use my dbl api Key top make Vote Message
if you have read the docs, you should know how to use it correctly
for your corresponding language
Okay thx
@rain heart i tried http:ip:port/webhook, what i used on postman and it still didnt send
http://
o
for example http://111.222.231.12:5000/webhook would be correct
import dbl
import discord
from discord.ext import commands, tasks
import logging
class TopGG(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.token = '*CENSORED*'
self.dblpy = dbl.DBLClient(self.bot, self.token)
@tasks.loop(minutes=30.0)
async def update_stats(self):
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))
def setup(bot):
global logger
logger = logging.getLogger('bot')
bot.add_cog(TopGG(bot))
Why is this code not working?
hmm
Why is there an error on
you need to initialize dbl with an auth and a port.
dbl.webhook.on('vote', vote => {
console.log(`User with ID ${vote.user} just voted!`);
});
Already exist
const dbl = new DBL(yourDBLTokenHere, { webhookPort: 5000, webhookAuth: 'password' }, client);
What is the password
you can make it any string, its your choice
you need to add the webhook stuff, otherwise it never creates the .webhook.on stuff.
I don't need it in webhook I want to send a message to a member
if you dont want a webhook, then why are you using it in your code?
I have read the docs and I am trying to post server count. @shut flume
Why is this code not posting my bots server count?
import dbl
import discord
from discord.ext import commands, tasks
import logging
class TopGG(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.token = '*CENSORED*'
self.dblpy = dbl.DBLClient(self.bot, self.token)
@tasks.loop(minutes=30.0)
async def update_stats(self):
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))
def setup(bot):
global logger
logger = logging.getLogger('bot')
bot.add_cog(TopGG(bot))
please provide some error and quit sending your message over and over again
the authorization for your webhook request
it should be the same you enter on your bot page settings
it verifies that the webhook request is coming from top.gg
ah
thankks!
so for example, i put in "hi" (example lmao) in the verification thing on the bot page
and after that the same thing in "webhookAuth"
"hi"
yes
ok, thanks
that would tell your webhook "oh, this request is indeed coming from top.gg, i can use it"
if it is not "hi", then it would say "oh this is not from top.gg, i should not use this"
in a string, right?
Yes
thanks for explaining that!
@rain heart alo, i need your help again (sowwy!)
so basically everything works fine, it says that the webhook is ready, etc
well if someone votes the webhook wont send the vote messsage
did you press save aswell? is the url format correct?
http://serverip:port/webhookcontext
replacing serverip with your servers ip, port for obviously port and webhookcontext with ending url you entered in webhookPath iirc
anyone knows how to check if someone voted for your bot in .py library
hello dbd.js do you have api?
to vote
dbd.js does not have a top.gg api, but since it is js aswell, i assume looking through the pins doesn't hurt
thx
I am looking at the translation, I did not understand what you said.
π

So can't I do it from dbd.js? @rain heart
You could, if you could 
Where do I get a token? I have searched google and haven't been successful
Sorry and there are no errors
i want someone help me how to add youtube search api in my code
do u use python 3.9 or 3.9.+?
3.9
hello?
hi
ghost ping, im not crazy 
Do someone know a good api that gives you random picture link? Such as Shiro api etc...
Plz mention I'm going to sleep π π€π€
How do I check when someone voted on my bot, and who. Im using the need to know that, how to use api and get auth if needed
that package is deprecated
do you have any idea how to get the DBL token?
how?
ohh
ok tysm
will it take some time to come on the web?
nvm
it works ty
anyone know i have to allow port in my ubuntu vps, but still cannot access from webhooks?
OK will do that ty
how do i send a message into a discord channel when someone votes for the bot via webhook
@ebon igloo Iβm not sure if this will help ! But it does have something related to do with wat ye want
This video is for how to setup vote tracker bot in your server which automatically attributes person who voted your server in top.gg server list.
#votetracker #discord #discordhelp
:linkπ:
β’ BOT :- https://top.gg/bot/702134514637340702
____...
ty ill look at it in the morning
Np
Any updates on when the python sdk will fix the http request issues on 3.9?
Also if I make a PR would it be accepted?
Both depend on the corresponding library dev
- Within the next few days. I already fixed it, just need to push an update.
- See point 1

Aight cool thank you!

Hello. I want my bot to detect users who voted from top.gg. Although I do everything as on the documents, nothing happens when someone votes. I think I entered the webhook part on the site incorrectly. What should I get into that part?
http://yourserverip:port/webhookPath
I probably have no clue about your programming language, i can only tell you to test it with postman for example
Oh, thank u.
import dbl
import discord
from discord.ext import commands
@commands.Cog.listener(1800)
class TopGG(commands.Cog):
"""Handles interactions with the top.gg API"""
def __init__(self, bot):
self.bot = bot
self.token = 'here my dbl token' # set this to your DBL token
self.dblpy = dbl.DBLClient(self.bot, self.token, autopost=True) # Autopost will post your guild count every 30 minutes
async def on_guild_post():
print("Server count posted successfully")
def setup(bot):
bot.add_cog(TopGG(bot))
why don`t work ??

Well the function isn't getting called.
You need to decorate it with commands.Cog.listener()
Also this appears to be an extension so you don't need to define client here.
And your setup function takes bot as a param but uses the defined client from the global scope.
Which isn't even a running instance, and shouldn't even exist.
now ?
Still haven't decorated the function that does the print
You've decorated the setup
Have you worked with cogs before lol
no
There's examples in dpy's docs if you want to have a look
i use functions only i don`t know this cogs
Well TopGG in your code is a cog
what cog do ? same function or what?
Go to dpy's documentation page and search for label: extensions
Actually cogs are classes. Subclasses of commands.Cog specifically.
And this is outside the scope of this channel.
ok thank you
import dbl
import discord
from discord.ext import commands
@commands.Cog.listener(1800)
class TopGG(commands.Cog):
"""Handles interactions with the top.gg API"""
def __init__(self, bot):
self.bot = bot
self.token = 'here my dbl token' # set this to your DBL token
self.dblpy = dbl.DBLClient(self.bot, self.token, autopost=True) # Autopost will post your guild count every 30 minutes
async def on_guild_post():
print("Server count posted successfully")
def setup(bot):
bot.add_cog(TopGG(bot))
it must work now or what?
@green roost
No
I'd suggest you read the documentation of discord.py and join their support server for further questions like this. This is not related to the top.gg API and therefore irrelevant to this channel.
ok thank you i will try
thank you for your time

dblapi.js has been depreciated?
I believe so yes
then what wrapper is good after dblapi.js
3.9
Python 3.9 isn't supported by dblpy yet
here
hi how do i use api with ts bot with a class instead of the = new Discord client
Keep an eye on the docs and this channel. I'll post a small message here when I release a full-on release
This expression is not constructable.
Type 'typeof DBLAPI' has no construct signatures.
Ok, Can you ping me?
Type originates at this import. A namespace-style import cannot be called or constructed, and will cause a failure at runtime. Consider using a default import or import require here instead.
the package has a problem :///
I'll try not to forget to π
Are you using dblapi.js or @top-gg/sdk?
dblapi.js
oh
yeah speaking to the team right now to see if we can get the js page updated
ok
I've stopped in here a few times recently about the weekend multipler always giving the weekend reward. I verified that the voting is working correctly. Single vote for week day and double vote for weekend. Is anyone using the multipler with Python and if so are you using an if statement or some condition to check if its the weekend for the actual reward?
The python lib has a property called isweekend, its on the docs. It might also be sent with the vote webhook.
Yep its sent with the vote webhook.
https://top.gg/api/docs#webhooks
You can just if statement the property.
Gotcha ya. Im going to look over this link real quick. Thank you very much
@bot.command()
async def is_weekend(ctx):
await ctx.send(bool(dblpy.get_weekend_status()))β```
That just returned true
So a webhook must be used?
I forget what timezone the site uses, its still weekend in some places.
get_weekend_status()[source]
Gets weekend status from top.gg.
Returns: weekend status β The boolean value of weekend status.
Return type: bool```
Hmm even though I tested the actual vote and its only counting as 1? I verified and it counted as 2 yesterday
Nvm I think we got it working!
Oh pog.
Yay shiv to save the day
I pronounce you officially murdered
That's what I was about to mention, but the docs didn't mention its async
Well i was only helping the dev but he didn't realize it was a async
Yes that's exactly what he said lol
Thank you for your help:)
Ah
top.gg considers Friday 00:00 to Sunday 23:59 UTC a weekend so you can technically check that yourself without an API request if you want
I need help, when i try testing the webhook on the site it gives a 400 error in the developer console
Hey, the roles reward for voting don't work on my serv
hey! using @wild lantern right?
yes @jaunty plank
Did you fill in the reward role on your servers edit page?
aand vote rewards dont work as expected
no
and I've checked, the DSL's role got all the perms and it's higher than the voter's role
so ?
you can try kicking and readding @wild lantern
Is it possible to use the api to post your bots own server count on your own server?
i dont know why you would need the api for that. you can just send a message(or edit an existing message) with the current server count on your server.
Oh i meant website not server sorry. I want to have a static website showing the bot count and when you refresh the bot count refreshes too
So if it is possible to get the bots server count via one simple javascript file
i dont know why you would need the api for that either, you can just get that from your bots process too.
But the bot already posts this online so if it is possible to get that in the same way the top.gg gets it
pretty sure its going to be more complicated than just using the data you have already, but yeah, you could make an api request.
you will only be able to get it 60 times a minute max(api ratelimit) so caching would be a good idea. youll also want to do this server side not client side.
minute not second lol
My bot is not that popular so I just want to request it once. But do you have docs for that?
youll be wanting to send the request to the "get bots stats" endpoint second from the bottom.
https://top.gg/api/docs#bots
Thanks
ok ty
Does the on-vote webhook require https?
You can only use http
anyone can help me?
ok lol
im using dbd.js language and they was able to make a vote
so
name: "$alwaysExecute",
code: `
$title[VOTE;https://top.gg/servers/$guildID/vote]
$description[Thanks for voting this server up $username remember to revote in 12 hours!!]
$footer[You can vote by clicking on title!]
$addTimestamp
$color[$getServerVar[Color]]
$onlyForRoles[$getServerVar[voteroleid];]`
});```
idk how worked lol
so basically i need to write in HTML a script that will count how many guilds the bot is in?
No you need to read the docs
i did, and im still lost.
Could you explain it to me? please
you can pretty much just copy and paste the code for whatever language your using
just add your bots top.gg api token to it
Hi
sooo here it;s necesary just to install npm dbl and after to put this script in my bot with my bot api key (token)?
Hey, I'm trying to make it so I can vote lock commands.
I've got all this down but I am confused
import discord
from discord.ext import commands
import dbl
def has_voted():
async def predicate(ctx):
check = await ctx.bot.dblpy.get_user_vote(ctx.author.id)
if check:
return True
else:
e = discord.Embed(title="", description="This command is vote locked. to use this command, please [vote here](https://top.gg/bot/758073269961359392/vote)")
await ctx.send(embed=e)
return False
return commands.check(predicate)
AutoShardedBot has no attribute dbl, how can I specify this to work properly? Thanks!
kinda braindead rn so yeah-
instantiate the DBLClient and assign it as a bot attribute, then you can use it in that way
though, you shouldn't do that, better cache the votes rather than making requests each check
wdym assign it as a bot attribute?
Like self.bot = DBLClient or smnthn?
im deadass braindead rn
DBLClient alone is a class, not an object. So instantiate it
so a def init somewhat?
huh? Do you know how to instantiate an object?
it's just as simple as calling the class as how you would do with a function, it'll call the __init__ automatically, so you shouldn't care about that
how are you making a bot without instantiating the bot itself then 
π don't forget to cache votes though
Hi
what are the needs for on_bdl_vote to works?
bruh i am gonna ask if a webhook is needed
since it appeas it doesnβt work in my code
then webhook is needed?
hm
i tested it but it doesnβt appear to work
nope
i will see
how to using top-gg/sdk webhook with multiple shard bot
Why it's show an Error?
token should be a string
?spiele hallo
Is there an api for when someone votes a server?
Yes
Is there a doc for it?
All I see is API when someone votes the bot
Yeah but all I see it bots. no server
wow
The server webhooks need to be fully done yourself, there's no library support for them
if you need the json schema, see pinned messages
Can someone give me a very basic run down on how to make a automatic claiming reward for when someone votes for my bot and DM's them saying that they did vote
read this to get started, though remember that the bot needs to share a server with the user in order to send the dm
and the user having dms enabled
How do I make 5000 port available to my server ip? I've tried the method that involves the firewal
Could you tell me how?
How do you make it so the user would have to vote to gain access to certain commands
Thanks
dbl.hasVoted("95579865788456960").then(voted => {
if (voted) console.log("Tonkku has voted!!!")
});
Where it has the ID, is that the Bot's ID or should I put the members ID?
Okay thanks
For this https://github.com/top-gg/node-sdk/blob/master/docs/Webhook.md do I need to download anything or can I just copy past this into my code and it will work
If you installed the wrapper, yes it should work
How do I add an else to it?
dbl.hasVoted(message.author.id).then(voted => {
client.commands.get('command_name').run(client, message, args)
})
That's the code but it's not even an if statement
voted is a boolean
if (voted) {
// user has voted
} else {
// has not voted
}
in a nutshell
Where can I find the wrapper?
pinned messages
This channel?
Oh okay thanks again lol
yes
How to use this API in python?
Sorry if it's basic, but am new to all this api and stuff
Hey
Add me please
?
Error: postStats requires 1 argument
``` I get this error
I pass one argument lol, happening since I am using discord.js-light
Hewo, where do I put the webhook in the API?
the url?
yes
it goes in your bots edit page, webhook section
the url will probably look something like this
http://VPSIPHERE:PORTHERE/dblwebhook
if you have any success please let me know
?
made both guild and bot webhooks with my own java library 
its dead simple with a programming language
i want to do it like it is on github, simple
then follow the tutorial mentioned there
here ?
the one on github, or read the pins on how to make webhooks for it
where?
on your bot page settings under webhooks
http://ip:port/path
replace ip:port/path with the corresponding server ip your bot is posted on, the port your webhook is on and the webhook path you've entered
well you probably messed up something in your request
so im using a vps that has a domain name as ip, thats also works?
yep
aiohttp.http_exceptions.BadStatusLine: 400, message="Bad status line 'invalid HTTP method'"
no and this is not the right place to ask this
I need help
const DBL = require('dblapi.js');
const dbl = new DBL(yourDBLTokenHere, { webhookPort: 5000, webhookAuth: 'password' });
dbl.webhook.on('ready', hook => {
console.log(`Webhook running at http://${hook.hostname}:${hook.port}${hook.path}`);
});
dbl.webhook.on('vote', vote => {
console.log(`User with ID ${vote.user} just voted!`);
});
how do I find my dbl token and what's this webhookAuth: 'password'
webhookAuth is the key thst identifies top.gg on your webhook
and where I can find that?
Create it yourself
the password
Name it whatever you want
oh ok
As long as you also enter it on your bot page settings
Yes
sry for the ping btw
ok
Try testing it out if you're unsure
Is the DBL webhook down for anyone else? It could just be something on my end; however, my bot stopped receiving updates π€

Interesting. Must be something on my end. Thanks for testing that!
Hmm... perhaps. I'll check it. Thanks!
It shouldn't have, but it's always good to check.
I'm hosting it from a VPS
Good point. Funny enough, I don't send any response back π
But, I guess, if it errors out ... I'll know.
webhook doesnt work when I test it.
I have created a hook for my announcement channel and copy-pasted it to Webhook URL in top.gg of my discord bot.
But it does not display anything
Omg, I can't believe what I just did. I commented out the code that contains the webhook server portion and pushed it to master.
pain
This is why you shouldn't push to master before testing locally
is there a top.gg api for discord.py?
Pins
I did test locally. I commented out the code locally so that I could test it ... and did git add --all π
soo there isnt?
I should have an environment condition have disable it when testing.
is there a work around, or it does not work with discord ? the app this site is built upon ???
lmao
you have to write your own server to receive the webhook requests and fire the discord webhooks
pretty poor decision making by their part tbh
thanks for the reply
um it's not poor decision making but ok
could have two separate
i mean writing a basic server isn't that hard
Top.ggs general goal with webhooks is to allow rewarding (vote tracking), not simple notifications. You can simply make a webhook that sends notifications into a channel if you wish to
and making two separate webhooks would be really difficult to manage
I know that I can make is easily, the point is to not have one more thing running, it's ok though it would just an extra nice thing to have
aight ima head out
If needed, you can run the webhook server alongside your bot on the same server or leverage an AWS serverless API gateway (which is free for the first 1,000,000 requests per month)
where's i can find the password, i just only found the token
js code for webhook lol
anyone knows
whats the link
for submitting bot
ty!
not found idk why
eh
okay
where is it in site
I dont find it in site
ty
lmao
will do that some time, but not right now, thanks
then ask in #development
yes
Ok, thanks
hi
im here to ask about how i can get votes in channel ex : when someone votes it sends in channel
Is this the place to put the webhook?
its not a discord webhook
Then how ^^"


Path can be anything. You can just leave it as the default (/dblwebhook)
On the webhooks tab on the website, you pass in the webhook URL as http://your_ip:port/path
What is api
can anyone help me how to do vote command but when u vote it gives reward
how to do it
set up a webhook server
in python
check the docs for dblpy
is it this site?
https://pypi.org/project/dblpy/
well it has an example so ig you can use that
it has only cogs as example.. I'm using main file only.
just use the python library 
hmm
You can literally convert the code for your main file 
yea but idk cogs, im watching a yt vid rn
on cogs
Just initialize the DBLClient with webhook args and the webhook will activate itself automatically
but idk how to convert cmds
(P.S. will be changed in v1.0.0)
What are you trying to convert there
You just do bot.dblpy = DBLClient(...) and then use the events

i have a main file like 750+ lines
main file
what will the dots be?
rtfd
Actually hold on I updated them for 1.0.0
webhook_port is the port the webhook will run on (type int)
webhook_path can stay '/dblwebhook'
webhook_auth is a password your webhook will use to authenticate requests to confirm that they are coming from top.gg (must be the same as Authorization field on the bot's Edit page in Webhooks section)
i dont get it
Example:
bot = commands.Bot(...)
dblpy_token = "top.gg token if needed, could leave this empty"
bot.dblpy = dbl.DBLClient(bot, dblpy_token, webhook_path="/dblwebhook", webhook_auth="password", webhook_port=5000)
The code above will generate a webhook on the following URL: http://your.machine's.public.IP:5000/dblwebhook
In order to actually use the webhook, you'll have to own an approved bot on the website
oh im getting reviewed
so if it is client instead of bot, in the 3rd line should i change bot to client
yes
ok
Any reference to bot, pretty much
k
if i run it then only i will get the URL
I don't understand what you mean
how will i get the url
yes how will i get that
Your machine's public IP address?
if i run the code will i get the url
yes
Do you use a VPS?
no
You host locally?
hm is there a way to get the time a user can vote again? me using py btw
Anyonne had Fennec for free
wrong channel
Wher is the real chanel
But can't u do like dank memer...
track that yourself is what dankmemer does
If you want to get the exact time a user can vote again, you need to do that yourself
Because top.gg's api only allows checking for votes, not when they can revote
somehow i still get this:
aiohttp.http_exceptions.BadStatusLine: 400, message="Bad status line 'invalid HTTP method'"
and how do i do that?
How can I show how many servers my bot is on
@uncut granite What language?
Python
aiohttp
Here's your code lol:
@client.event
async def on_guild_join(guild):
data = {"server_count":len(client.guilds)}
auth = {"Authorization":"Top.GG API Token"}
async with aiohttp.ClientSession() as cs:
async with cs.post('https://top.gg/api/bots/botid/stats',headers=auth,data=data) as r:
json_obj = await r.json()
If you use bot instead of client, replace client with bot. Replace botid with your bots ID, and Top.GG API Token with your API key.
Where do we write the api?
@uncut granite
?
Where to add the api?
wait whut
@uncut granite That's the code if you're using Discord.py
Basically whenever you join a server, it'll send a POST request to Top.gg
@manic rune In your bots code, run it whenever you join a server.
interesting
I can't put my bot on vds. Is there any helper production?
process.exit(1)
question why doesnt this image work? https://top.gg/api/widget/servers/771932435449249862.svg
i think .svg isn't supported
<a href="https://top.gg/bot/771932435449249862">
<img src=" https://top.gg/api/widget/servers/771932435449249862.svg" alt="[name]" />
</a>```
Ok im new to all this webhook stuff
Hello
i made a webhook (i think) using @top-gg/sdk and like copy pasted the vote stuff
does myip:port/dblwebhook work as a webhook link and can i use it on sites besides top.gg
do you put in index.js file
yeah
ok
Hello! I am having a little trouble in implementing the vote feature on my discord bot. I tried to do it yesterday, but it won't even log the event or an error message when I voted with a test account. Help will be much appreciated π
db.add(`apples_${vote.user}`, 1);
db.add(`eggs_${vote.user}`, 1);
let voteembed = new Discord.MessageEmbed()
.setTitle(`New Vote from Top.gg!`)
.setDescription(`${vote.user.tag} Just voted!`)
.setThumbnail(`${vote.user.avatarURL()}`)
.setTimestamp()
bot.channels.cache.get('channel-id').send(voteembed)
console.log(`User with ID ${vote.user} just voted!`);
});
(btw this is discord.js)
That's not for events, if you want to receive voting events, use webhooks
Is there a way to have something similar to that in the bot though?
voting events, no
webhooks is the only way
you could check if a user voted manually, by using the same method, but reading the proper usage on the docs
Alrighty
When will the status tracking problem be resolved? My bot is online but in top.gg offline xd
when the api gets updated i assume

the body in DBL's request to my webserver is undefined. Any reason π€
@hearty lintel you may know
are you using the library or your own thing?
own thing
are you using a body parser
no
you need a json body parser
such as https://github.com/expressjs/body-parser ?
sure
you can also just use the library where it's built into the express middleware
thanks
at IncomingMessage.<anonymous> (C:\Users\Dell\Desktop\MasaΓΌstΓΌ\kodlar\denemebot\node_modules\dblapi.js\src\index.js:118:25)
what is this
Very unhelpful traceback, need more details
(node:1548) UnhandledPromiseRejectionWarning: Error: 401 Unauthorized
at IncomingMessage.<anonymous> (C:\Users\Dell\Desktop\MasaΓΌstΓΌ\kodlar\denemebot\node_modules\dblapi.js\src\index.js:118:25)
at IncomingMessage.emit (events.js:327:22)
at endReadableNT (internal/streams/readable.js:1327:12)
at processTicksAndRejections (internal/process/task_queues.js:80:21)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:1548) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection,
use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:1548) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
@sullen nymph
also dblapi.js is deprecated
ew dblapi
.,
what's the difference between mod, webMod and admin in the user object?
also supporter refers to if the user has premium right?
admin is website admin ofc
webmod is website mod (though mod and webmod are the same thing iirc)
supporter is premium i assume
test it on me because i do have premium
{
"discriminator": "0001",
"avatar": "a_c11a553ea1b8ec378b234469b7c45949",
"id": "669452973755072524",
"username": "Aurel",
"defAvatar": "322c936a8c8be1b803cd94861bdfa868",
"bio": "Bot-Reviewer",
"color": "#002270",
"admin": false,
"webMod": false,
"mod": false,
"certifiedDev": false,
"supporter": false,
"social": {}
}
not sure what supporter is then
docs good
also certified dev is in relation to if the user has a certified (the old program) bot, correct?
yes
that's something you can test on 212530298259374080 (@bold fulcrum)
it appears so yeah
is there a list of outputs that can be given by the lib attribute of a bot?
I want to make an enum but need to know the values
the lib attribute is deprecated, no need to implement it
as bots can no longer set their library
fair
yeah I just noticed that
Wait is the longdesc attr optional?
I thought bots had to have a long description?
hm? where
I assume the ? means optional/nullable
yeah not sure about that one
Little late, but yes, in documentation ? After a return or variable name means nullable.
cool ty
retry-after integer Indicates how long the timeout period is/when you will be able to send requests again
this is in seconds right? or milliseconds?
I should probably just look at how the SDKs handle it
in Seconds
ok thank you
not sure what you're referring to with foreign api clients
non-official
alr cool ty
*help
@commands.Cog.listener()
async def on_dbl_vote(self, data):
print(data)```
this not work anymore?
π¦
Idk
I wouldn't think you would know because you don't have the bot developer role
But i make cool bot
I'm talking about the topgg API, I wouldn't expect you out of all people to know how to use it
where did you get this
is it new endpoint
It does. Check the logs to see if the webserver is running fine.
hello, i am getting a bad request with the top.gg webhook
everytime i test the weebhook
show code
just a second
import sys, datetime, json, re
from discord import Webhook, RequestsWebhookAdapter, Embed, Color
from flask import Flask, request, abort, jsonify
from pymongo import MongoClient
import os
with open("settings.json") as settings:
data = json.load(settings)
webhook_password = data['webhook_password']
discord_webhook = data['discord_webhook_url']
if discord_webhook != "":
webhook_id = int(re.search(r"\d+", discord_webhook).group())
webhook_token = re.search(r"(?!.*\/)+(.*)", discord_webhook).group()
mongo = MongoClient()
app = Flask(__name__)
@app.route("/")
def index():
return "<h1>Bot is running</h1>"
@app.route('/test', methods=['GET', 'POST'])
def test():
return jsonify(dict(request.headers))
@app.route('/dblwebhook', methods=['POST'])
def webhook():
sys.stdout.flush()
if request.headers.get('Authorization') == webhook_password:
user_id = request.json.get('user')
bot_id = request.json.get('bot') # ID of the bot that was upvoted
request_type = request.json.get('type')
weekend_status = request.json.get('isWeekend')
now = datetime.datetime.utcnow()
mongo.voters.vote.insert_one({
'type': request_type,
'user': user_id,
'bot': bot_id,
'weekend': weekend_status,
'time': now
})
if discord_webhook != "":
embed_title = "Test" if request_type == 'test' else 'New upvote!'
embed = Embed(title=embed_title, description=f"**Upvoter: <@{user_id}>** ({user_id})\n**Upvoted bot:** <@{bot_id}> ({bot_id})", timestamp=datetime.datetime.utcnow(), color=Color.green())
webhook = Webhook.partial(webhook_id, webhook_token, adapter=RequestsWebhookAdapter())
webhook.send(embed=embed)
return '', 200
else:
abort(400)
if __name__ == '__main__':
app.run(host='0.0.0.0', port=1129)
mongo.close()
Oh hey that's my example
Anyhoo, what line does the error occur on?
idk tbh, its a bunch of unknown error, comes as bad request everytime i test the webhook
i will show an image
Sure
what da fak
ikr i couldnβt figure out whats the issue
yes, and im sending the requests through my hosterβs url
Huh
Ah
Using the node-sdk can you check if it is authenticated?
/users/{user.id} https://top.gg/api/docs#users
The old lib always says 0.0.0.0
That's the old lib
2.4.1
Check pins
riight?
Dblapi.js is the old lib
ok what i need
Check pins
i dont know big english
only i writiing
@waxen widgetgg-auth
turkish
npm i @waxen widgetgg/sdk
i write it
oh boy, top is getting so many pings 
yes this is webhook?
I don't understand what this means
The last sentence
What is the HTTP header and all that
What programming language is your bot in?
Javascript
You can use the auto poster library so you don't have to worry about that.
In the autoposter section
ok
@feral palm
top.gg token
not your bot token
a
@jaunty plank how do i start is it same as bot?
If you make it in the same language and set it up the same yeah
thanks Iam using js ill take ur help :D
@charred ridge Could you DM me
Good! Could someone help me how to get data from a webhook for the top.gg api?
I saw that to get votes, a webhook with password, username and port is used. Someone help me?
how do you post shard count?
you need to parse it yourself using json, the json schema is listed on https://top.gg/api/docs
Sorry for the spam but it was for a report
yes, dm @jolly hornet
Is it possible to have votes for the and for the associated support server to be tied together
or will votes always be seperate
they will always be seperate
If you're referring to a bot and associated support server for example
yes specifically the associated support server
I feel like having users vote twice is alot to ask for
lol
most likely not going to be a thing, as both are seperate things
I feel like having users vote twice is alot to ask for
sorry that message didnt go through earlier
ok gotcha
hey im new in this api-thing..is there a way to listen for votes without any webooks?
nope
well, you could check every now and then for the users who voted for your bot, and check for any new users
but i'm pretty sure that's api abuse
oh ok
Is this channel for the discord api
I mean are discord.py questions relevant here
Ok
Yes
what?
Or no wait
Bruh
Ok
Thanks π
Can u tell me where i can ask questions for d.py
When/if i need to
it has 18 members wow
huh
lmao
correct server is discord.gg/dpy
Lmfao you what
This is the real python server ands itβs partnered too lmao
discord.gg/python
Iβll accept that mute then Β―_(γ)_/Β―
hehe
Can't save it until your bot is approved
ahk
@commands.Cog.listener()
async def on_dbl_vote(self, data):
print(data)```
is this supposed to work regardless of if u have the webhook stuff setup? i do have the dbl client setup in the same class though
No you need the webhook set up. Which is fairly easy to do you just need to pass in an unused port to the webhook_port kwarg
tbh it doesn't really matter if it's in different class as long as it's the same bot instance.
mind if i dm you? i have no idea how to do that 
Ya da lee da doo
I'd rather you didn't, keep it in this channel since it is topical
Read the docssss
To keep it short, webhook_port must be a port the webhook will run on, the rest is optional
webhook_path is the route to use, a string that comes after the IP and port in URL (must start with /)
webhook_auth is the Authorization key to use for confirming that requests are indeed coming from top.gg, basically a password
How to create webhook
when i used the test webhook button in topgg api website i got a response on my bot's server's console
"POST /dblwebhook HTTP/1.1" 404 -
is this the desired response im supposed to get?
code i wrote? ok
import dbl
import discord
from discord.ext import commands, tasks
from os import getenv
class TopGG(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.token = getenv('TOKEN2')
self.dblpy = dbl.DBLClient(self.bot, self.token, webhook_path='https://HandCricketBotDiscord.samirmishra127.repl.co/dblwebhook', webhook_auth=getenv('password'), webhook_port=8000)
@tasks.loop(minutes=30.0)
async def update_stats(self):
"""This function runs every 30 minutes to automatically update your server count"""
print('Attempting to post server count')
try:
await self.dblpy.post_guild_count()
print('Posted server count ({})'.format(self.dblpy.guild_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):
print("Received an upvote!")
print(data)
def setup(bot):
bot.add_cog(TopGG(bot))
Is this okay lol
I got an error when i set webhook_path to "/dblwebhook"
what's the error
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x7f34d80f5580>
Task exception was never retrieved
future: <Task finished name='Task-115' coro=<DBLClient._webhook() done, defined at /opt/virtualenvs/python3/lib/python3.8/site-packages/dbl/client.py:436> exception=ValueError('path should be started with / or be empty')>
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/dbl/client.py", line 453, in _webhook
app.router.add_post(self.webhook_path, vote_handler)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/aiohttp/web_urldispatcher.py", line 1094, in add_post
return self.add_route(hdrs.METH_POST, path, handler, **kwargs)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/aiohttp/web_urldispatcher.py", line 1034, in add_route
resource = self.add_resource(path, name=name)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/aiohttp/web_urldispatcher.py", line 1014, in add_resource
raise ValueError("path should be started with / or be empty")
ValueError: path should be started with / or be empty```
You can't use on_dbl_vote
okay i dont want on_dbl_vote but i want to query the votes list
Then DBLClient.get_bot_upvotes and remove the webhook
π
just curious how recent votes the function will return and is there a ratelimit on the function?
Well, the returned list consists of last 1000 votes regardless of whether they are valid now or not
As for the ratelimit, dblpy limits you to 59 requests per 60 seconds
oh okay then i need not to worry ty.
hello i look docs but i cant found anything. whats mean of Authorization at Webhook?
https://i.imgur.com/rMwSzmC.png

again, you need to make your own webhook using express for example, no current top.gg library (for js at least) supports server webhooks
If we do not fill out the webhook url field will it be not possible to use on_dbl_vote() event reference?
no
how are you going to receive vote events if you have no way of knowing if you received one or not
Ah ok.
can i get the userID of a user that voted?
yeah, the webhook has that
will the vote.user return a user object, name, or id?
id
Okay, thanks
Hello I have a problem with the java library for the api, can someone help ? java.lang.NoClassDefFoundError: org/discordbots/api/client/DiscordBotListAPI$Builder The error only occurs with JARs
@river kestrel you need to add the api to your maven/gradle dependencies
Re-check the docs
How to create a webhook?
I did
do you use maven or gradle for your libraries?
<dependency>
<groupId>org.discordbots</groupId>
<artifactId>DBL-Java-Library</artifactId>
<version>2.0.1</version>
</dependency>
yes
maven
and it works when I launch it
from intelij
but not when I build the artifact
and launch the jar
you need to build your project with the library too, you need to implement it inside of your application
implement ?
I have this in my project structure
as i'm not using maven, i can't really tell you how, but you need to compile the library aswell
it just adds the jar inside your application, not the actual source
idk it says extracted so my guess is that it would extract it
Open the built artifact with winrar and check if you see the source from the top.gg library
the source or the .class files ?
Just check the folder tree if it contains org.discordbots.api.client.DiscordBotListAPI
I have this
