#topgg-api
1 messages · Page 163 of 1

docs says to ask in this channel
https://top.gg/bot/834409783502438480/vote?bot=834409783502438480&user=562553902990491659&type=test&isWeekend=False
well i created this webhook
is the format correct?
which language ?
okay
use this to verify the request is from top.gg
the Auth Token is what you put when setting up
^°^
np
Just use aiohttp doe, no more dependencies.
Plus it's async
:<
does that value reset every month?
Alguien español para que me ayude ?
@restive otter thank you for the help
Can anyone help me me to do this??
About me is in the developer page (where you find your bot token) and status is a thing you code lolz
The topgg webhook isnt working, it might be because im using replit, but it doenst seem to work
@willow spindle ordan geliyom
-notr
İngilizceden başka dillerde sohbet etmek için #general-int kanalını, top.gg hakkında (Türkçe olarak da) destek almak için #support kanalını kullanın.
Bu kanalda Türkçe konuşmayın.
-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.
I do clustering. currently when I post my guild, I make call to each cluster and sum the guild count myself, then post it. I see 2 arguments in the payload shard_count and shard_no
for example if each cluster hosts 4 shards out of 40, and each of my clusters post guild count by filling out shard_count with 40 and shard_no with 4, will top.gg api handle summing that up for me, or should I continue what I'm currently doing?
do i need a webhook for a vote-only command (command that requires vote)
i have done it before so yes
but i used another repl so that it doesnt mess with anything else
const Topgg = require('@top-gg/sdk')
const app = express() // Your express app
app.get('/', (req, res) => res.send('Hello World!'));
const webhook = new Topgg.Webhook('(password)') // add your Top.gg webhook authorization (not bot token)
console.log(webhook)
app.post('/dblwebhook', webhook.listener(vote => {
// vote is your vote object
console.log(vote.user) // 221221226561929217
})) // attach the middleware
app.listen(3000, () =>
console.log(`Example app listening at http://localhost:3000`)
);```
just making sure, in the "Topgg.Webhook('(password)') your auth key is there (or hidden behind an env variable)
like you did put in the authkey
right
I jsur put that there so tou dont see passeord
ok good
so when you run your repl, do you have the webpage thing?
(it doesnt have to say Cannot get /)
@stark dove yes
okay
so that means it should be working
but on your topgg webhook page
did you put in the right url
like https://replname.replaccount.repl.co/dblwebhook
I hace that
nothing in the console?
No
that's weird
wait
do you get the "Example app listening at http://localhost:3000"in your console
or smtn like that
that is interesting
could you show me the topgg webhook page (cross out ur password n stuff)
are you sure that there is absolutely no difference between the password in top.gg and replit
also make sure that you saved the info
Still dont wok
And i copy and pasted the passeord and saved it still doesnt eork
that is really interesting
try removing these strings
and then try again
also if your repl is offline but someone votes for your bot the repl will wake up (it did that for me)
Must of been the app.get then
It works now
Alright
do i need a webhook for a vote-only command (command that requires vote)? i don't think i need a webhook to verify, but im just making sure. or do i need to make some kind of database, idk lol
ye?
On the webhook repl, store the ID in repldb, and access it from your main one
Like an array
Thing is I don't actually use repl for hosting my bot anymore ...
I use heroku now :P
But i was wondering if i could just grab if a user has voted (like a bool value) without needing a webhook
what is msin?
Main
you could but then you would probably need to buy more dyno hours or set up a web module (which means your bot will go offline every 30 minutes if it's idle)
thats why i use worker for my main bot and replit for my webhook
that way if my repl goes offline, my main bot would still be online
You can access repldbs outside of replit but i dunni how
Actually
You can use repl database outside of replit
Meh
?
nothing
hey guys, im trying to use the dblapi for dotnet and GetVotersAsync returns everything as null, and HasVoted returns "voted" not found
sends you a webhook when someone vote
oh so i can make like a votes channel and it will send a webhook message there?
No but you can make it do that
What?
hold up
how do u get this with discord.js
or get it to show ur bots online on top.gg
const { AutoPoster } = require('topgg-autoposter')
AutoPoster('topgg-token', client)
.on('posted', () => {
console.log('Posted stats to Top.gg!')
})```
@barren sundial what are you hosting it on?
Oh nvm
localhost xdd
Oh then it wont be able to see it?
Localhost is your network only devices connected to your wifi can view it
oohh
1 sec
app.get('/', (req, res) => res.send('Hello World!'));
app.listen(port, () => console.log(`Example app listening at http://localhost:${port}`));```
Add that to tour code
btw dblapi.js still works for verify if someone has vote?
Do this and comment out the webhook

To see if your ip is working as a website
Thats localhost
i added this and it doesnt show the online like this
ya
Im not sure what the autoposter actually soes but i assume it will do that
like the bot?
Yea
i think it auto posts the server count
The webhook doesnt have anything to send to the wbrsite
u cant access your own ip from a device on the network i think
So just fo to the ip
Should be able to
mmm i will see with replit
please 
But youll need 2 seperate replits if you want to keep the bot online snd have a webhook
const Topgg = require('@top-gg/sdk')
const DB = require('@replit/database');
const db = new DB(process.env['db'])
const app = express()
const webhook = new Topgg.Webhook(process.env['pass'])
app.post('/dblwebhook', webhook.listener(async vote => {
let votes = await db.get('vote')
if (votes == undefined) votes = []
votes.push(vote.user)
await db.set('vote', votes)
}))
app.listen(3000, () =>
console.log(`Example app listening at http://localhost:3000`)
);```
i guess you cant add the online status so i just added the html widget to the description
I think so
How to test if api is working?
I tried the on_dbl_test thing, but its not returning anything
ty
Does it work
How i can add my bot 24/7 it's music bot
#development, please keep this for top.gg api only
Ok
Show code
api.setStats(serverCount);
pls help where to put this so server count will show
on my bot page
put it into your index/main.
hi
Why my bot not showing servers on top.gg
it should tell how many servers my bot is in
is it down becuase it won't let post how many server the bot in
API is down
oh ok
nvm
const { AutoPoster } = require('topgg-autoposter')
const ap = AutoPoster('==)
poster.on('posted', (stats) => { // ran when succesfully posted
console.log('Posted stats to Top.gg!')
})````
this right
@modern crest
i have never used any webhook, so can someone tell me how to get a webhook url for top gg
sorry for ping

anyone?
const Topgg = require("@top-gg/sdk");
const api = new Topgg.Api(process.env.topapi)
setInterval(() => {
api.postStats({
serverCount: client.guilds.cache.size
})
}, 18000000)
also im using this. Put that inside of client.ready()
@final wren can you not just use rhis?
How are you hosting your bot?
heroku
Im not sure how heroku webservers work but try this
const Topgg = require('@top-gg/sdk')
const app = express()
const webhook = new Topgg.Webhook('YOUR_TOKEN')
app.post('/dblwebhook', webhook.listener(async vote => {
console.log(vote.user)
}))
app.listen(3000, () =>
console.log(`Example app listening at http://localhost:3000`)
);```
Why
oh thnx but im using python
Ah okay
any idea for it?
Take a look at this https://github.com/top-gg/python-sdk#using-webhook
For the port, you want to get it from the env variable PORT, i.e., os.getenv("PORT")
The URL would be https://<yourapp>.herokuapp.com/dblwebhook assuming you followed the example
oh thnx
Hey i don't get ping in voting that is like this
it's ```js
channel.send(<@${user.username}> has Voted for ${client.user.username}!)
js btw
HELP ME
no one ;-;
user.id
you missed the "!" so it should be like this
channel.send(`<@!${user.username}> has Voted for ${client.user.username}!`)
``` its after the "<@" btw
if you ask why then the reason is
roles use <@& Role Id >
but users use <@! User Id >
Don't think it's necessary
@last vault Did you use python for that?
Does anyone know how I setup a topgg client in python?
It's clear that it's not Python by seeing the syntax
I was hoping he'd say yes...
Take a look at topggpy, it got examples too
Totally Python
Totally
is there any timeline for v1?
Hey guys, not sure what to put in Password??
new DBL(yourDBLTokenHere, { webhookPort: 5000, webhookAuth: 'password' });
ok thanks 🙂
ok perfect thanks 🙂
Gou put your own password there and make sure their same both in the website and tour code
How do I make a webhook?
I'm trying to make my bot do something when someone votes for my bot
Go onto your bots website, scroll down to "edit" and select webhook
Are you using js or python
Python
I cant help you with that
Hey Evie
This will be the same to make the webhook
Ok, that's fine
to get the event of when someone votes, it's dbl.webhook.on('vote', vote => {
Yes?
It doesn't work for me, would you be willing to call? or to check my code? It's small
I cant call but i can dm
sweet
There's nothing in the webhook url
I know you have to provide it
@modern crest what did you use as your webhook? (Obviously don't tell me the actual URL)
Like did you go to a website or something to create one?
add '!' after '@'
Are you running it on your computer?
Their using js
My bot?
Yes
Oh then it should just be your website/dblwebhook
Alright, I'll try that
I have no idea hiw python works btw
Shouldn't it be similar in terms of adding a webhook to top.gg?
It doesn't require any coding
oh
Everytime someone votes it gets sent to your website webhook
Sorry im not sure how it works with python
Alright
Can someone confirm if this event is working for them Python v3.9.2
@bot.event
async def on_dbl_vote(data):
pass
What package? dblpy or topggpy?
topggpy
You have to do the webhook thing first btw

If you find out how, PLEASE tell me
topggpy should work on 3.9. dblpy got some issues which I can't recall if it affects the webhook
Well disregard that
How did you setup the WebhookManager?
i did not 
@restive otter Do u know how to?
Then that event is meaningless, won't fire at all
Have you seen the examples yet?
i was going through discords docs they let create custom webhooks , will it work with that?
I have but how do I actually get a webhook
?
Nope
Integrate your service with Discord — whether it's a bot or a game or whatever your wildest imagination can come up with.
I mean, what actually is the url part?
that idk myself 
I know what to do with everything else, I just don't know where to get a url
someone explained it to me yesterday
Is it a website, app, software???
Where are you guys hosting your bots on?
setting up flask and all
:{
GCP
then it's simple for you iguess
like just add an extra route
for webhooks
I see, so just follow the webhook example, the URL would be http://<your instance public IP>:port/path
Wouldn't I do something different because my website is actually on the web
http://<your instance public IP>:5000/dblwebhook if you copy the example 1:1
Is it running on the same process as your bot?
It's not necessarily running. It's uhm... hosting on google firebase
I could go onto a website create a custom webhook link
It's called integromat.com
It works :))
Now I have the webhook... what should I do next?
@restive otter
nvm
I think I've done it
If you use integromat, you don't need the WebhookManager from topggpy
You got the integromat URL, I have never worked with that tbh
yes, I have a url
Now you can answer the question yourself
well it is workin now
wot do i do with this data tho
Hey, how can I make someone vote for my bot to send a notification?
Wdym?
You mean when someone votes for your bot it will send a notification in a channel?
yes
Python or js
js
What are you hosting your bot on
const Topgg = require('@top-gg/sdk')
const app = express()
const webhook = new Topgg.Webhook(process.env['pass'])
app.post('/dblwebhook', webhook.listener(async vote => {
//vote.user is the user ID of the user that voted
}))
app.listen(3000, () =>
console.log(`Example app listening at http://localhost:3000`)
);```
Are you currently hosting a website?
no.
Just add that to wherever your creating the website
i don't know html
ok.
Tell me if it eorks
I dotn believe so as theres no examples of code for doing that, i think the api is just for bots i belive
With replit you can host for free
Also dont you need the DSL bot in your server to advertise it?
Wait no sorry
Wrong thing
I dont believe so
What do you want it for?
On your server page is there a option that says "edit"
Is there a webhooks section
Same as bot one
I think it will work the same as bot
Are you using js or pythin
Uhm im sure it will eork the same
Do you have a web server?
Okay
ahhhhh darkmode
const Topgg = require('@top-gg/sdk')
const app = express() // Your express app
const webhook = new Topgg.Webhook('topggauth123') // add your Top.gg webhook authorization (not bot token)
app.post('/dblwebhook', webhook.listener(vote => {
// vote is your vote object
console.log(vote.user) // 221221226561929217
})) // attach the middleware
app.listen(3000) // your port```
Thats rhe code on the npm package
Try that
Im not sure itll sork with servers but you can try
Once youve done it
I beleive so yes
i answered my own question now lol
apparently so, yes 
idk
it return if user has voted in the month and latest 1000 iguess
i think i know
it does iGuess
what they mean by topgg token
That makes it so much easier
the token above webhook entry
how tho?
Yea
like how'll you check at the instant user has voted
Yes
Yes
that needs a webhook
yea click show token
the let voted = await user has voted thing is for commands
Actually no it dowsnt help in mt case
i know how to get my token
So youve got your server vote thing working?
i was replying to this
meirl about to make the fact command a vote-only thing B)
My vote only are tictactoe and akinator
They know
i just started a world of confufu
?
joy
My all commands xd
They only get images command for not voting , if they vote access to all commands
I dont like to make peiple do stuff to use mine
Wdym
Yes , but me need votes after 100 server and being verified , I will keep vote to use commands in lesser commands
ok thx
how do you make the bot update topgg servercount?
me?
User object has mention method try that
can you send me pls
Remove all of this <@user.username>
ok
Use <@!{user.id}> or {user.mention}
Cause whenever someone is mentioned the message contains there id instead of username
So that in future when username changes
it's like this
Because user is not in your server iGuess
i am in the server
Did you try both of them?
Yea
not mention
The format is right
o
Question
how do i do this?
Using Webhooks
ik that but how?
Which language ?
k wait a second
okie
Hello
hey
@restive otter
const express = require('express')
const Topgg = require('@top-gg/sdk')
const app = express()
const webhook = new Topgg.Webhook('topggauthtoken')
app.post('/webhook', webhook.listener(vote => {
console.log(vote.user)
//Save to db
db.set(vote.user, Date.now())
}))
app.listen(3000)
what's up
what is express?
just use any db like redis, quick.db etc
umm
it's like flask but in NodeJS
const voteTime = db.get(user.id)
if(!voteTime){ return console.log("Nope") }
if((Date.now() - voteTime) <= 12*60*60*1000){
console.log("User has voted")
} else {
console.log("Nope")
}
This checks for vote in last 12 hours
with what ?
like if they recently voted a server?
just save server id along with time
ok 
Im trying to get the webhook working, but i dont really understand how to get the domain... Im running this on my pc for now
const webhook = new Top.Webhook('hereThePsw');
webhook.login('what should i put here? /topggVote', '3000'); //you can edit the port (only numbers) NOTE: PUT .login METHOD BEFORE THE .on('vote') METHOD
webhook.on('vote', vote => {
console.log(`User id: ${vote.user}\nAll data: ${vote}`);
});
did you read the docs?
yeah but i dont really understand
yes but how do i get the domain
wait
whats the link of that github?
im using this one https://www.npmjs.com/package/top.gg-core
ok ty
@willow sphinx @hearty lintel are they allowed to use top-gg as name 🤔
I'll have to get a law degree and get back to you on that
how do I check if the person voted for my bot or not
use a webhook
save the data in a database
fetch data from database and check if the user voted or not
has a packpage that does this?
type a top-gg/sdk
ok so if i want to run this on my pc i will need to do port forwarding and i dont want to... so by running this on heroku what should be the http://your.server.ip:3000 ?
and do i have to do something on heroku to make it work?
yourapp'sname.herokuapp.com iirc
iirc?
ok ty ill try this
http://<yourappname>.herokuapp.com/
the port you run your webserver on will rely on the PORT environment variable
and to get that its process.env.PORT ?
Yes
ok thank you again

