#topgg-api
1 messages ยท Page 145 of 1
and dblapi.js is depcreated anyways and if any breaking api changes happen dblapi.js wont work even in the slightest
lol
Yep that's why I switched
read the error โข๏ธ
ok
see last pin
that ^
so
What happend to dblapi.js?
deprecated
Soo, how can i check if a user has voted by now?
someone who speaks turkish and approved for the bot top gg dm
you can use #general-int
can i use a free website/code hosting site and make it so every time you'r API send request it sends it in a private discord channel (using a webhook) and then i make my bot to read whatever is in the channel and reward people according to that?
OR
is it a waste of time?
(please ping me then responding)
sa
url is the ip/domain of your webhook
and the password is the password you choosed for the webhook
Any tutorials with dblpy?
Anyone knows how to make vote rewards?
you can use webhooks to see who voted, and do something from there e.g. change some value in a database to show if they've claimed their vote reward yet in the past 12 hours
So basically your saying how to make my bot online forever?
my bot is online but i want to use the webhook with my bot
What do you mean?
lol
Banned sadness?#1210 (@static harness)
-servercount @kind obsidian
@kind obsidian
To have your bot's server count displayed on Top.gg, please read the documentation on server/shard posting.
ty
hey, so I sorta have a question
would something like ${api.getVotes[1].name} return the username of the most recent voter?
getVotes[0], no?
or that, yeah
getVotes()?
I really just have no clue how top.gg's api works
same lol
I'm tryna make some sort of vote command that tells them the last 5 voters, the total vote count, and if they have voted in the past 12 hours
where's the link for python?
in the docs: https://docs.top.gg
thanks
I desperately need help
with using the .getVotes() thing
also how does the authorization work?
What I want to do is make a command that:
gives the total number of votes
says if the guy has voted in the past 12 hours
and gives the names & tags of the past 5 voters
so I'm wondering if like
api.getVotes().name[0] would work in getting the name of the most recent voter
or api.getVotes()[0].name or something
why can i not get any vote info?
api.getVotes()[0].username
how do i get the voting info on the website?
get_bot_upvotes
How to make a webhook :< Cus i wanted voting rewards :<
shivaco, do you know where to get the voting info from the website?
A webhook is just an HTTP listener running on a machine
JS and Python SDKs support those by default
You can get your bot's votes via DBLClient.get_bot_upvotes, but you'll have to own an API key, which means an approved bot
no, where do i find the token and stuff on the website
See pins
how to get logs who voted my bot ?!
It's not your computer
See the last pinned message
Codejs const DBL = require("@top-gg/sdk"); const dbl = new DBL(process.env.TOPAPIKEY);ErrorDBL is not a constructorIs this going to work?
no
yes, i saw, my bot doesn't have those
Well then you can't use those until your bot's approved
๐ก
Are you looking at the Edit page currently
yep
You don't have a Webhooks section?
tried that and it didn't work, maybe its because I didn't do the authorization (which I can't figure out)?
It's in the request headers
Authorization: "YOUR_TOP.GG_TOKEN"
Then yeah
this
do they not realize that people want to test?!?!?!
๐ก๐ก๐ก๐ก๐ก๐ก๐ก๐ก๐ก๐ก๐ก๐ก๐ก๐ก
wdym?
What is there to test even
You wouldn't have any data to work with in the first place
to test if my code receives votes correctly
I have no fucking clue how the authorization works; where am I meant to put it
you can send test requests just fine yourself
You can do that with Some dummy data you can make yourself with the schema on the docs
In request headers
what?
topggjs?
topggjs, so the node SDK
Yes, if you're referring to using the topgg api
const express = require("express")
const app = express()
const port = 3000;
const DBL = require("@top-gg/sdk");
const webhook = new DBL.Webhook('topggauth123')
app.post('/dblwebhook', webhook.middleware(), (req, res) => {
// req.vote is your vote object e.g
console.log(req.vote.user) // 121919449996460033
}) // attach the middleware
app.get('/', (req, res) => res.send("The bot is Jisoo and it's ok!"))
app.listen(port, () =>
console.log(`Jisoo is listening at http://localhost:${port}`)
);```Will this work? Because there isn't any errors
and the webhook is like topggauth123
yeah, I have all of that and it throws an error
"TypeError: Cannot read property 'username' of undefined"
console.log getVotes()
That's somewhere in your code
Are you hosting on a VPS?
no repl :/
Use port 8080
hmm
its from this api.getVotes()[0].username
Just output api.getVotes()
Your URL will be your repl's repl.co URL
with /dblwebhook appended to it
This is code```js
const express = require("express")
const app = express()
const port = 8080;
const DBL = require("@top-gg/sdk");
const webhook = new DBL.Webhook('topggauth123')
app.post('/dblwebhook', webhook.middleware(), (req, res) => {
// req.vote is your vote object e.g
console.log(req.vote.user) // 121919449996460033
}) // attach the middleware
app.get('/', (req, res) => res.send("The bot is Jisoo and it's ok!"))
app.listen(port, () =>
console.log(Jisoo is listening at http://localhost:${port})
);
```But it says Cannot GET /dblwebhook
then it gave [object Promise]
but it didnt throw an error
I'm not sure if it will output 405 Method not allowed or that
but
If / route works, so should /dblwebhook with POST requests
the post request didn't work
but get worked
How did you send it
const express = require("express")
const app = express()
const port = 8080;
const DBL = require("@top-gg/sdk");
const webhook = new DBL.Webhook('topggauth123')
app.get('/dblwebhook', webhook.middleware(), (req, res) => {
// req.vote is your vote object e.g
console.log(req.vote.user) // 121919449996460033
}) // attach the middleware
app.get('/', (req, res) => res.send("The bot is Jisoo and it's ok!"))
app.listen(port, () =>
console.log(`Jisoo is listening at http://localhost:${port}`)
);```
here the code
:/
send not create
where?
How did you send the POST request
Wdym :/
Okay

Correct
Yeah...
Make sure the auth matches too and press Test on the bot's Edit page in Webhooks section
Did you save?

app.post('/dblwebhook', webhook.middleware(), (req, res) => {
let voteperson = bot.users.get(req.vote.user)
console.log(req.vote.user)
voteperson.send("Thank you for voting!")
})
```@sullen nymph
will this work
sry for ping
could someone show me an example code for top.gg votes with python?
it just needs to do print() when there's a vote in the example
the docs really aren't that good
https://github.com/top-gg/python-sdk#examples does the example for webhook not help either?
A simple API wrapper for top.gg written in Python. Contribute to top-gg/python-sdk development by creating an account on GitHub.
God damn it, need to rework that README
i did not know that existed
actually, that's not the full code needed
Yeah, those examples only provide what's needed to just get it working
To adapt it to your use case is up to you
no, it doesn't work
it runs, but i need to get it to wait for a vote then call the function
not just define the function
Assign a function as an event to your bot object, make sure your port is open (and forwarded to your device if hosted locally). The function will be called when vote requests are received
You can only send mock votes manually currently since your bot hasn't been approved yet
P.S. you can send HTTP requests manually
i do not understand this library well, so what would this be?
with services like https://reqbin.com/
@bot.event
async def on_dbl_vote(data):
"""An event that is called whenever someone votes for the bot on top.gg."""
print(f"Received an upvote:\n{data}")
@bot.event
async def on_dbl_test(data):
"""An event that is called whenever someone tests the webhook system for your bot on top.gg."""
print(f"Received a test upvote:\n{data}")
https://dblpy.readthedocs.io/en/latest/api.html#event-reference
P.S. refer to docs.top.gg instead of top.gg/docs in the links
no, that's what i have
Yeah, you assigned those functions as events. dblpy will use the bot's event system to call them when votes are received
it ends the program
what do i do to make it continue to run?
or just discord bot run?
Are you familiar with discord.py?
Do you have bot.run in your code?
no
Well..?
i thought something would be in this
You assign events, etc etc, then use .run method on your client/bot object
okay
That's discord.py thing and goes off this channel topic

do i need a URL?
Yes
do i can not do this without a website to create a URL for?
so
this doesn't work
dbl_token = 'token'
bot.dblpy = dbl.DBLClient(bot, dbl_token, webhook_path='/dblwebhook', webhook_auth='password', webhook_port=5000)
@bot.event
async def on_dbl_vote(data):
"""An event that is called whenever someone votes for the bot on top.gg."""
print(f"Received an upvote:\n{data}")
@bot.event
async def on_dbl_test(data):
"""An event that is called whenever someone tests the webhook system for your bot on top.gg."""
print(f"Received a test upvote:\n{data}")
How does it not work?
my TOP.GG-WEBHOOK is not working!
the first code I did worked but it keeps repeating the user ID that voted for my bot
the second one worked only once and does not answer but
nothing happens
@top-gg/sdk?
How are you using the webhook?
verification is "password"
@sullen nymph yes
update
what?
update the SDK
How are you testing it?
What version is your @top-gg/sdk package at?
the last version
which version exactly
3.0.7
Update
for which version?
ok
with the test webhook/vote button
this doesn't work (why?)
dbl_token = 'token'
bot.dblpy = dbl.DBLClient(bot, dbl_token, webhook_path='/dblwebhook', webhook_auth='password', webhook_port=5000)
@bot.event
async def on_dbl_vote(data):
"""An event that is called whenever someone votes for the bot on top.gg."""
print(f"Received an upvote:\n{data}")
@bot.event
async def on_dbl_test(data):
"""An event that is called whenever someone tests the webhook system for your bot on top.gg."""
print(f"Received a test upvote:\n{data}")
for voting, the docs said to do this
{ webhookPort: 5000, webhookAuth: 'password' });
what do i put for thsoe
im new to webhooks
/dblwebhook
http://ip:port/dblwebhook
use @top-gg/sdk
you can look at pins how to use them
ok
"ip" or a value?
a value
Hi
ip being the IP address of the machine where the webhook is hosted
port is 5000 because webhook_port
i'm trying that now
it did not work
Better not leak the IP here
dont mind if i do
Make sure no firewall is blocking that port
it is considered public
One message removed from a suspended account.
One message removed from a suspended account.
i have absolutely no idea how to do that
One message removed from a suspended account.
One message removed from a suspended account.
One message removed from a suspended account.
One message removed from a suspended account.
A free open port check tool used to detect open ports on your connection. Test if port forwarding is correctly setup or if your port is being blocked by your firewall or ISP.
One message removed from a suspended account.
yes
okay
good girl Faith
One message removed from a suspended account.
Then that port isn't open on the network
tried multiple different numbers
how do i fix this?
One message removed from a suspended account.
One message removed from a suspended account.
One message removed from a suspended account.
Not necessarily
ISP?
oh
You will need to forward port 5000 to your device in router settings and open it in firewall settings on your PC
i'm not really good at this, how?
One message removed from a suspended account.
Google time!
maybe?
One message removed from a suspended account.
i don't know
Do you not have physical access to the router?
One message removed from a suspended account.
Are you familiar with how an internet connection is performed?
One message removed from a suspended account.
nope
One message removed from a suspended account.
One message removed from a suspended account.
One message removed from a suspended account.
about ||13|| (over minimum discord age)
One message removed from a suspended account.
One message removed from a suspended account.

