#topgg-api

1 messages · Page 142 of 1

restive otter
#

Hi

oak orbit
#
const Topgg = require('@top-gg/sdk')
const api = new Topgg.Api('my topgg token')

setInterval(() => {
    api.postStats({
        serverCount: client.guilds.cache.size,
        shardId: client.shard.ids[0],
        shardCount: client.options.shardCount
    })
}, 1800000)
``` can someone tell my why tf I got ratelimited?
#

should I increase the interval to 3600000?

rain heart
#

what's the ratelimit error you're getting

short isle
#

my server count is not showing on my bot's page i used the updated code but still don't work this is the code:

from discord.ext import commands

import dbl


class TopGG(commands.Cog):
    def __init__(self, client):
        self.client = client
        self.token = ''  # set this to your DBL token
        self.dblpy = dbl.DBLClient(self.client, self.token, autopost=True)  

    @commands.Cog.listener()
    async def on_guild_post(self):
        print("Server count posted successfully")


def setup(client):
    client.add_cog(TopGG(client))
calm pulsar
#

How do I set up the voting query command with Discord.js?

gentle yacht
#

How does someone vote for My Bot send him a thank you note for voting for the bot

novel notch
#
gg
narrow trellis
#

you're testing with a discord webhook url?

trail crest
#

where deh fak is my api key

rain heart
#

read pins

trail crest
#

o its there

#

ok

short leaf
#

How do I get my bot here on top.gg site?

rain heart
#

have your bot certified

#

you can't anymore though

short leaf
#

my bot is approved

restive otter
#

can someone send me a link to the API

#

on the topgg site

true pecan
#

When will my bot be approved?

brittle spoke
restive otter
#

ty

restive otter
#

is the only thing we can receive are votes?

#

Like does the api support comments etc..

obtuse roost
#

someone please tell me how can i use webhook for vote logs.

#

I tried almost everything thing but can't get log on channel.

#

code sample:

  @commands.Cog.listener()
    async def on_dbl_vote(self, data):
        chan = self.client.get_channel(channel_id)
        user = self.client.get_user(int(data['user']))
        await chan.send(f"<@{user}> has voted!")
  
night ingot
#

Why did you ping a community manager?

green roost
pastel drift
vast umbra
#

do you have to pay for the api

night ingot
#

No, you don't

vast umbra
#

ok

#

thx

night ingot
mortal wasp
#

Hey

rain heart
#

-api

abstract mothBOT
#

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.

mortal wasp
#

What is api

#

Hop

rain heart
#

top.gg api, this channel isn't for off-topic conversations

mortal wasp
#

Do you mean Toxic

#

R no

rain heart
#

Change channels please

mortal wasp
#

To what

rain heart
#

-api

abstract mothBOT
#

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.

mortal wasp
#

What is that

rain heart
#

once again, change channels

mortal wasp
#

Hello

rain heart
#

-api

abstract mothBOT
#

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.

rain heart
#

last warning

mortal wasp
#

Can we be friends

#

Hop

rain heart
#

-m @mortal wasp decided to continue off-topic conversations in #topgg-api after multiple warnings | 12h

abstract mothBOT
#

🤐 Muted valentino5972#3736 (@mortal wasp)

obtuse roost
rain heart
#

because you should wait for someone who can explain it. As I don't know python

#

The docs are the fastest you can get

supple karma
#

https://top.gg/api/bots/:id
sends unauthorised instead of bot data when trying to fetch it, but if I visit the site via browser, it shows me bot data.. how to get bot data via fetch then?

rain heart
#

You need to set a Auth header with your top.gg token

supple karma
#

🤔

rain heart
#

Which is set on your browser by default (when logged in)

supple karma
#

ohh

#

so i need to get the bot top.gg token and set it ?

rain heart
#

with the Authorization header, yes

supple karma
#

k thanks

#

:)

oak orbit
wraith skiff
#

What is the best way to setup a webhook for the voting?

rain heart
#

how exactly does it tell you? in a json form or in html?

oak orbit
rain heart
#

just a simple 429 too many requests? nothing with html or anything?

#

then most likely ratelimited from top.gg, wait an hour

#

if nothing changes, a full day

oak orbit
#

In the interval?

rain heart
#

nah just don't do nothing in regards to the api, take out your server count interval and wait an hour

oak orbit
#

Hm k

rain heart
hasty echo
#

Hey just wondering if anyone was able to add voting to their bot while having it sharded 😅 Struggling to find out how to do it

barren kestrel
#

Anyone? An another alternative is hosting the webhook on my local network, but idk what to port forward etc

plucky lance
#

you will forward the port you specifiy yourself

#

@barren kestrel Use a random port from the range 9000-65000

#

allow incoming TCP connections for this port in your firewall

#

and forward the port (TCP) to your device

#

but if you don't got a static IP address it may get difficult

#

you will likely create your own DDNS or use a public service if it really needs to be hosted from home

barren kestrel
#

Lan*

#

And also how do I find available poets

#

Ports

#

This is so confusing

plucky lance
#

you will have to use your public IP of course... there's no IP forwarding, just port forwarding, the port you can freely CHOOSE

barren kestrel
#

Ok

plucky lance
#

to know your public IP address

barren kestrel
#

That is my publix

#

Ik

#

But

#

I can’t paste that in my forward menu

#

It says to port forward an ip or something

plucky lance
#

yes forward the port the a device which got a local IP assigned by your router

#

probably 192.168.x.x

#

the webhook is sending a package to your public IP, your router accepts the incoming package (because you allowed TCP package on that port) and will forward it to your local device

#

the local device the webhook service is running on

#

and to find the local device the router needs it's LAN IP

#

depending on the router it might be a good idea to assign a static (local) IP address to the device

#

if your router supports this

barren kestrel
plucky lance
#

that actual local device IP

barren kestrel
#

Where do I get that

plucky lance
#

take a look into your router, it should have a LIST of all connected devices

barren kestrel
plucky lance
#

dunno what router you have

barren kestrel
#

Netgear nighthawk

#

R7960P

#

I’m on the list of attached devices

#

Do I find my device ip

#

In that list

plucky lance
#

you should yes

barren kestrel
#

ok

plucky lance
#

as well as the local device names, MAC addresses etc.

#

probably

barren kestrel
#

ok so

plucky lance
#

depends on the router always

barren kestrel
#

in my router port fodwaring menu

#

i says

#

service name

#

and an option

#

rn its at ftp

#

Then next to it is the server address

#

Whi9hc I copyed and pasted from my laptop on the attached devioces menu

plucky lance
#

don't choose a prexisting service

barren kestrel
#

huh

#

so what do I clicik

plucky lance
#

can you actually add an own?

#

Protocol is TCP, port the one you choose (from 9000-65000)

barren kestrel
#

Service name

#

and Server IP address

plucky lance
#

gimme a screenshot of it

barren kestrel
#

Is it add custom service?

plucky lance
#

don't need to hide local IP range but ok

#

hold on lemma look

barren kestrel
#

oh ok

#

k

plucky lance
#

add custom one, yes

barren kestrel
#

ok

plucky lance
#

service name can be whatever you like

barren kestrel
#

@plucky lance

#

Now what

plucky lance
#

lets enter a service name, for example topgg webhook

barren kestrel
#

ok

#

then

plucky lance
#

choose TCP only not TCP/UDP

barren kestrel
#

ok

#

then

plucky lance
#

external starting AND ending port is the port you wanna choose, e.g. 9111

#

whatever you like

#

same like internal port

#

and instead of enter the devices IP you can CHOOSE it

barren kestrel
#

Ill do 5000

plucky lance
#

no

#

Protocol is TCP, port the one you choose (from 9000-65000)

#

not from a range < 9000

barren kestrel
#

Oh

#

so 9000?

plucky lance
#

you could block existing ports required from different services, OS, etc.

#

9000++

barren kestrel
#

so

plucky lance
#

9500, 9005, 9555 whatever you like

barren kestrel
#

k

plucky lance
#

19555

barren kestrel
#

9500

#

ok

#

19555 it is

plucky lance
#

and then choose the device and save it

barren kestrel
#

Ok

#

Ok done

#

saved

plucky lance
#

guessing the device is Windows?

barren kestrel
#

Yes

#

I host on a spare laptop, and use anydesk to access it whenevfer

plucky lance
#

you need to accept internal connections on that port now in the firewall

barren kestrel
#

Ok how to do that

#

Tysm for this detailed explanation btw

plucky lance
#

one second, lemme get a command line runner

barren kestrel
#

np

#

take ur time

plucky lance
#

AWWW FUCK

#

a typo

#

hold on

#

netsh advfirewall firewall add rule name="topgg webhook" dir=in action=allow protocol=TCP localport=19555 enable=yes profile=any

#

open the windows command prompt and enter this

#

you will probably need to open the command prompt as admin

#

you can later view that entry in the firewall app

#

response should be OK

#

@barren kestrel

barren kestrel
#

Ok

#

Ill do that

plucky lance
#

nope

barren kestrel
#

command prompt

#

?

plucky lance
#

command prompt

#

cmd

barren kestrel
#

in system32

#

right

#

the directory

#

I cant do it rn as Im away from host pc, but I will do ASAP

plucky lance
#

oh alright

barren kestrel
#

tysm for this help

#

thats servie nma ebtw

#

name*

plucky lance
#

just hit your Windows icon in the taskbar and start typing CMD without pressing something

barren kestrel
#

netsh advfirewall firewall add rule name="Topgg webhook" dir=in action=allow protocol=TCP localport=19555 enable=yes profile=any

plucky lance
#

yes to identify the firewall record

barren kestrel
#

ok

plucky lance
#

you will be able to see it later in the list

jade zodiac
#

Are We Getting the Api Key From Here?

plucky lance
#

you can later open your firewall app on your device Windows Defender Firewall with Advanced Security > select INCOMING RULES on the left list > sort by name > see your record

barren kestrel
barren kestrel
#

Find that and there it is

plucky lance
barren kestrel
#

@plucky lance I just now after running that in my command prompt, I add to code right?

#

I have my code already

plucky lance
#

run the command prompt, enter what I've sent, press enter

#

should return OK

barren kestrel
#

k

vivid nest
#

This is my code: ```import discord
from discord.ext import commands, tasks
import dbl