i get this in heroku logs at=error code=H14 desc="No web processes running" method=POST path="/dblwebhook" host=ekko-bot.herokuapp.com request_id=415a87c8-e86b-464f-aab9-709e563c7752 fwd="159.203.105.187" dyno= connect= service= status=503 bytes= protocol=https
How to approve my bot?
(when i click "test)
turn web dyno on
umh u mean web npm start?
err i still haven't figured that out to this day
You probably need to run the webserver separately
or just run your bot via web dyno with webserver attached to it
and how do i do that? 
ok so now i changed "worker" with "web" in the proc file and now if i run it and test it i get
at=info method=POST path="/dblwebhook" host=ekko-bot.herokuapp.com request_id=b9b12b0f-eb54-4973-9cc4-40a193723a00 fwd="159.203.105.187" dyno=web.1 connect=1ms service=9ms status=204 bytes=147 protocol=http
2021-07-31T13:17:51.916994+00:00 app[web.1]: {
2021-07-31T13:17:51.917010+00:00 app[web.1]: bot: '864776547285991445',
2021-07-31T13:17:51.917011+00:00 app[web.1]: user: '521758040492474379',
2021-07-31T13:17:51.917012+00:00 app[web.1]: type: 'test',
2021-07-31T13:17:51.917012+00:00 app[web.1]: query: { test: 'data', notRandomNumber: '8' },
2021-07-31T13:17:51.917013+00:00 app[web.1]: isWeekend: true
2021-07-31T13:17:51.917013+00:00 app[web.1]: }
2021-07-31T13:17:52.531950+00:00 heroku[web.1]: Restarting
2021-07-31T13:17:52.543993+00:00 heroku[web.1]: State changed from up to starting
2021-07-31T13:17:52.000000+00:00 app[api]: Build succeeded
2021-07-31T13:17:53.635756+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2021-07-31T13:17:53.734254+00:00 heroku[web.1]: Process exited with status 143
2021-07-31T13:17:55.000365+00:00 heroku[web.1]: Starting process with command `node main.js`
2021-07-31T13:17:57.216138+00:00 heroku[web.1]: State changed from starting to up
its kinda works as i get the test resul
but then it restarts
and i dont think its a positive thing
143 usually means the application caught a SIGTERM signal, meaning the process was killed. This could be because another process killed it, or perhaps because the operating system killed it for using too much memory or some other resource, etc.
and this could be fixed by?
now its working fine
but i dont think i changed anything
🤔
Fuck knows
I've told top.gg to send the POST request to my website on the web
But how do I see it?
def __init__(self, client):
self.client = client
self.token = 'my token'
self.client.topgg_webhook = topgg.WebhookManager(self.client).dbl_webhook("https://webhook.site/'some url'/dblwebhook", "auth code")
self.client.topgg_webhook.run(5000)```
its not responding , havent got any error or response on test
dbl_webhook("/dblwebhook", "auth code")
wheres to put the webhook url then
so i need to put the real auth code or just the text "auth code"
What do you think
Perhaps making a path validator would help people debugging their own code, or just add the route directly when the method's called instead of adding the routes before running? Since aiohttp has its own error for that
If you tell a person "math" do they learn maths from just that?
Path validator
I'll work on it once I'm done with my stuff here
Oh well, that might give clearer sight
Actually, they should've got the error when running. Perhaps it's suppressed because of it's wrapped in a Task?
So I managed to get a working webhook url
I can also see my post requests when I test with Top.gg
Now all I have to do is link it to my bot
Time to figure out how...
I've been thinking that too tbh
Cuz I do get it
~~May/may not be related to asyncio debug flag. ~~Actually, it's on error level, just need to add a handler to the logger
does you path start with / ?
I didn't need help
alr
Im trying to test my webhook and hosting on my pc, but when i try testing it, it does not print anything. Any idea why?
It outputs the exception on ERROR level?
Yeah, but ig you need to add a handler for the asyncio logger
Maybe the basic config will do
Will try to play around later
I removed all the logging handlers and it did output the traceback
nani
I should've probably tested it w/ d.py xd, cuz it's the one that happened to suppress task errors back then

Yeah, it doesn't need any logging handlers tbh. I wonder why they're suppressed back then
Does anybody know how to connect topgg webhook to heroku? Python
does anyone know why DblApi.GetMeAsync() returns null?
id variable has discord bot id and Constant.token has discord bot token
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.
One message removed from a suspended account.
One message removed from a suspended account.
hey, can the topgg api output values as well, such as my bots statistics for my website?
hello!
i have a doubt...
How to add the guild_count attribute in an event in my dpy bot?
Where do u get the real auth code?
import os
import discord
from discord.ext import commands
intents = discord.Intents.all()
bot = commands.Bot(command_prefix='?',
help_command=None,
activity=discord.Game("?help"),
intents = intents)
#HANDLING COGS
#Loading all cogs at the start
for i in os.listdir('./cogs'):
if i.endswith('.py'):
bot.load_extension(f"cogs.{i[:-3]}")
#RUN
TOKEN = os.getenv('DISCORD_MYBOT_TOKEN')
bot.run(TOKEN)
Which API are you using? Is it @top-gg/sdk package?
@jaunty plank Is their a way to check vote status for users like we can check for bots?
api.hasVoted(user.id)
Like this ??
I don't use the npm package
I used node-fetch package to directly make a request to the API
Anyways, now it got solved ❤️
Dbl
dblapi.js is deprecated
Can you switch to the new package? I can help with the new one
yea
/dblwebhook = route
password = Authorization key on top.gg
Which is the new one?
@top-gg/sdk
One sec
The code is js right? Forgot to ask.
Nah sorry
Oh, okay
Just realized ur using js but thx
Ok
@restive otter It is kke this
password is the password you had put in your bot's webhoook settings in top.gg
Yes
topggpy runs it for you
Yea
One question? Is the auth any random one I put?
Correct. Just make sure it matches the value on the website
Another question sorry what specifically should the path look like?
how can i make that if someone voted for my bot he gives him something or tell me that he voted with his id in a channel ??
Use Webhooks.
Here's an example
const express = require('express')
const Topgg = require('@top-gg/sdk')
const app = new express()
const webhook = new Topgg.Webhook('topggauthtoken')
app.post('/webhook', webhook.listener(vote => {
console.log(vote.user) //The user id of the uer who voted
client.users.fetch(vote.user).then(user => {
user.send("Thanks for voting")
}).catch(console.error)
}))
app.listen(3000)
where do i put my bot token or id or ??
No you don't put your bot token
hol on a second
what should i put
then scroll down
You'll find something like this
Here put your url (eg http://PUT_YOUR_IP_HERE:YOUR_PORT)
and a random auth token you like
Then click save
Then go to your code and put the same auth token you put here
you're done
Anyone pls help me how to connect api to bot
which part of api ?
what do i put in here?
i know my ip and port btw
i just forgot how to structure the url
i get this error whenever somebody votes
Error handling request
Traceback (most recent call last):
File "C:\Users\dylan\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\aiohttp\web_protocol.py", line 314, in data_received
messages, upgraded, tail = self._request_parser.feed_data(data)
File "aiohttp\_http_parser.pyx", line 546, in aiohttp._http_parser.HttpParser.feed_data
aiohttp.http_exceptions.BadStatusLine: 400, message="Bad status line 'invalid HTTP method'"
could someone pls help me figure out what this means?
oh i fixed it
How to get authorization
The authorization code is not necessary.
It's Fake
You can also make sure requests coming from topgg by filtering the source IP of the request for example.
I know 🤣
Ta ta ta ta
is there a way to check if user has voted in the last 12h without using the database?
Np I really appreciate your help, sadly is still returns null with version 1.4.0 (at least for me, and It might be my fault but idk what I am doing wrong).
using the database
Which database? Yours?
If you add a timestamp to the records, yes of course you can.
not using a database
const Topgg = require(`@top-gg/sdk`)
const api = new Topgg.Api('Your top.gg token')
await api.hasVoted(user.id)
// => true/false
Select Small (Upvotes) from the drop-down
Copy paste the HTML
i tried this but it said yes even tho i didnt vote today
Python, i use webhook. I run this code and then i make test request and nothing happened
http://ip_from_ipv2:8078/dblwebhook
my link
Or just use the API
can't I use discord.ext.commands.Bot type bot as the parameter here?
then either I need to post my token publicly
or
use a back-end which costs wasy more than hosting a static site
How would a backend cost more? Assuming you have a host you have options.
GitHub pages fact
They asked how do they add it to their website, not that they were using Github pages though 👀
Well
I thought add to website means "Add in HTML"
not make another api handler and then rendering the json in html
Websites aren't just HTML
anyway
I gave a 3 line solution
If you can give one in 2 lines you win

any1?
commands.Bot subclasses discord.Client, so that's fine
I’m completely lost 😞 mayb someone assist me
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))```
What do I put in auth and webhook path?
dblpy is deprecated in favour of topggpy
What should i put as my webhook url to check on my local host pc?
top.gg wont be able to send a webhook to your local host
Oh
Then can anyone show an example using the raw api in python ?
I am hosting on heroku with python and trying to find a webhook url, and nothing is working
sorry for the interruption, but I have come to ask a question regarding the top.gg java sdk:
with the code shown, i am trying to check whether a user has voted or not, using a command, !test. However, in the second picture, hasVoted appears to be null. Why is that?
I’m trying to give my server members some tokens when they vote for my bot on Top.gg
I have tried the bellow code so far and seems to happen nothing. Can anyone please help?
Here is the code so far -
/* THIS POSTS STATS TO Top.gg */
const Topgg = require("@top-gg/sdk");
const { AutoPoster } = require("topgg-autoposter");
module.exports = {
/**
* Starts to post stats to Top.gg
* @param {object} client The Discord Client instance
*/
init(client){
if(client.config.apiKeys.topgg && client.config.apiKeys.topgg !== ""){
const stats = AutoPoster(client.config.apiKeys.topgg, client);
setInterval(function(){
stats.postStats(client.guilds.cache.size);
}, 60000*10); // every 10 minutes
const topgg = new Topgg.Webhook(client.config.votes.password);
topgg.listener(async (vote) => {
const dUser = await client.users.fetch(vote.user);
const member = await client.findOrCreateMember({ id: vote.user, guildID: client.config.support.id });
member.money = member.money + 40;
member.save();
dUser.send(client.translate("misc:VOTE_DM", {
user: dUser.tag
})).catch(() => {});
const logsChannel = client.channels.cache.get(client.config.votes.channel);
if(logsChannel){
logsChannel.send(client.translate("misc:VOTE_LOGS", {
userid: dUser.id,
usertag: dUser.tag
}));
}
});
}
}
};```
Why does the API sometimes return status code 401 and it sometimes returns status code 200?
401 and 200 are different things
200 means request is successfull, 401 means your api key is invalid
send a request to the api https://top.gg/api/bots/869410048743473182/check?userId=id
header = {"Authorization" : self.bot.dbl_token}
res = requests.get(f"https://top.gg/api/bots/869410048743473182/check?userId={ctx.author.id}",headers=header)
if res.status_code != 200:
raise TopGGApiConnectionError("Failed to connect to API",res.status_code)
hmm
Anyone?
If you don’t specify one there’s none
Using webhooks or send requests to the topgg API
Webhooks being sent right in the moment someone votes
Requesting the API will show all voters of the past 12 hours only
Without timestamps afaik
Yes
data['user'] will return ID of the user who voted
In a string though. Remember to convert it to int
does anyone know how to make a voting system
being the host an azure vps
how do I know when a user has voted (in real time) java/kotlin
const DBL = require('dblapi.js')
const dbl = new DBL(process.env.TOPGG_TOKEN, { webhookPort: 3000, webhookAuth: process.env.TOPGG_AUTH });```
Can I change the webhookPort to other number?
def addUpvoteRecord(userid):
with open("vote.json") as f:
vote_list = json.load(f)
if not userid in vote_list:
vote_list[userid] = []
with open("vote.json", "w+") as f:
json.dump(vote_list, f)
@client.event
async def on_message(message) :
if message.channel.id == 870147153706750022 :
data = message.content.split(" ")
user = re.sub("\D", "", data[5])
addUpvoteRecord(user)
await client.process_commands(message) ```
i am getting this error
> TypeError: list indices must be integers or slices, not str
can anyone help me??
One message removed from a suspended account.
What kind of number I can change it?
One message removed from a suspended account.
One message removed from a suspended account.
Oh..
One message removed from a suspended account.
One message removed from a suspended account.
Okay then.
One message removed from a suspended account.
One message removed from a suspended account.
I see.
One message removed from a suspended account.
One message removed from a suspended account.
Oh okay!
One message removed from a suspended account.
One message removed from a suspended account.
@scarlet cobalt Sorry late reply I didin't realized, but thank you so much!
How to get the server count or user count that using the bot i need to put it on my html/css/js website
Example:
There are (users count) users using the bot
@scarlet cobalt
that's not topgg api related at all
Just count up memberCount in all guilds in all shards
Wdym?
I mean discord bot server members count meaning,
Count of servers that the bot's in, i got a discord bot website so i need an server bot count to my html website
@smoky marten
const app = require("express").Router()
const {Webhook} = require("@top-gg/sdk")
const wh = new Webhook(process.env.voteWhPass)
app.post("/vote",wh.listener((vote)=>{
console.log(vote)
}))
app.get("/vote",(req,res)=>{
res.send("a")
})
module.exports = app
is this correct?
ignore the get one
help??
????
how many servers is your bot in ?
also You can't put in directly in your HTML (Unless you wanna just put the default card from top.gg)
You'll need an api. Either you'll have to make the api or use a third party api (like top.gg) but if you use top.gg api you'll end up making your token public (Which is not suggested at all) so your best choice should be making an api for it then using js fetch to get the count from the api
Hello how can i add my bot commands in top gg?
import topgg
# This example uses topggpy's webhook system.
bot.topgg_webhook = topgg.WebhookManager(bot).dbl_webhook("/dblwebhook", "password")
# The port must be a number between 1024 and 49151.
bot.topgg_webhook.run(5000) # this method can be awaited as well
@bot.event
async def on_dbl_vote(data):
"""An event that is called whenever someone votes for the bot on Top.gg."""
if data["type"] == "test":
# this is roughly equivalent to
# `return await on_dbl_test(data)` in this case
return bot.dispatch("dbl_test", data)
print(f"Received a vote:\n{data}")
@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 vote:\n{data}")
In this example, what is bot? It doesn't make any sense, bot isn't even defined anywhere in the example but it just exists?
Python btw
Check the parameter type of webhookmanager
|| ||
just put it in description
discord.Client and anything that subclasses it
I’m trying to give my server members some tokens when they vote for my bot on Top.gg
I have tried the bellow code so far and seems to happen nothing. Can anyone please help?
Here is the code so far -
/* THIS POSTS STATS TO Top.gg */
const Topgg = require("@top-gg/sdk");
module.exports = {
/**
* Starts to post stats to Top.gg
* @param {object} client The Discord Client instance
*/
init(client){
if(client.config.apiKeys.topgg && client.config.apiKeys.topgg !== ""){
const topgg = new Topgg.Webhook(client.config.votes.password);
topgg.listener(async (vote) => {
const dUser = await client.users.fetch(vote.user);
const member = await client.findOrCreateMember({ id: vote.user, guildID: client.config.support.id });
member.money = member.money + 40;
member.save();
dUser.send(client.translate("misc:VOTE_DM", {
user: dUser.tag
})).catch(() => {});
const logsChannel = client.channels.cache.get(client.config.votes.channel);
if(logsChannel){
logsChannel.send(client.translate("misc:VOTE_LOGS", {
userid: dUser.id,
usertag: dUser.tag
}));
}
});
}
}
};```
because thats not how it works
topgg.listener is a express middleware
It's there any set reason, or is it a big that the bot suddenly can't Post server count?
Like it runs fine for a long time, and then suddenly it stops
How can i use the api without express?
you can use api.hasVoted()
but the user needs to run a command
snowflake isn't a real (JSON) data type. do these parameters exist as strings or integers?
Strings
alright, thanks
I think there should be an example showing you so
there are no example requests on https://docs.top.gg/resources/webhooks/, which is where this table is located
Ah I see… not for webhooks tho
Nvm then
But you can test the functionality and will see the response being a string
if only it was that simple in languages where the request body needs to be deserialized to a type in the first place
Which language are you talking about?
rust
Output it as string ezpz /s
Maybe i will pass that to messageCreate event.
hey guys im confused how to use the express thingy is there a example code somewhere cuz i have never used express anywhere
where should i put this code?
any server / computer / container connected to the internet and about to run NodeJS
How do I make a command that only works if the user has upvoted the bot I cant figure it out
I need it in discord.py
Use the API in pins. Listen to the vote event. Save voter ID in database with a timestamp. When the command is run, check message timestamp against user's ID in the database. If less than 12h have passed since their last vote, run the command.
Wait what
I'm even more confused
My bot is small so I will probably save it in a .json file
I definitely would never recommend that.
Ok
For anything
The only reason why I do it is I have never used a database before and its confusing
You'll have to learn then! 😊
Well ok thanks for the help I really appreciate it
https://docs.top.gg/api/bot/
I looked here, but the number of members is not withdrawn, right?
console.log(`Posted stats to Top.gg | ${stats.memberCount} users.`);
```I tried it didn't work.
mind showing more of your code ?
that much code dosen't giv sheit
How do i make a commamd which will make bot join vc ONLY when he vote the bot i am using discord.js
api.hasVoted()
I have a problem with my bot's TOKEN.
I've changed it several times and every time a user votes for the bot it keeps giving an error, saying that the user didn't vote. This problem started yesterday
https://normal-api.ml/topgg/hasvoted?bot=**BOT ID**&user=**USER ID**&token=**BOT TOKEN**
No, I'm saying how memberCount is drawn, I asked a question about the code
So, i’m trying to setup webhooks for Top.gg. I’m using aws ec2 to host the bot. I’m trying to do a simple request of getting the user who voted (as shown in the Top.gg module example). But i’m not sure how to setup aws to work with the webhook. Should i pass the ipv4 shown in the instance along with the /topgg added on the webhook url field? Can anyone help? Here is my code - ```js
const Topgg = require('@top-gg/sdk');
const webhook = new Topgg.Webhook(client.config.votes.password);
const express = require('express');
const app = express();
app.post('/topgg', webhook.listener(vote => {
// vote is your vote object e.g
console.log(vote.user);
}));```
Anyone?
Should i pass the ipv4 shown in the instance along with the /topgg added on the webhook url field?
@mossy gazelle Give it a try. Make sure you actually run the webserver first though
I think i have the web server running as i followed this tutorial to setup - https://ourcodeworld.com/articles/read/977/how-to-deploy-a-node-js-application-on-aws-ec2-server
Are you sure it's actually running? Have you tried opening the URL manually in your browser?
It errors. ERR_CONNECTION_TIMED_OUT
Seems either the webserver isn't running or your port is not set up properly
I have tried changing configurations of security group. Express throws err if i change anything.
But with this, no errors
May i send you screenshots of security group inbound rule and ip setup so you can make sure?
Sure
Please check your dm in sometime
Do you have app.listen(...) in your script?
Yes
Odd
Sorry I was in class
anyway the full code should be like
const { Api } = require("@top-gg/sdk")
const api = new Api("YOUR_TOP-GG_API_TOKEN")
//rest of the code
//someone in the code
const voted = await api.hasVoted(message.author.id)
if(!voted){ return "User is not voted" }
return "User is voted"
“Hi developer 🥰, welcome to top.gg developer docs. You are currently viewing v0 of our API documentation. We're going to be working on the next version of the top.gg API (v1) soon, stay tuned!”
i’m sorry i don’t know english the best, but does this mean v1 is not out yet or the docs aren’t finished?
thanks! would it be best to wait for v1 or should i start on v0
Nah God knows when v1 will release
Still stuck here. Get works but post doesn’t
const express = require("express")
const api = require("node-fetch")
const app = express()
const {Webhook} = require("@top-gg/sdk")
const wh = new Webhook("no")
app.post("/vote",wh.listener((vote)=>{
console.log(vote)
console.log("a")
}))
app.get("/",(req,res)=>{
res.send("yo")
console.log("d")
})
app.listen(2000)
did i set this up correctly?
topgg keeps saying there was an error processing request
looks right, are you trying to add a webhook to a server?
yes
webhooks for servers are kinda broken right now.
how exactly am i supposed to use the authenticator for the API?
like
Authorization:
i have no idea what to put there
you can just check it vs a string
your the one who chooses it
its like a password, you decide it.
yep, on the site. then just use it in your code.
so just double checking
Authorization: My Password
that’s literally it?
man i overthink things lol
A password, litterally mine i just spammed chars in my keyboard and copied it over to my code.
dont like use an actual password for like discord or something 👀
uh it just said my password isn’t defined
👀 new to programming?
might help to learn what variables and strings are.
sort of new, it’s just
sometimes terms confuse me
usually i can just tinker until i get it right
that’s a lot of the fun for me tbh
ah, just kind of "trying stuff" wont work here
but now im introducing something that’s pretty concrete, completely throws off my style
webhooks require understanding of how the internet works, websites work, routers work, and an understanding of your code.
eek
but if you look at my code can you tell me what i’m supposed to do? i wanna learn from that because the api docs told me to ask here
are you looking to understand webhooks, or just want to make it work?
I can give you resources understand it, or just ask and give you copy paste sources till it works 👀
at the moment making i want it to work so i can understand it, i am a visual learning in that sense
could you do both by any chance?
I dont know if I have time for that tbh.
uh i’ll ask someone else for resources, could you help me get it to work?
ye, wheres your code being hosted? vps, replit, heroku, home?
at home
https://docs.top.gg/libraries/javascript/#webhooks
const Topgg = require("@top-gg/sdk")
const express = require("express")
const app = express()
const webhook = new Topgg.Webhook("your webhook auth")
app.post("/dblwebhook", webhook.listener(vote => {
// vote will be your vote object, e.g
console.log(vote.user) // 395526710101278721 < user who voted\
// You can also throw an error to the listener callback in order to resend the webhook after a few seconds
}))
app.listen(3000)
^ the above code is pretty much copy paste.
youll need to install the sdk.
npm i @top-gg/sdk
also what does replit and heroku mean? i don’t know this term
replit and heroku are hosting providers. replit is a development platform mainly for students, heroku is mainly intended for websites and making an api.
both are not really for bots, but many people use them for bots.
OHHH
let me know when youve added the above code.
i knew what vps meant and i just got confused with those
would i replace my old code?
since this is a webhook, youll not want it inside a command like that.
webhooks have their own events, so they dont depend on discords.
this sort of looks like a event, would i put it in my main.js then?
yeah, outside any other events
oh alrighty, added the code now im just installing the package
your next bit is going to be port forwarding.
port forwarding is how the router knows where to send data to on your network.
https://portforward.com/
its router specific, so i cant be much help here. the above link has guides for most routers.
pretty much
incoming request -> router looks at the port -> if the port is forwarded it sends the data to that device -> device handles it
also can i log people voting to a channel?
yep
how would i do that?
youd have to do all of this first 👀
I'm using the Discordia Library, and i've been trying to figure out the api for updating server count on my bot's top.gg page. I've been basing all of this on https://docs.top.gg/api/bot/#post-stats. Here's my code:
local http = require('coro-http')
local body = {
server_count = #client.guilds,
shards = client.shardCount,
shard_count = client.totalShardCount
}
body = json.encode(body)
print(body)
local header = {
{"Authorization","(my key)"}
}
local res, bod = http.request("POST","https://top.gg/api/bots/794759245408370729/stats",header,body)
return(bod)
json body: {"shard_count":1,"server_count":43,"shards":1}
response body: {"error":"Required parameter server_count or shards missing"}
It looks like I have both of those required parameters, what isn't working? Also, doesn't the documentation say only server_count is required?
im at the menu now, what port would i forward?
hmm, it might be related to the fact content type isnt being set, so the site doesnt know what the body format is.
3000 in the code example i gave
theres a couple things i need to fill out and idk with what
services:
port range:
local ip:
local port:
services: is probably TCP, guessing its protocol, but maybe not?
port range: 3000-3000
local ip: the internal ip of the computer thats running the code
local port: 3000
uhm i’m going to sound very stupid but i have no idea what my IP is lmao
windows 10
anyone know of a ebay watcher and viewer bot?
Nope
sorry, for the computer hosting it
try #general or searching https://top.gg/, or google.
thanks x
i get that a lot but it’s a trash laptop

oh also i think i have to install the express package since it said it at the top of your code
anyways what am i supposed to do to find out?
That worked, I wish I remembered that. Thanks for the quick reply!
windows key, type in "network status"
then view hardware and connection properties.
https://i.woo.pics/0bb3ca4d92.webp
your looking for ipv4 address
https://i.woo.pics/6963d7be85.webp
honestly, took a shot in the dark.
glad it worked
you just need everything before /24
nah, not needed
make sure to save. some routers will look like they saved but havent(i need to click save like 3 times for it to work on mine)
i spammed apply lol
honestly, wont know it worked till you test it, probably easiest that way.
uh how do i test it?