i will try my other computer, which is set up for this stuff first, then try to get other stuff to work if not
One message removed from a suspended account.
One message removed from a suspended account.
ok so i have this
if(message.content.startsWith('$claim')) {
let voted = await topgg.hasVoted(message.author.id)
if(!voted) {
message.reply("You havent voted yet. Use $vote to vote on top.gg")
} else {
message.reply('Thanks for voting and supporting us as we grow! You have been awarded 25k bobux')
this.economy.addBal(message.author.id, 25000)
}
but people can keep spamming it after they vote
how would i make it work only once
is it possible to use none of this?
and have the library just call a function
why not?
what? discord.py works that way
?
One message removed from a suspended account.
One message removed from a suspended account.
One message removed from a suspended account.
One message removed from a suspended account.
One message removed from a suspended account.
One message removed from a suspended account.
One message removed from a suspended account.
One message removed from a suspended account.
i meant, connect through the library, not sort of set up an API
I tried going to https://top.gg/bot/:yourbotid/webhooks to get my top.gg token but it gave a 404 (Yes I replaced :yourbotid with my bots ID)
paste in here what you have entered
this one works tho
wdym
no 404
My bad I actually get a 403
Are you logged in on the right account?
I wasn't logged in LOL, thanks for the help haha
๐
is mine just cursed 
@warm linden that's a server isn't it?
or what is that
that's not even a bot on our site or a server
Oh it has to be up set up through the website, welp I'm dumb, I was trying to get the automated messages when somone votes for a server
That was a new discord application I made
Is it still possible to make that happen?
You have to submit your bot to begin with
and get it approved
you can't just get started without having submitted it yet
Oki dokes, I'll get on that, thank you for the help 
@sullen nymph can you please help
Which webhook
your webhook you're hosting yourself
If you want live-notifications of votes, you do
you need to actually host the webhook, simply entering the ip and post does not work
read the docs: https://docs.top.gg
i managed to get some help with opening the ports
yep
maybe the autorization "password"
i spelled it wrong
it has a h
you need to use a "password"
bot.dblpy = dbl.DBLClient(bot, dbl_token, webhook_path='/dblwebhook', webhook_auth='password', webhook_port=5000)
the password
you can make it what ever you want
are there any current issues with the voting being posted multiple times?
bc ive had that happen a ton lately out of no where
It will re-send the webhook if you don't respond with a 2xx response due to some fairly recent changes.
so if the developer hasn't implemented a response, it'll happen multiple times
that's exactly what i needed to hear, thanks so much!
@severe blade no ads
no one cares bout ur twitch
Is there a webhook to trigger when the bot is invited for a guild ?
How can I say in disocrd.js when a user voted, do somehting. I don't want to use a webhook.
if you want live updates, you can't without webhooks
What package do I need for JavaScript to access the api
read pins
Ok. So if I have a webhook hosted on repl, how can I go to that webhook if I have my webhook hosted on repl, and my bot self hosted
I want to make a lb soon. where every time a user votes, it adds them a point
can't really help with that
I can do the db stuff its just that part
to connect to the webhook
ok np
if anyone knows just ping me
you need to authorize your webhook
are you sending the authorization along with the request?
apparently not or the authorization is wrong
Yes, and what you have defined in your code
it is not your bot or top.gg token
yes
how are you testing it then? DM me the url
and the authorization

how is top.gg supposed to make requests to it when it is on localhost
import dbl
import discord
from discord.ext import commands
class TopGG(commands.Cog):
def __init__(self, client):
self.client = client
self.token = 'token'
self.dblpy = dbl.DBLClient(self.client, self.token)
@commands.Cog.listener()
async def on_ready(self):
print(f"LOGGED IN AS: {self.client.user}")
@commands.Cog.listener()
async def on_dbl_vote(self, data):
print(data)
def setup(client):
client.add_cog(TopGG(client))
Can anyone help, why doesn't it print any data on vote?
self.dblpy = dbl.DBLClient(self.bot, self.token, webhook_path='/dblwebhook', webhook_auth='password', webhook_port=5000)
What does webhook_path mean here?
vote or test vote?
Vote
Any clues what have I done wrong?
nope
I've been trying to get this right from a month
or define client/bot object
But no data is being printed
Is webhook a requirement?
not how webhook works
you need to use http://ip:port/dblwebhook
http://ip:port/dblwebhook
second one
ip will be my host ip, right?
yes
with an open port
The port forwarding tester is a utility used to identify your external IP address and detect open ports on your connection. This tool is useful for finding out if your port forwarding is setup correctly or if your server applications are being blocked by a firewall.
I'll give it a try
@pastel drift did it work?
How do I find open port?
you need to open it
I feel so dumb rn
Yeah but this api and webhooks are so confusing
yep
I'll check if it works
did it?
you must have the program running
yes, SS it
One sec
Actually can you join a vc?
Yes from the control panel I did
I have the program running as well
import dbl
import discord
from discord.ext import commands
class TopGG(commands.Cog):
def __init__(self, client):
self.client = client
self.token = 'token'
self.dblpy = dbl.DBLClient(self.client, self.token, webhook_path='/dblwebhook', webhook_auth='top.gg', webhook_port=5000)
@commands.Cog.listener()
async def on_ready(self):
print(f"LOGGED IN AS: {self.client.user}")
@commands.Cog.listener()
async def on_dbl_vote(self, data):
print(data)
def setup(client):
client.add_cog(TopGG(client))
This is the right way to define path, auth and port?
webhook auth should be a password
other than that, yep
http://ip:port/dblwebhook is your link for webhook
Yes the same
Nope
Sometimes
is it connected to the router thing? (for internet, not a mill)
Connected via wifi
is it public?
Is it anything related to my antivirus?
maybe
Oh it wasn't
i don't know how to open port, someone did it for me
I just changed it
is it now open?
I have the program running again
after it's "open" i can help more
Still not open
it takes a minute
This is gonna be painful for me
Now I am testing this on windows and later I have to upload it to AWS ubuntu
i use linux+ubuntu, and know how that works (terminal)
does the computer say it's locally open?
you clearly know more about how internet works than me
i now know how to set up an API, but that's about it
I'll see how can I get it done and I'll contact you back if it's okay?
Thanks for helping me
import requests
x = requests.get("https://top.gg/api//bots/:807170972801040394/check?userID=528898630074236928")
print(x)
But I am getting response 401 Unauthorized
what do to?
Thanks finally works now
Okay I have that token, where should that be added in the request?
/* THIS POSTS STATS TO DISCORDBOTS.ORG */
const DBL = require('@top-gg/sdk');
const express = require('express')
module.exports = {
/**
* Starts to post stats to DBL
* @param {object} client The Discord Client instance
*/
init(client){
const stats = new DBL.Api("token");
setInterval(async function (){
await stats.postStats({
serverCount: client.guilds.cache.size
})
}, 60000*10); // every 10 minutes
const webhookClient = new Discord.WebhookClient('id', 'token')
const app = express()
const webhook = new DBL.Webhook('topggauth123')
app.post('/dblwebhook', webhook.middleware(), (req, res) => {
console.log(req.vote.user) // 221221226561929217
webhookClient.send(`${req.vote.user} Voted me`)
})
app.listen(3000)
}
};```not receiving messages
what do you mean not receiving messages?
vote logs
where do you host your bot
dan
which are u using and how do you pass Auth in that?
so it's not possible to receive vote logs with dan?
yeah
Hey Reis which programming languages you know?
js
๐ข
Okay
You know to send request? @restive otter
import requests
x = requests.get("https://top.gg/api//bots/:807170972801040394/check?userID=528898630074236928")
print(x)
But I am getting response 401 Unauthorized
How do you do this in js
there are many tutorials how to make requests online lol
I got the response {"voted":0}
I was checking if the user has voted
Is that indicating Boolean value 0 , 1 ?
or how many votes the user has
@restive otter you know ?
What do you mean hidden
That on the web I have not found anywhere to access those endpoints, I found them browsing outside top.gg
In which section of there does it show top.gg/bot/:botid/votes or top.gg/bot/:botid/widgets?
Widgets aren't described yet
What else is not yet described?
Because "votes" neither is it
Sorry if I ask a lot, I'm curious
Even though I am voted it is still showing 0
I asked my friend to check
He also voted
But 0
False
API v1
/votes should be documented
Mhm.
Remove the colon
oh end point
api/ not api//
Is there a date for v1?
None
why still I am getting {"voted":0} this json
F, okay thanks @sullen nymph ๐
It is wrong that request
That endpoint can take up to an hour to update
Where are you sending the Authorization header btw
this is more effecient?
huh
oof
P.S. use aiohttp with your discord.py bot
yeah
P.S?
A postscript (P.S.) is an afterthought, thought that's occurring after the letter has been written and signed. The term comes from the Latin post scriptum, an expression meaning "written after" (which may be interpreted in the sense of "that which comes after the writing").
just a hint that you should use async stuff with async stuff
and requests isn't async
okay are they the same way like requests?
No, refer to aiohttp docs on how to send HTTP requests
This isnt working```py
@client.event
async def on_dbl_vote(data):
"""An event that is called whenever someone votes for the bot on top.gg."""
print(f"Received an upvote:\n{data}")
channel = client.get_channel(828203330752610335)
embed = discord.Embed(title="Vote log", description=data)
await channel.send(embed=embed)
@client.event
async def on_dbl_test(data):
"""An event that is called whenever someone tests the webhook system for your bot on top.gg."""
print(f"Received a test upvote:\n{data}")
channel = client.get_channel(828203330752610335)
embed = discord.Embed(title="Vote log", description=data)
await channel.send(embed=embed)```
idk doesnt print
anything
when I test it , it shows webhook tested but doesnt print in my console
on_dbl_test doesn't get called?
No no, api not, without /api/
website shows it has been tested but doesnt print the output
no errors
token needs to be a string ?
I set port to 80 now
no idea what is port
alright
How can i get all the server my bot is in displayed on the website?
Check the pins
I cant see what it says about number of guilds?
Use this package https://npmjs.com/package/topgg-autoposter
python?
ok nw :)
No problem! ๐
Have a good day!
Thanks. You too
Thanks :)
sorry to bother you again, what does the logger.info do? where does it send the message?
In terminal? I don't know I'm not familiar with py
ok nw thank you though!
How can I make a notice when voting
Is there a video?
It will be easier
Well, thank you 
Javascript
Thank you
In the console when you have logging set to include DEBUG messages
by default*
Itโs not showing up on the website though?
why wont dblpy work i read the docs and everything i even looked at examples but my bot doesnt pick up when someone votes or gets a test
Show your code
ok one sec
import dbl
import discord
from discord.ext import commands
import asyncio
class TopGG(commands.Cog):
"""Handles interactions with the top.gg API"""
def __init__(self, bc):
self.bc = bc
self.token = self.bc.dbltoken # set this to your DBL token
self.dblpy = dbl.DBLClient(bot=self.bc, token=self.token)
@commands.command()
async def botvotes(self,ctx):
votes = await self.dblpy.get_bot_upvotes()
await ctx.send("BreadBot has {} votes on top.gg!".format(len(votes)))
@commands.Cog.listener()
async def on_dbl_upvote(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(bc):
bc.add_cog(TopGG(bc))
on_dbl_vote not upvote
i looked at the docs
You didn't specify webhook parameters in DBLClient
it should automatically put the parameters into place though
Which parameters kekw
the bot and the dbl token
can be found on this page
why do i need a webhook
Because webhook means receive votes in real time
and how the heck do i get a webhook port
and for the on_dbl_x events to work you need the webhook
You simply specify any port you have accessible
where do i find webhook auth
It's just a password you create and enter both in your code and your bot's top.gg page
:p sorry for asking so many questions
Nah it's fine
where is the path for the webhook
Seeking knowledge is admirable
It's a route that comes after either the domain or ip:port in your URL
then after the repl.co URL
For example,
https://yada.yeehee.repl.co/dblwebhook
path here would be /dblwebhook
Though keep in mind that you will need to set webhook_port to 8080
ok
How to create api?
do i need to put anything into my keep_alive file tho
Nvm
Eugh... you can redirect the requests from your keep_alive to a locally hosted webhook
on some other port
Say, keep_alive on port 8080, while your dblpy webhook runs on port 5000
mk
And since you can't run two webservers on the same port
yeah, that's why I mentioned redirecting the requests
ahh
Essentially from internal repl proxy to your proxy to your webhook ๐
so would the api put the data into the link
https://github.com/shivaco/DBL-python-webhook/blob/master/listener.py#L27 oh yeah even better
Flask script mainly to handle POST requests from top.gg - shivaco/DBL-python-webhook
I think you'll get the gist easier with that
@sullen nymph i have used the code from the docs but the bots servers isnt updating?
Yeah well that doesn't tell me shit, let's be honest
Could you actually provide your code and show what you use?
Sure! sorry
no problem
import dbl
import discord
from discord.ext import commands, tasks
from discord.ext.commands import Cog
import asyncio
import logging
class TopGG(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=30.0)
async def update_stats(self):
"""This function runs every 30 minutes to automatically update your server count"""
channel = self.bot.get_channel(828240894800560128)
await channel.send('Attempting to post server count')
try:
await self.dblpy.post_guild_count()
await channel.send('Posted server count ({})'.format(self.dblpy.guild_count()))
except Exception as e:
await channel.send('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)
def setup(bot):
global logger
logger = logging.getLogger('bot')
bot.add_cog(TopGG(bot))```
ah yes
the good ol' forgotten task start
Though can't blame you, dumb me forgot to put that initially there
In the cog's init add self.update_stats.start()
ok thanks!

will it update instantly on restart or do i have to wait 30mins
Oh fuck right
Remove the await asyncio.sleep(1800)
ok thanks!
yup
k thx
So with the unnecessary .sleep removed, it will... run on start, iirc
in case that doesn't happen, you can wait 30 minutes
It worked tysm!

@sullen nymph tysm the flask thing worked
hell yeah
Hey where are api key the page to generate does not exist anymore
How do we get the AUTH_PASS for our bot?
yeah
What do you mean by AUTH_PASS?
see last pinned message
hey! i need help with logging votes when they happen. I have this code which runs while my bot runs.
// top.gg
const top = require('top.gg-core');
const topgg = new top.Client(dbltoken);
const webhook = new top.Webhook(webhookPW);
client.on("ready", () =>
{
if (token == devtoken) console.log("MIZU (DEVELOPMENT) IS READY");
else console.log("MIZU (PUBLIC) IS READY");
topgg.post({
servers: client.guilds.cache.size
});
setInterval(() => {
topgg.post({
servers: client.guilds.cache.size
});
}, 3600000); // posts stats every 1h
});
topgg.on('posted', data => {
console.log(data);
});
webhook.login(`${webhookIP}/mizutopggVote`, '3000');
webhook.on('vote', vote => {
console.log(`Voter id: ${vote.user}\nAll data: ${vote}`);
});
It console.logs the server info every hour:
{
servers: 9,
shard: { id: null, count: null },
timestamp: 1617544395488
}
But when I vote, it does not detect it. Here is the webhooks page.
In the docs, there is a value called webhookAuth, where do we get it?
What the fuck is top.gg-core
Why not use the official @top-gg/sdk package
@sullen nymph Can you help please?
You create it yourself
It's a password that's simply used to confirm that requests are coming from top.gg
Make sure it matches the value in the Authorization field on top.gg
This?
Yeah
Ok tysm
thanks! will this code do the job of logging when someone votes? (on the npm site of the sdk) :
app.post('/dblwebhook', webhook.middleware(), (req, res) => {
// req.vote is your vote object e.g
console.log(req.vote.user) // 221221226561929217
}) // attach the middleware
``` sorry im quite new to webhooks
That's just the handler, which looks good to me. Make sure you run the webhook on an accessible port
okay! so if the webhook url is all good, that, along with the rest of the code using express in the example, should log the user's id when they vote?
Keyword: should
I'm only relying on common sense and intuition since I'm not exactly proficient in JS
It's better if you test it for yourself
okay! thank you so much for the quick help ๐

sorry, for the repeat neediness.
it doesn't seem like i need to use my api token in this process. is this correct?
Well, do you want to use the API for stuff like posting your bot's server count?
nope
Ehhh then you can scrap that and just use the webhook
oh nice! this is so convenient. thank you very much again!

-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.
Guys i wanted to know how can i get when a user vote for my bot then example give him some coins. i use discord.js
How fo I setup upvote webhook?
var path = require('path');
const { webhookPW } = require(path.resolve(path.normalize("./config.json")));
const init = async() =>
{
console.log('[EXPRESS] STARTING SERVER')
const express = require('express')
const app = express()
const Topgg = require('@top-gg/sdk')
const webhook = new Topgg.Webhook(webhookPW) // add your top.gg webhook authorization (not bot token)
app.post('/dblwebhook', webhook.middleware(), (req, res) => {
// req.vote is your vote object e.g
console.log(req.vote)
}) // attach the middleware
app.listen(25569, () => console.log('SERVER READY'))
}
module.exports.init = init
Hey! this is my webhook code, but my vps is not receiving the requests sent by topgg tests. I have used sudo ufw allow 25569 and sudo ufw allow http Any idea how to fix this?
ya same except in py
the command for ufw would be sudo ufw allow 25569
oh i meant that sorry
whats webhook password
bot.on('ready', async () => {
api.postStats({
serverCount: bot.guilds.cache.size
})
})
Anyone know why this is only coming up as 2 when the bot is in like 100 guilds?
-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.
ask in #development
that is topgg api?
oh my bad

Can someone help me make a webhook to travk upvotes? Im python
should i be asking this question in #development ?
gcount = len(bot.guilds)
url = "https://top.gg/api/bots/825063508806467664/stats"
data = {'server_count': int(gcount)}
headers = {'authorization':'top.gg auth token'}
requests.post(url, headers=headers, data=json.dumps(data))
what am I doing wrong here?
I get a response 400 when I send the request
use json= not data=
What you are doing is simply sending a string without a Content-Type header
ah ok
ill try that again
thanks, I got a response 200
not sure if it actually posted the guild count tho
nvm it did
thanks

dbl_token = os.environ.get("DBL_TOKEN")
webhook_password = os.environ.get("WEBHOOK_PASSWORD")
discord_webhook = os.environ.get("WEBHOOK_URL")
bot.dblpy = dbl.DBLClient(bot, dbl_token, webhook_path=discord_webhook, webhook_auth=webhook_password, webhook_port=5000)
@bot.event
async def on_dbl_vote(data):
"""An event that is called whenever someone votes for the bot on top.gg."""
print(f"Received an upvote:\n{data}")
@bot.event
async def on_dbl_test(data):
"""An event that is called whenever someone tests the webhook system for your bot on top.gg."""
print(f"Received a test upvote:\n{data}")
dont work?
webhook_path must be a route not a Discord webhook URL
im confused
Do you know how webservers operate
Route and URL are different
route comes after domain
For replit you use port 8080 and use repl.co as the URL
webhook_path must be anything like /dblwebhook
so that your URL becomes https://xxx.yyy.repl.co/dblwebhook
alr
dbl_token = os.environ.get("DBL_TOKEN")
webhook_password = os.environ.get("WEBHOOK_PASSWORD")
discord_webhook = os.environ.get("WEBHOOK_URL")
bot.dblpy = dbl.DBLClient(bot, dbl_token, webhook_path='/dblwebhook', webhook_auth=webhook_password, webhook_port=8080)
Looks good
so should i tes
as well as Authorization
oh ok
Discord webhooks aren't related to this at all
Yes
hm
doesnt work still
on test
nothing hapepnes
this is whole code for top.gg/py
import dbl
dbl_token = os.environ.get("DBL_TOKEN")
webhook_password = os.environ.get("WEBHOOK_PASSWORD")
discord_webhook = os.environ.get("WEBHOOK_URL")
bot.dblpy = dbl.DBLClient(bot, dbl_token, webhook_path='/dblwebhook', webhook_auth=webhook_password, webhook_port=8080)
@bot.event
async def on_dbl_vote(data):
"""An event that is called whenever someone votes for the bot on top.gg."""
print(f"Received an upvote:\n{data}")
@bot.event
async def on_dbl_test(data):
"""An event that is called whenever someone tests the webhook system for your bot on top.gg."""
print(f"Received a test upvote:\n{data}")
Do you run that file anywhere
for this
wait lemme try making it one file
One small question:
by running get_user_vote(user_id), does it return if the user has vote at least once in their life, or in the past 12 hours?
how do you make it send webhook to my channel when someone upvotes i cand understand documentation bc im not good at reading
what do i put in authorization
How do I make a webhook send a message whenever someone uovote in python?
exactly what ive been trying to do
same
How can i check if a user has voted for my bot in code
https://top.gg/api//bots/<your_bot_id>/votes
Gives you data on who has voted.
Thanks
// Make sure to install this with 'npm install dblapi.js`
const DBL = require('dblapi.js');
// The webhookPort can be whatever you want but make sure you open that port in the firewall settings (for linux for example you can use `sudo ufw allow 8000`)
// The webhookAuth is set by you, make sure you keep it secure and don\'t leak it
const dbl = new DBL(config.API_TOKEN, { webhookPort: 8000, webhookAuth: 'password' });
// When the webhook is ready log it to the console, this will log `Webhook up and running at http://0.0.0.0:8000/dblwebhook`
dbl.webhook.on('ready', hook => {
console.log(`Webhook up and running at http://${hook.hostname}:${hook.port}${hook.path}`);
});
// This will just log errors if there are any
dbl.on('error', e => {
console.log(`Oops! ${e}`);
})
// When the webhook receives a vote
dbl.webhook.on('vote', async vote => {
// This will log the whole vote object to the console
console.log("debugging: someone voted lol")
console.log(vote)
// Get the Discord ID of the user who voted
const userID = vote.user;
// If the channel to send messages in exists, we send a message in it with the ID of the user who votes
vote.user.send("Thanks for voting! $20 has been added to your balance.")
//i give the money here
})
does anyone have any idea why this this isnt working
Does it log any errors?
@sullen nymph Sorry to bother you again but the bot doesn't seem to be refreshing every 30mins?
It is 6 am
oh shit, sorry
CRAP
forgot to remove my token
ok regened it so we all good
import dbl
import discord
from discord.ext import commands, tasks
from discord.ext.commands import Cog
import asyncio
import logging
class TopGG(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)
self.update_stats.start()
# 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"""
channel = self.bot.get_channel(828240894800560128)
await channel.send('Attempting to post server count')
try:
await self.dblpy.post_guild_count()
await channel.send('Posted server count ({})'.format(self.dblpy.guild_count()))
except Exception as e:
await channel.send('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))```
Does it send the messages though?
channel would be None if the bot wasn't ready yet
And you're sure the port and password is correct?
yeah I'm sure
i copied that code into repl it with my token and tested it all it seems to do on run is nothing and stop
Yh i fixed it sorry for the inconvenience...
can i see
ive been having trouble
I just change the channel = to self.channel udner the innit
when i press run it just stops the code
yeah
yh then it wornt work sorry
thats what cogs is
runs several files at once
Im not the best at this stuff
try speaking to one of the staff sorry
im not either ;-;
xd
could i host a seperate code for it like on repl it or something
i use repl it for small codes
when
when what
dblapi.js is deprecated .-.
Trying to setup a vote webhook for my bot but for some reason it's not working. In console - upon startup - it shows Top.gg API running at http://0.0.0.0:521/dblwebhook which is concerning because 0.0.0.0 as you may have guessed, is not the IP.
const dblapi = require("top.gg");
const express = require("express");
const dash = express();
const verify = express();
const http = require("http");
const server = http.createServer(dash);
const get = require("superagent");
const colors = require("colors");
module.exports = (client) => {
// Discord Bot List (now top.gg) API, used for communicating server count and receiving vote hooks
if (!process.env.DBL_TOKEN) return;
const dbl = new dblapi(process.env.DBL_TOKEN, {
webhookPort: 521, // Replace this with whatever port you want to run the webhook on
webhookAuth: process.env.DBL_AUTH,
});
dbl.webhook.on("ready", hook => {
console.log(colors.magenta(`Top.gg API running at `) + colors.white(`http://${hook.hostname}:${hook.port}${hook.path}`));
});
dbl.webhook.on("vote", vote => {
const settings = client.getSettings(channel.guild.id);
const logs = client.channels.cache.get(settings.modLogChannel);
if (!logs) return;
logs.send(`User with ID ${vote.user} just voted!`);
});
};
I saw above that the dblapi.js package is deprecated, hence why I'm using top.gg now.
0.0.0.0 should be correct, it's just telling you that it's running on your local IP
Is the port correct, and open?
Yep, I chose 521 instead of the usual 80 or 443 as those are already in use.
is it open on https://canyouseeme.org/?
A free open port check tool used to detect open ports on your connection. Test if port forwarding is correctly setup or if your port is being blocked by your firewall or ISP.
Running on a VPS so can't use that website.
I did check to see if it was open though.
Ran sudo lsof -i -P -n | grep LISTEN in CLI.
This code isnt working for me, it has no errors though(I have defined the tokens and auths earlier in the code)
app.post("/dblwebhook", topwebhook.middleware(), (req, res) => {
console.log(req.vote.user);
});
@smoky breach could you try to send your own webhook to the server, just to make sure it's actually working?
dbl.webhook.on("vote", vote => {
const settings = client.getSettings(channel.guild.id);
const logs = client.channels.cache.get(settings.modLogChannel);
console.log("foo")
if (!logs) return;
console.log("bar?")
logs.send(`User with ID ${vote.user} just voted!`);
});
Did the ol' foobar trick and it seems neither foo, nor bar is logged.
Also, remember to hit "Save" after you change the webhook url on the page. It doesn't save automatically
So I assume it's an issue with the on vote event.
Regenerated credentials and saved, didn't seem to fix the issue though alas.
I'm not sure how the js lib works, but could you try dbl.webhook.on("test"... instead?
Just to double-check, syntax is https://discordapp.com/api/webhooks/:ID-OF-BOT/:DBL-TOKEN, right?
Or am I still outdated?
Had this all setup perfectly a while ago but then with the deprecation of dblapi.js, everything seems to have been changed.
What would this achieve?
dbl.webhook.on("ready", hook => { }) Already got this so I know that it's working.
actual votes and test votes are two different events afaik
Doesn't seem to have changed anything alas.
how do i thank a user who voted for my bot via her dm?
Not official btw
Can you still use the top.gg package or is it a must to switch to top.gg/sdk?
top.gg package is unofficial
hmm
soo you might switch to @top-gg/sdk
But the problem is, I face a lot of problems while using sdk, and the code isnt as easy as top.gg
ยฏ_(ใ)_/ยฏ
it is easy tho
The webhook part didnt work :/
I triple checked everything
it works for me tho
hmm
Did you run .listen
Are you sure the port is accessible
I think so, havent checked
where do you host your bot?
I host the Canary(Test) bot on Visual Studio Code, but I publish the changes to my main bot which is hosted on repl
so the webhook is on replit?
No
Its on Visual Studio Code
well then cant help ya
So locally
yes
cuz i am bad at local hosting things lol
but once its working, I insert the code in my main bot hosted on repl
Use port 8080, make sure port is forwarded to your device and your device's firewall isn't blocking requests to it
i mean it works for me on replit
Which port if im hosting on repl? 
any port
oh alright
So lemme try coding directly in the main bot which is hosted on repl
Thanks for the help
your url should be
https://replname.username.repl.co/dblwebhook
8080
No, every port is working on repl
hello
Hi
Oh, interesting
Yup, thanks
How to Direct Message the user when they vote :?
How?
right now it only logs in the console
the use id
user*
app.post('/dblwebhook', webhook.middleware(), (req, res) => {
console.log(req.vote.user)
})``` and this si the code
is*
like bot.user.get?
i did
TypeError: bot.users.get is not a function

?
So... What can i doo?
:<
Keep getting this Attempting to post server count Failed to post server count NameError: name 'channel' is not defined Attempting to post server count Attempting to post server count Posted server count (26) Posted server count (26)
import dbl
import discord
from discord.ext import commands, tasks
from discord.ext.commands import Cog
import asyncio
import logging
class TopGG(Cog):
"""Handles interactions with the top.gg API"""
def __init__(self, bot):
self.bot = bot
self.token = 'nono' # set this to your DBL token
self.dblpy = dbl.DBLClient(self.bot, self.token)
self.update_stats.start()
self.channel = self.bot.get_channel(828240894800560128)
# 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"""
await self.channel.send('Attempting to post server count')
try:
await self.dblpy.post_guild_count()
await self.channel.send('Posted server count ({})'.format(self.dblpy.guild_count()))
except Exception as e:
await self.channel.send('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))```