class TopGG(commands.Cog):
def init(self, bot):
self.bot = bot

@tasks.loop(minutes=30)
async def update_stats(self):
    """This function runs every 30 minutes to automatically update your server count."""
    await self.bot.wait_until_ready()
    try:
        server_count = len(self.bot.guilds)
        await self.dblpy.post_guild_count(server_count)
        print('Posted server count ({})'.format(server_count))
    except Exception as e:
        print('Failed to post server count\n{}: {}'.format(type(e).__name__, e))

@commands.Cog.listener()
async def on_dbl_vote(self, data):
  user = data['user']
  embed = discord.Embed(description="New Vote! Voter: {}".format(user))
  channel = self.bot.get_channel(int(822973544412741632))
  await channel.send(embed=embed)

def setup(bot):
bot.add_cog(TopGG(bot))This is what happens when someone votes:Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x7fbd44abb910>```

#

Any ideas?

plucky lance
barren kestrel
plucky lance
#

oh yeah forgot that part, lemme know later

sullen nymph
#

Where do you even have your webhook that runs to receive the event

sick canyon
barren kestrel
barren kestrel
plucky lance
#

pretty sure he talked to the guy above us, providing snake code

barren kestrel
barren kestrel
#

I got the ok

#

so I now add to code?.

plucky lance
#

Now I'm able to hack into your system... already downloading any credit card information

#

joking

barren kestrel
#

ik

plucky lance
#

well yeah, now make sure to add your public ip to topgg and the port

barren kestrel
#

ok

plucky lance
#

you will probably also need to specify that port in the code again

#

the code for the webhook service

barren kestrel
#

@plucky lance

#
const express = require('express')
const app = express() // Your express app
const webhook = new Topgg.Webhook(config.topggwebhookauth)
const dwebhook = stuff

app.post('/dblwebhook', webhook.middleware(), (req, res) => {
  // req.vote is your vote object e.g
  console.log(req.vote.user) // 221221226561929217
  dwebhook.send(`<@${req.vote.user}> has voted for News Agent on top.gg!`)
});

app.listen(19555)```
plucky lance
#

well never worked with express, can't help u with that

#

but it seems to be right, I guess

barren kestrel
#

Ok but is my ip part right?

plucky lance
#

yes, your public IP address not the internal LAN address

barren kestrel
#

k

plucky lance
#

just for reference

barren kestrel
#

@plucky lance No error, and it doesnt work

plucky lance
#

press save before using test

barren kestrel
#

Did

plucky lance
#

might still be an issue

fickle breach
#

whats the code for sending guild count to top.gg again

barren kestrel
#

I think its in docs

#

py or js

fickle breach
#

js

barren kestrel
#

ye its in docs

fickle breach
#

lemme look

barren kestrel
#

@fickle breach

#

and there

fickle breach
#

oh sweet

#

thanks

barren kestrel
#

np

barren kestrel
plucky lance
#

well your side is configurated well

#

do you even have a public IP v4?

#

make sure it's an actual IPv4 not v6

barren kestrel
#

yes

#

I copyed that

#

added the port

#

and the /dblwebhook

plucky lance
#

hmm imma not sure about express tbh

barren kestrel
#

Its the exact code in the docs as well

plucky lance
#

if you router successfully forwards the port it should be ok

barren kestrel
#

How do I check if it forwarded it again?

#

@plucky lance

plucky lance
#

one second

barren kestrel
#

ok

vivid nest
#

is it possible to know who upvoted my bot with only a token?

barren kestrel
#

but if you have a token yes

vivid nest
#

ok

barren kestrel
#

you would need webhook url, webhook auth, and top.gg token

#

@vivid nest

vivid nest
#

how do i get webhooks tho

barren kestrel
#

And then your language

plucky lance
#

@barren kestrel To check if the port is opened up open a Windows command prompt from outside your network and enter telnet your-public-ip 19555 and see what u get

jade zodiac
barren kestrel
#

o h wait im installin rn

plucky lance
#

On the external device: click on the windows icon > enter windows features > scroll down > tick the checkbox for telnet > wait until installation is done

barren kestrel
#

yes ty

plucky lance
#

can also be done from a Linux device of course

#

doesn't need to be an external Windows device

barren kestrel
#

@plucky lance

plucky lance
#

that's bad, that means your router didn't forward the port

barren kestrel
#

eEEk

plucky lance
#

do you probably need to activate the rule?

#

or is the checkbox just to delete the rule?

#

ow wrong link... meant the image below

barren kestrel
#

wdym

plucky lance
barren kestrel
#

the box is to

plucky lance
#

there's a little checkbox infront of the rule

barren kestrel
#

edit or delete

plucky lance
#

oh ok

barren kestrel
#

ye

plucky lance
#

the internal device IP is correct?

barren kestrel
#

i chnaged the name to

#

yes

#

topgg webhook

#

no caps

#

or how bout

#

topgg

plucky lance
#

hmm doesn't matter

#

well than your ISP is blocking these port(s) probably

barren kestrel
#

probs

#

cann try changing ports?

plucky lance
#

in the first place try to restart the router and test it out

barren kestrel
#

Ok

plucky lance
#

yes

barren kestrel
#

Ill update firmware and restart

plucky lance
#

you can change the port to 80

#

but remember to do that anywhere

barren kestrel
#

80?

plucky lance
#

also for the firewall rule

barren kestrel
#

i thought above 9000

#

k

#

Can I remvoe the old firwewall rule

plucky lance
#

yeah 80 is the default webserver port (HTTP)

barren kestrel
#

ok

#

ill do 80

#

how do I del old friwwall rule

plucky lance
#

you can edit the firewall rule

plucky lance
fickle breach
#

where is the page for getting ur bot's api token again

plucky lance
#

Double click your rule > protocolls and ports > change 19555 to 80

restive otter
barren kestrel
plucky lance
vivid nest
#

How can I read this 172.18.0.1 - - [21/Mar/2021 16:33:29] "POST / HTTP/1.1" 405 -

barren kestrel
#

ok

fickle breach
plucky lance
#

netsh advfirewall firewall add rule name="Topgg webhook" dir=in action=allow protocol=TCP localport=19555 enable=yes profile=any

fickle breach
#

it used to be in some api page so I got confused

plucky lance
#

rule name="Topgg webhook"

barren kestrel
#

k

barren kestrel
#

now changing to code

#

then u[dating frimware and restarting

plucky lance
#

and the router

#

aye

#

just to make sure, the actual code is on the device?

#

you forwarded the port to

vivid nest
#

what do i hav eto put in webhook_path

barren kestrel
#

it is on the device I forwadeded

plucky lance
barren kestrel
#

Updating firmware

plucky lance
#

that doesn't fix issues with port forwarding but isn't a bad idea anyways

#

if port 80 isn't opened up after a restart of your router then Houston we got a problem

barren kestrel
#

Yep

barren kestrel
#

Also router restarting rn

plucky lance
#

I replied to somebody else

barren kestrel
#

Ah

#

@plucky lance Ok

#

Port is 80 rn

#

Im restrtaing

#

and we will test

plucky lance
#

aye

barren kestrel
#

ay retsrarted router

#

now to test

#

🤞

#

Oh shoot

#

im dumb

#

@plucky lance

#

I did this on my norm pc and not my host pc 🤦

#

forgot to allow the port forwars tuff

plucky lance
#

O M G

#

getting my baseball bat ready

barren kestrel
#

uhm

#

Its not

#

showing on my firwall thingy

#

it said ok

#

@plucky lance

plucky lance
#

what

barren kestrel
#

its now showing up on my firwall section

plucky lance
#

port 80?

#

O N the device your webhook code is parked?

barren kestrel
#

yes

plucky lance
#

alright

barren kestrel
#

Topgg Webhook isnt showing up

plucky lance
#

it's not in incoming rules?

#

thought it was there a mins ago you edited the firewall rule

barren kestrel
#

Ok now it is

#

one minute

#

im fixjng

#

IT STILL SAYS CLOSED

#

I ENABLED

#

AND IT SHOWS ON FIREWALL

#

AND ON ROUTER-LOGIN

#

@plucky lance

plucky lance
#

well then you're basically fucked, your ISP is filtering the ports

#

don't think it's the routers fault, netgear isn't building bad stuff

barren kestrel
#

im dumbo

#

and did the wrong ip c:

#

@plucky lance Lets start from step 1

#

Ok that step done

#

Next I do ther firewall

#

netsh advfirewall firewall add rule name="topgg" dir=in action=allow protocol=TCP localport=80 enable=yes profile=any

plucky lance
barren kestrel
#

Yes

#

Ok so now it shows up in my firewall

#

now we

#

do the thing

plucky lance
#

CHOOSE the RIGHT device in your router the CODE is running ON

#

then ON that device add the FIREWALL rule

#

that's it

#

your public IP address remains the same of course

barren kestrel
#

I did but it still says cannot connect

#

@plucky lance

#

It shows on firweall

#

Is that right

#

ok idk what to do

#

this isnt working

plucky lance
#

yeah like I said, all incoming package will pass your ISP first, then your router, then your device

#

your ISP might drop some package he doesn't like or he thinks you don't need

barren kestrel
#

Like tyhis

#

thats why

#

lets do something big

#

random

plucky lance
#

you will probably need to contact your ISP and question him about it or just host the code on a public device

#

like a dedicated server / VM

barren kestrel
#

read above

#

@plucky lance

#

SO what port can we use

#

lets use 19555

plucky lance
#

sure test it out

#

you now know how it works tho

barren kestrel
#

netsh advfirewall firewall add rule name="topgg" dir=in action=allow protocol=TCP localport=19555 enable=yes profile=any

barren kestrel
plucky lance
#

don't always add new firewall rules

barren kestrel
#

Oh I deleted the old ones

plucky lance
#

edit the rule like I told you

barren kestrel
#

so thats why im adding

plucky lance
#

simply editing it is enough, it's active in the moment you're saving it

barren kestrel
#

Eek ok ill just make it this last time

#

Ok it shows up

#

@plucky lance

#

YES

#

its open

#

what I had to do

#

was

#

first chnage the port to that

plucky lance
#

you remember I said before use ports > 9000

barren kestrel
#

tthen in code

#

yes

plucky lance
#

looks like I was right

barren kestrel
#

then in my code I needed to listen to it first, then run my bot, then check

#

only then it listens yes

#

ty

#

let me try again now

plucky lance
#

as long as the code really is on the device the firewall rule is set, it should now work

barren kestrel
#

@plucky lance Doesnt send

plucky lance
#

saved before clicking the test button?

barren kestrel
#

Yes

#

:c

#

nope

#

dont work

plucky lance
#

did the telnet check work?

#

@barren kestrel if so you may wanna join #support and ask if somebody can send u a webhook to test it out and see the response (even if it fails)

barren kestrel
barren kestrel
#

Can you xD?

#

The bot is “News Agent”

plucky lance
#

nope but I can send u a webhook

#

hold on

#

send a PM to me including your public IP

barren kestrel
#

What

#

No dude

plucky lance
#

well then, I can't send u a webhook

barren kestrel
#

You can test

#

If you vote for the bot

#

:/

#

But it’s fine

#

I’ll try

#

It’s probs code

plucky lance
#

If the test button didn't work you won't receive one I guess

#

that means you need to debug why

thorny matrix
#

is there a precise guide on how to get the if a person votes for your bot API in discord.py

plucky lance
#

that requires to send a webhook to your endpoint FROM external and see the debug log

#

(the response)

barren kestrel
#

ok

plucky lance
#

since the port is open there will be an error

thorny matrix
#

okay , any precise guide?

#

on YT or Google maybe

plucky lance
thorny matrix
#

can someone teach me how to use the Vote for bot API with discord.py

plucky lance
#

read the docs in the first place

short isle
#

the topgg api isn't working for me as no errors are thrown. I am trying to show the count of servers my bot is in but on the page it shows N/A

here's the code:

from discord.ext import commands

import dbl


class TopGG(commands.Cog):
    def __init__(self, client):
        self.client = client
        self.token = ''  # set this to your DBL token
        self.dblpy = dbl.DBLClient(self.client, self.token, autopost=True)  

    @commands.Cog.listener()
    async def on_guild_post(self):
        print("Server count posted successfully")


def setup(client):
    client.add_cog(TopGG(client))
forest shard
#

Or did you just plain copy and paste it without reading what you’re supposed to do

short isle
#

i removed it here tho so no one can use it lol

short isle
short isle
#

???

restive otter
#

hi

open surge
#

where is any suggestion posted?

Include in the voting endpoint, the date of the vote that a person makes

barren kestrel
#

So I’ll see if it works

#

Also do you know how I can say... when a user votes, do something

violet viper
#

Hey, so my firewall blocks POST access to my bot for voting, so is there any other way to gain POST because I can't bypass the firewall of the compound where I live.

green roost
#

Don't self host ez

craggy sentinel
violet viper
#

Ok, thanks.

restive otter
#

dont selfhost webhook tbh

rain heart
#

Unless you couldn't care less about reliability

acoustic veldt
#

Can anyone explain this to me?

from discord.ext import commands

import dbl


class TopGG(commands.Cog):
    """
    This example uses dblpy's webhook system.
    In order to run the webhook, at least webhook_port must be specified (number between 1024 and 49151).
    """

    def __init__(self, bot):
        self.bot = bot
        self.token = 'dbl_token'  # set this to your DBL token
        self.dblpy = dbl.DBLClient(self.bot, self.token, webhook_path='/dblwebhook', webhook_auth='password', webhook_port=5000)

    @commands.Cog.listener()
    async def on_dbl_vote(self, data):
        """An event that is called whenever someone votes for the bot on top.gg."""
        print("Received an upvote:", "\n", data, sep="")

    @commands.Cog.listener()
    async def on_dbl_test(self, data):
        """An event that is called whenever someone tests the webhook system for your bot on top.gg."""
        print("Received a test upvote:", "\n", data, sep="")


def setup(bot):
    bot.add_cog(TopGG(bot))
#

Does the dbl handle hosting of the webhook?

rain heart
#

Read the comments

#

No it doesn't

acoustic veldt
#

So I still need a working url for callback?

rain heart
#

You need to host the webhook yourself

green roost
acoustic veldt
#

Thanks, @green roost That explains a lot, so If I leave out the webhook_path, it will be just ip/:port/?

green roost
#

No I believe the default path is /dblwebhook

#

You can manually set the path to / if you want.

plucky lance
acoustic veldt
#

@plucky lance I'm gonna make a tunnel, cause unfortunately my ISP use CGNAT, and I haven't bought a static IP so I can't open ports

#

the problem i have now is this

plucky lance
#

Well u mean DSLite that’s what the most ISPs use today

#

Even if that means you don’t have a public IPv4 you could try to enter the IPv6 on topgg and see if it supports it

#

But I expect the traffic is still sorted out

#

As long as u don’t have a business connection/contract with ur ISP - speaking about your internet connection- that may won’t change

acoustic veldt
#

I've already set everything up with ngrok

#

But can't save the url

#

Does my bot need to be approved for this?

plucky lance
#

Is it necessary to host it at home?
Isn’t there a VM/dedicated server you can use?

acoustic veldt
#

I'm developing it currently, but yeah it will be hosted so no problem there

plucky lance
#

Well your bot has to be online 24/7 to get approved because it can happen at any time.

acoustic veldt
#

Kk, thanks for the info

plucky lance
#

Regardless that fact a bot which isn’t online 24/7 doesn’t really make sense at all oldEyes

short isle
#

The api support is so bad

#

I literally get no help

night ingot
#

What's your issue?

short isle
#

I added my token but it shows N/A on my bots page

#

That's my issue

#

@night ingot

night ingot
#

Hmm, it seems correct

#

You're sure the token is right?

short isle
#

Yup

#

I even regenerated but still don't work

night ingot
#

Does it work if you remove the listener?

short isle
#

Didn't try

#

I think its required tho

night ingot
#

I don't use the listener in mine, but I don't feel like it should make a difference

short isle
#

Ight lemme try

plucky lance
#

A listener requires to be able to read incoming connections

#

Did you even add a rule in your firewall for incoming connections on your specified port?

short isle
#

Yes

plucky lance
#

Is the code n a dedicated/VM (server)?

#

huh where did my O go

short isle
#

Nope

plucky lance
#

Then at home I guess

short isle
#

Still don't work @night ingot

plucky lance
#

Testing/hosting at home is hassle

night ingot
#

Strange, and you tried leaving it on for a while? Since it only posts every 30 minutes

short isle
#

Yes

plucky lance
#

You need to make sure your ISP isn’t blocking your traffic/ports, you have an actual public IPv4, you forwarded the ports in your router etc.

short isle
#

Yes I have

plucky lance
#

If one these things isn’t setup properly you won’t be able to receive a webhook

short isle
#

I did everything correctly

night ingot
#

If you want to, you could swap to the manual way of posting server counts. That way you can see if any errors happen when it tries to post it

spark pebble
#

@plucky lance @plucky lance @plucky lance

plucky lance
#

Huh?

short isle
#

@night ingot

night ingot
#

Is that the method from the docs?

plucky lance
#

Oh you wanna post your bot stats only? Thought you wanna receive a webhook.

short isle
#

yes

vague edge
#

hello how do i do the webhook think for the upvotes i created a new one in my server copied url tried to save but it says problem while saving

short isle
plucky lance
#

Oh my bad. Than opening ports etc. isn’t required

night ingot
night ingot
#

Hm, strange

short isle
#

i tried the one from the docs before

night ingot
#

They're different

short isle
#

still didn't work

silk reef
#

Hmm how do i listen to web hooks? I am using a rasp pi 4

night ingot
silk reef
short isle
#

wut do i do abt dis?

night ingot
plucky lance
#

Setup a webhook listener (service), open up the required ports on your device and there you go
Port forwarding is required as well if you host at home as well as a public IPv4 address
(guessing IPv6 won’t be supported)

short isle
#

😔

night ingot
short isle
#

wut do i do now just wait until the api is fixed?

silk reef
#

Damn gotta expose my rasp to the internet then pandasad

plucky lance
#

Well the API works fine

night ingot
#

I guess you could keep asking and see if someone who knows would reply

plucky lance
#

I’m able to send the stats at any time

night ingot
short isle
#

i'd rather not waste my time

night ingot
#

And top.gg has a feature to add an authorization to the webhook so that you know it's from us

restive otter
silk reef
#

O didn't know abt that nice

plucky lance
#

Even if the port is opened up nobody will know which service is behind

#

And make sure to choose a port from range > 9000-65000

barren kestrel
#

@plucky lance Any idea how I could say, once a user has voted.... do something

#

Cause python has something like that

#

But js doesnt

#

Im making a lb.

plucky lance
#

well you can easy create an instance of your Discord client (bot) and send a message to the user who has voted

barren kestrel
#

Then I thought, why don't I do, once the webhook receives data, then add to the db, and that is what I'm doing with the webhook.

barren kestrel
#

I want to say

#

Once a user votes for my bot, then do something

plucky lance
#

just including djs and login the client like u're doing in your main bot

barren kestrel
#

what wdym

#

See python has that

#

Js doesnt

#

like a

#

on voting

#

or smth

cursive steppe
#

You need to setup a web server to receive post requests from topgg

barren kestrel
#

how would I do that. Thats the thing

cursive steppe
#

Use express

plucky lance
#

The webhook includes the user id

#

the py event isn't doing something else

#

you're basically getting a few informations about the vote, incl. the actual user id

vague edge
#

a

plucky lance
#

You can take that user id and send him a message or what ever you like

#

But there's no info about the guilds the user is in of course, voting at topgg does only share your Discord user id

#

If you wanna send the user a DM for example, you will need to search your bots cache or try to fetch the user and if you got a positive result, send him a message

vernal trench
#

How can i set up my dbl on python.
Because i have some code using the on_dbl_vote event.
But i have the feeling i need to mention my auth code. where i do that?

barren kestrel
#

@plucky lance It says my port is open, on that website and when I test it doesnt work

plucky lance
#

yeah I do remember that but I'm actually not sure if the issue is coming from topgg

#

I dont think so, since I can successfully receive webhooks if I'm testing it

barren kestrel
#

so then what could be wrong/

plucky lance
#

I'm not exactly sure

barren kestrel
#

my code

plucky lance
#

token

vernal trench
#

remove

plucky lance
#

cough

vernal trench
#

remove that message

#

fasat

#

people gonna pull ur token

plucky lance
#

calm down, tokens can be regen

vernal trench
#

we dont want that

barren kestrel
#

Thats not token

#

Its webhook

#

c:

plucky lance
#

yeah, webhook topgg token

barren kestrel
#

no only webhook

plucky lance
#

yeah the topgg API token

barren kestrel
#
const express = require('express')
const app = express() // Your express app
const webhook = new Topgg.Webhook(config.topggwebhookauth)

app.post('/dblwebhook', webhook.middleware(), (req, res) => {
  dwebhook.send(`<@${req.vote.user}> has voted for News Agent on top.gg!`)
});

app.listen(19555)```
plucky lance
#

even that can be abused

barren kestrel
#

No i mean that part was only a wevbhook

#

I did that right

plucky lance
#

any as I said yesterday without actual sending a webhook to YOU from EXTERNAL I can not figure the issue out

#

If you don't wanna share your public IP you need to test it yourself

#

Send a webhook from OUTSITE your network to your endpoint (public IP, port 19555 as I can see)

#

and log the result and watch what happens

#

You may will receive an error code or information on the SENDER side why the RECIPIENT can't be reached

plucky lance
#

Just send a webhook using JS, PHP etc. to your endpoint

#

But from outsite your network of course

#

I could send u one like I said but it would require to share your public IP...

#

privatly of course

barren kestrel
plucky lance
#

in PHP using cURL for example, XMLHttpRequest for JS

barren kestrel
#

ok i have no clue how to do that.....

#

Is there a way

#

to

#

Say inJS

barren kestrel
#

When a user votes, do something

#

THats all I wnt

plucky lance
#

yeah I explained that above already

barren kestrel
#

I get the english but not the code

#

I want to say

#

Once a user votes, log them into the db

#

I have the db part

plucky lance
#

Yeah receiving the webhook from topgg includes the Discord user id; you gonna save that into your DB

barren kestrel
#

SO I have to use a webhook

plucky lance
#

lemme check something

#

You don't necessary need to use the webhook

barren kestrel
#

Ye

#

I just want in plain js

#

when user votes log them into db

#

Python has something like that

plucky lance
#

You can also do an API request getting the last 1000 votes

#

The response is an array of users who vote

#
[
  {
    "username": "Xetera",
    "id": "140862798832861184",
    "avatar": "a_1241439d430def25c100dd28add2d42f"
  }
]
#

including their username and id

#

you can save this into your db

barren kestrel
#

@plucky lance Ok but how do I use that in djs

plucky lance
#

and if the id exists already update the row or ignore the insert

#

you don't need djs for it

#

that's raw JS

#

using a lib to do curl requests for you

barren kestrel
#

Ok im confused. How do I use that

#

How do I do that?

#

Lol

plucky lance
barren kestrel
#

Like this is so complicated to just get one single thing

plucky lance
#

lemme send you an example

barren kestrel
#

ok

#

Also if I host my webhook on repl, and send a test, it spams the user multiple times

#

Idk why

plucky lance
#
fetch('https://top.gg/api/bots/<bot_id>/votes', { method: "GET", headers: { "Content-Type": "application/json", "Authorization": <dbl_token> } })
    .then(res => res.json())
    .then(json => console.log(json));
#

using the node-fetch lib

barren kestrel
#

Ok. And where can I put this? I have node-fetch installed

#

in my index.js

plucky lance
barren kestrel
#

ok

plucky lance
barren kestrel
#

k

plucky lance
#

you gonna implement the code in a file which contains your DATABASE lib

#

and then save the received data in your database

barren kestrel
#

my db will be json.sqlite

plucky lance
#

sqlite not json, right?

barren kestrel
#

yes

#

json.sqlite is the db name

plucky lance
#

alright, never use json as db

barren kestrel
#

im uisng quick.db

#

ye ik

plucky lance
#

ok

barren kestrel
#

.sqlite is the extension

stuck igloo
#

i gotta keep resetting the webhook token for this to work

plucky lance
#

well then create a new project, index.js, whatever.js putting the node fetch code in it and the response you got from it will be saved in your db

barren kestrel
#

ok

plucky lance
#

all you do in your new file/project is to send a request to the API using fetch and work with the response

#

in your case, saving the user ids from the response in your db

#

since it's always viewing the last 1000 voters make sure to ignore the insert if the user id is already found in your database

#

dunno how quickdb handles that, never worked with it

barren kestrel
#

ok im doing the quickdb code rn

plucky lance
#

with the example code I provided above for example and log the process to see if you're able to receive the webhook

barren kestrel
plucky lance
#

just to test to send a webhook to you, yes

#

using JS for example

#

@barren kestrel

short isle
#

@plucky lance do yk why the server count don't work for me?

plucky lance
#

can help you out with php, js etc. but not with py, sorry

#

I don't speak snakish pandasad

#

All you have to do is to POST a stringified JSON body the topgg API incl. { "server_count": xxx }

nocturne sonnet
#

Anyone know how to add a status to a bot in discord.py

plucky lance
#

the content types need to be json and your dbl token

restive otter
#

more a question for discord.py / whatever lib you use

#

they all have discord servers for support

restive otter
#

that too

short isle
#

IT WORKED I GOT IT TO WORK

#

LETS GOOOOO

plucky lance
#

Alright, great

#

You can implement this into your bot for example, posting the server count inside the ready event

#

Adding an interval to repeat the post proccess any XXX time, for example each hour or 30 mins

#

Less doesn't really make sense; that said keep an eye on the API limits not to abuse them

short isle
#

how can i add the offline/online status of my bot on topgg

plucky lance
#

py?

short isle
#

yes

#

i dont see it in the docs

plucky lance
short isle
#

not that

#

for the topgg page

plucky lance
#

there's no status you can set on topgg

#

That's the actual status of the bot, I guess

near crypt
#

im not getting anything through when i test the webhook, do you know what i might be doing wrong?

#

the route is /topgg

#

i have it set to this on the site

#

and process.env.TOPGG is this

plucky lance
#

Hosted the webhook service at home?

cosmic thorn
#

!rang

near crypt
#

its on a vps

#

with a cname attached to it

#

the site works fine

#

im just not getting anything printed on the console

#

does it need to be hosted on port 80?

plucky lance
#

since you didn't add a port the host it has to, yes

#

requires to allow incoming connections on port 80 TCP in your firewall

near crypt
#

nvm i fixed it

#

i wasnt setting up the route correctly

#

its coming through now

plucky lance
#

alright

near crypt
#

thank you anyway :)

plucky lance
#

np

rich obsidian
#

who loves goanimate and vyond and legacy video maker (lvm clones) me yes

#

who loves goanimate and vyond and legacy video maker (lvm clones) me yes

hallow dock
#

Why does he spam when some one vote?

green mantle
#

need 2xx code responses

#

though IDEK why so many people wernt already doing that

restive otter
#

hiiii

#

i need help

#

how should i set the webhook ?

plucky lance
#

You need to run an own webhook service in your environment

#

The public address or DNS will be your topgg webhook URL

rugged veldt
#

hi does the on_dbl_vote actually works on dblpy? If it does, may I have an example of what you did?

restive otter
#

I don't see why not

restive otter
#

on_dbl_vote doesnt seem to work

#

guild post is working jsut fine

#

but in another cog the on_dbl vote does nothing when a vote is registered

#

even though it should print the data for the vote

green roost
#

Is your webhook functional?

restive otter
#

yep

#

i got rejected cus of having too much info on my np command...

green roost
#

Did you test it?

restive otter
#

yes

#

it worked

green roost
#

If the test worked, the vote should work.

restive otter
#

thats the problem

#

it isnt printing the vote data in my logs

proper pagoda
#

Hello, I would like to know if anyone has a reliable solution to be able to put APIs on shards, for example the API of top.gg, because otherwise there are the same two APIs on the same ports and the bot crashes (which makes sense)

plucky lance
#

Well you wouldn’t call it shards but the easiest way to do it is to use a load balancer to route the incoming API request to one of your instances/nodes.

#

For example multiple webservers running on the default port 80 can be the target of the load balancer

#

They need to run on different physical locations or at least on a host with multiple NICs

#

If not load balancing doesn’t make any sense at all

proper pagoda
#

Ah ok I see, thank you for your solution

agile oak
#

What's the best way of getting when a user votes for a server?

rain heart
#

using webhooks

plucky lance
#

Or calling the API if doesn’t need be a "live" event

agile oak
#

well it has to be a live event

plucky lance
#

Than what Hope said

agile oak
#

basically I want to give users a role when they vote

rain heart
#

servers doesn't have a api

#

only way of getting vote data on servers is webhooks

agile oak
#

and where can I find the docs for that?

#

I couldn't find anything about it

rain heart
agile oak
#

already checked that

#

it only says about bots

rain heart
#

there's a webhook section for servers

plucky lance
rain heart
agile oak
#

oh thanks

#

wait, can I use the java library for this?

#

or do I have to learn spring to make my own api?

#

because it says it requires me to add a bot id

#

which isn't an option for me since my bot is private (made only for my server)

rain heart
#

I don't think the current Java library has Webhook support, there's a few libraries on github specifically for webhooks

agile oak
#

oh so spring would be the best approach

#

thank you

#

regarding my second question, do I need to add a bot to top.gg to do this?

rain heart
#

for server webhooks, no

agile oak
rain heart
#

yeah something that still needs to be updated

#

but you should be able to find the settings on your server info section of your server page settings

agile oak
#

oh alright

#

thank you so much

restive gate
#

fuck u

rain heart
#

?

wraith skiff
#
import dbl
from discord.ext import commands, tasks
import asyncio
import logging

class TopGG(commands.Cog):
    """Handles interactions with the top.gg API"""

    def __init__(self, bot):
        self.bot = bot
        self.token = '' # set this to your DBL token
        self.dblpy = dbl.DBLClient(self.bot, self.token)

    # The decorator below will work only on discord.py 1.1.0+
    # In case your discord.py version is below that, you can use self.bot.loop.create_task(self.update_stats())

    @tasks.loop(minutes=5.0)
    async def update_stats(self):
        print("update")
        """This function runs every 30 minutes to automatically update your server count"""
        logger.info('Attempting to post server count')
        try:
            await self.dblpy.post_guild_count()
            logger.info('Posted server count ({})'.format(self.dblpy.guild_count()))
        except Exception as e:
            logger.exception('Failed to post server count\n{}: {}'.format(type(e).__name__, e))

        # if you are not using the tasks extension, put the line below

        await asyncio.sleep(300)

def setup(bot):
    global logger
    logger = logging.getLogger('bot')
    bot.add_cog(TopGG(bot))
#

this wont work

#

still says N/A

rain heart
#

any errors?

wraith skiff
#

no unfortunately

rain heart
#

then you most likely didn't run it, add a few debug lines

wraith skiff
#

ok

#

it doesnt print

#

nothing

#

weird

#

this api doesn't work for a lot of people

#

can I just send a https post to the api?

rain heart
#

yes

lean wolf
#

How would I include how many servers my bot is in?

rain heart
rose burrow
#

Hi i need help using webhooks

short isle
short isle
wraith skiff
sharp totem
#

Hey how to make my bot get music from YouTube

#

I mean which module helps that?

toxic copper
restive otter
#

hi

toxic copper
#

I didnt use webhooks I use this code

const client = new Discord.Client() // Your discord.js or eris client (or djs ShardingManager)
const AutoPoster = require('topgg-autoposter')

const ap = AutoPoster('Your Top.gg Token', client)

ap.on('posted', () => {
console.log('Posted stats to Top.gg!')
})

#

Oh

#

What is the meaning of shards?

restive otter
#

Hey how i can fix that ?

brittle spoke
#

using the docs

restive otter
#

How ?

dusk lake
#

I'm a bit confused on what the webhook api does?

#

Ah, okay, so when i try and test it, it says sent the test message but I never received it.

#

on my webhook

marsh cedar
#

how to check if a member voted for my bot I can't find enough information for discord.py in the docs

dusk lake
#

ah, hm lemme double check.

marsh cedar
#

I want to check if a member already voted , not only if someone votes

toxic copper
#

The server count comes up in the bot page but when I refresh the page it disappears how can I fix it

marsh cedar
#
import dbl
import discord
from discord.ext import commands, tasks

import asyncio
import logging


class TopGG(commands.Cog):
    """Handles interactions with the top.gg API"""

    def __init__(self, bot):
        self.bot = bot
        self.token = 'dbl_token' # set this to your DBL token
        self.dblpy = dbl.DBLClient(self.bot, self.token, webhook_path='/dblwebhook', webhook_auth='password', webhook_port=5000)

    # The decorator below will work only on discord.py 1.1.0+
    # In case your discord.py version is below that, you can use self.bot.loop.create_task(self.update_stats())

    @tasks.loop(minutes=30.0)
    async def update_stats(self):
        """This function runs every 30 minutes to automatically update your server count"""
        logger.info('Attempting to post server count')
        try:
            await self.dblpy.post_guild_count()
            logger.info('Posted server count ({})'.format(self.dblpy.guild_count()))
        except Exception as e:
            logger.exception('Failed to post server count\n{}: {}'.format(type(e).__name__, e))

        # if you are not using the tasks extension, put the line below

        await asyncio.sleep(1800)

    @commands.Cog.listener()
    async def on_dbl_vote(self, data):
        logger.info('Received an upvote')
        print(data)

def setup(bot):
    global logger
    logger = logging.getLogger('bot')
    bot.add_cog(TopGG(bot))

How to get which member voted in on_dbl_vote ?

brittle spoke
#

try that

#

bot would prob be better

sinful lodge
#

@Mantaro

livid blade
#

:200iq:

#

||:200iq:||

marsh cedar
jaunty plank
#

Just make a request to it

restive otter
#

hey, i have in index.js

const express = require('express')
const Topgg = require('@top-gg/sdk')
const app = express()
const webhook = new Topgg.Webhook('process.env.TOPGG')
app.post('/web', webhook.middleware(), (req, res) => {
  console.log(req.vote.user)
  bot.channels.cache.get("812602214954565672").send(`<@${req.vote.user}> has voted for me on top.gg!`)
});

app.listen(5000)
``` but idk why the bot dont log/send any message when someone votes
#

im hosting the bot with heroku

#

not my pc

#

ok

toxic copper
#

I have a doubt the server count comes up in the bot page but when I refresh the page it disappears how can I fix it

restive otter
#

in this or in the code

#

k

#

8080 didnt worked

#

but i have a question before trying 8000
my webhook url need to be like this?

#

as i host with heroku, it needs my ip in it too?

#

idk where i can find my heroku url 🙄

jaunty plank
#

Heroku has docs for it

toxic copper
#

Is the discord bots analytics thing accurate coz in that it is showing 3 votes but in my bot page it is only showing 1 vote

restive otter
#

nope searched everything and nothing about heroku url

gusty plover
#

I’m confused on how this works. Will it send when it’s voted and stuff to a discord channel?

marsh cedar
rain heart
#

Have you sent the token in your authorization header with it?

marsh cedar
#

token?

marsh cedar
#

in web browser it didn't require a token

#

in the link?

#

Ok , thanks

#

same error

rain heart
#

send your code on how you do it

dark bridge
#

How to show the number of bot servers on the site

marsh cedar
#
def uservoted(member:discord.Member):
    link = f"https://top.gg/api//bots/805030662183845919/check?userId={member.id}"
    headerstoken={"authorization":"MyTokenHere"}
    f= requests.get(link,headers=headerstoken)
    ftext=f.text
    print(ftext)
    myfile=json.loads(ftext)
    votereceived=False
    if myfile['voted']>=1:
      votereceived=True
    return votereceived
dark bridge
#

is javascript ??

sullen nymph
#

@marsh cedar if you use discord.py, use aiohttp instead of requests

#

You can bool() the voted key to work with boolean directly, but you got the gist of it

#

P.S. iirc requests has .json() method on responses

marsh cedar