#topgg-api

1 messages · Page 125 of 1

red glacier
#

i was supposed to use pip3....

#

dum dum moment

restive otter
#

yes lots of dumb dumb moments in this server

red glacier
#

Yeah haha

#

I like how getting a bit of help here is quite a lot less toxic than looking for help in discord.py, with dumb mistakes at least haha

restive otter
#

Kathleen Kennedy thought Rogue One was boring, but she produced the worst fucking star wars movies ever

red glacier
#

@restive otter

flint olive
#

why does dblpy not work for the latest version of python?, and is there an alternative?

rain heart
#

what exactly doesn't work

flint olive
#

I was told it is not compatabile

#

Only with 3.7.6 and below

#

@rain heart

sullen nymph
#

It only works with Python versions strictly below 3.9 atm

#

I'm working on adding support for it

tender furnace
#

is it possible to make the bot update the bot's description on top.gg?

rain heart
#

From a api-wise point, no

#

You could scrape the site and reverse-engineer the description-update process, but i think that's most likely not allowed

cyan wyvern
rain heart
#

@tender furnace through the test button

rain heart
#

The ip of the server your bot is hosted on

#

if heroku or repl.it, most likely the project url

tender furnace
#

im using local tho

rain heart
#

You'll need to portforward then

tender furnace
#

oh

sullen nymph
fringe cove
#

is there a way I could show how much time left for someone to revote?

cyan wyvern
sullen nymph
#

Because there's no fix for them and I never found the cause

#

Well, a workaround I have planned is to suppress that specific error but raise others

cyan wyvern
#

ok i see

#

thx

dim wren
#

hello I have a problem with the api

#

if somebody help me

sullen nymph
#

See pins

#

aka use @top-gg/sdk instead

dim wren
#

this si a module ?

#

I do npm i @top-gg/sdk

sullen nymph
#

Maybe

#

See pinned messages in this channel

dim wren
#

it still doesn't work sniff

restive otter
#

Gi

#

Hi

unkempt grove
#

Top.GG API Error: 404 Not Found ?

vapid shuttle
#

Hi, I want to make a vote log, took help of top.gg api doc, and I am Confused

    if (voted) console.log("Tonkku has voted!!!")
});
``` Over Here What is 95579865788456960
#

I have the Module dbl

rain heart
#

That is an example of checking if a specific user has voted

#

in this case, the user tonkku with the ID 95579865788456960

vapid shuttle
#

oh, so how to make like all user

rain heart
#

use webhooks instead, read the docs

vapid shuttle
#

And Youtube or Google has no Help

unique scaffold
#

does my bot need to be verified for me to get a key?

rain heart
#

yes

unique scaffold
#

oop ok

#

ty

flint olive
sullen nymph
#

Like December-early January soon

flint olive
#

This December?

sullen nymph
#

Yeah, only an assumption though

#

I bet closer to early January

flint olive
#

K thx

restive otter
#

please refresh your token

honest jungle
#

How do i post server stats?

#

I would like to use node request, not the dbl package

hot axle
#

read the api docs

#

there's an explanation on the endpoint and request body

honest jungle
hot axle
#

yeah

#

check the resources tab

#

*section

restive otter
#

hi

#

im new

#

from the stream

#

can someone help me

#

stream?

#

ye there was a streem

#

in twich

#

i dont know what do you mean

#

why did you join in this server

#

bicos there was a link in the stream

#

pityscreams

#

wrong server i guess

#

hmmmm

jaunty plank
#

so weird how this discord gets randomly linked places

jaunty plank
#

they mean webhooks as in webhooks you make with an http server.

#

top.gg webhooks are not compatible with discord webhooks.

robust path
#

My code got blocked from accessing the top.gg api, and it was working fine before

#

nothing wrong was happening, and then at 100, it randomly started saying blocked

worn silo
#

ohh

#

that's because if your bot is at 100 servers you have to verify your bot to be able to have more than 100 servers for your bot

hot axle
#

not exactly

#

the top.gg api should still work

worn silo
#

oh wait

#

ye

#

idk

#

but that may be a reason tho

hot axle
#

o

crisp tendon
#

Not at all if the bot works

dim wren
#

hello with the @top-gg/sdk module we can detect the votes of my bot like for example when someone votes ca send a message?

#

pls

wintry niche
#

how would i set up the api for votes?

#

i dont really know how to use the webhook stuff but i looked at the code examples in the python library for it

dim wren
#

I am in JavaScript

#

and in the npm library I couldn't find

wintry niche
#

I have the stats update part done but the webhook is confusing me

dusky monolith
#

is there something wrong with this?

#
  File "/home/container/bot.py", line 169, in <module>
    raise e
  File "/home/container/bot.py", line 166, in <module>
    client.load_extension(cog)
  File "/home/container/.local/lib/python3.9/site-packages/discord/ext/commands/bot.py", line 664, in load_extension
    self._load_from_module_spec(spec, name)
  File "/home/container/.local/lib/python3.9/site-packages/discord/ext/commands/bot.py", line 610, in _load_from_module_spec
    raise errors.ExtensionFailed(key, e) from e
discord.ext.commands.errors.ExtensionFailed: Extension 'cogs.topgg' raised an error: ImportError: cannot import name 'logger' from 'logging' (/usr/local/lib/python3.9/logging/__init__.py)

i get that error frequently

#

when i try to start my bot

hoary urchin
#

is it a real token?

restive otter
#

lol

dusky monolith
#

i-

hoary urchin
dusky monolith
#

regenerating

flint olive
#

what code would I put for the api if I am not using cogs?

#

I just want to paste it in my main.py file with everything else

rose yarrow
#

Uhh

#

Tf

rain heart
#

@jolly hornet

hot axle
#

should we pings mods

#

yea

red glacier
#

How can i get it so, everytime the guild count updates, it sends a message to a certain channel in my server?

#

also with a cog, how do i view it's console?

#

cause if i just do print it doesnt send it to the console the bot runs on

#

just @ me with answers pls

worn lion
#

Can I have more context

red glacier
#

@flint olive I just had to make a cog

restive otter
#
import requests

url = 'https://top.gg/bots/788330205185703967/check'

#demonstrate how to use the 'params' parameter:
x = requests.get(url, params = {"userid": 727031232243695626})

#print the response (the content of the requested file):
print(x.text)
#

showing page not found

rain heart
#

you're using the wrong url

#

re-read the docs please

tame orchid
#

Something like: dbl.postStats(totalGuilds, bot.shard.count) in a setInterval should work for posting the bots guild count and shard count right?

rain heart
#

yes

#

i mean

formal sparrow
#

Hi, I tried using @top-gg/sdk package from npm in JS, did this ```js
app.post('/dbl-webhook', webhook.middleware(), (req, _res) => {
console.log(req.vote);
});

I'm receiving the request when I click the test button in the website, it just doesn't pass the `webhook.middleware()` for some reason
#

The authorization is right, I'm pretty sure with that, it just gets rejected in the middleware function and I'm not sure why

rain heart
#

@formal sparrow you need to submit the url in order to test it

#

by pressing the save button

formal sparrow
#

I did

rain heart
#

dm me the url

#

i'll test it from my end with test data

formal sparrow
#

My test version was ```js
app.post('/dbl-webhook', () => console.log(1), webhook.middleware(), () => console.log(2), (req, _res) => {
console.log(req.vote);
});

rain heart
#

Then you aren't send a response if it doesn't do anything after that i think

formal sparrow
#

What do you mean?

#

It's supposed to log 2 after the middleware uses next function

rain heart
#

oh no clue then

formal sparrow
#

I'll just check the request and do stuff myself then

restive otter
#
import requests

url = 'https://top.gg/api/bots/788330205185703967/check'

#demonstrate how to use the 'params' parameter:
x = requests.get(url, params = {"userid": 727031232243695626})

#print the response (the content of the requested file):
print(x.text)

#

It's showing error unauthorized user

rain heart
#

you need to use your top.gg api token in the Auth header

quaint karma
rain heart
quaint karma
#

thanks

rain heart
restive otter
#

@rain heart can u just send me how to where to write it

rain heart
#

Inside the request headers, can't help you with that

formal sparrow
#

Votes resets at 2 AM EST right?

#

Basically new day in top.gg in everything is at 2 AM EST?

restive otter
#
import requests

url = 'https://top.gg/api/bots/788330205185703967/check'

#demonstrate how to use the 'params' parameter:
obj = {
  "userid" : "727031232243695626"
}

x = requests.get(url, headers={"Authentication":"xxxxx"}, params = obj)
#print the response (the content of the requested file):
print(x.text)

#

Then also same output

#

@rain heart

rain heart
#

Authorization, not Authentication

restive otter
#

Now it's showing

#

No query userid, add userid? to your request

#

@rain heart

rain heart
restive otter
#

Thx

#

Problem solved

restive otter
#

someone knows how to make dbl command
for example
!dbl 713369365294350397 and i give information about the bot in top gg

wise silo
#

!dbl 763772564962148402

#

hm

restive otter
#

anyone can help me to setup my discord bot upvote webhook?

sullen nymph
#

it should have support for the GET Bot endpoint

sullen nymph
restive otter
sullen nymph
sterile cedar
#

how to add bot server counts into top.gg

sullen nymph
#

What library?

sterile cedar
#

discord.js

sullen nymph
#

Refer to topgg-autoposter or @top-gg/sdk on npm and see which one fits your case

sterile cedar
#

wdym

sullen nymph
#

topgg-autoposter will post your bot's server count automatically every X minutes whereas with the SDK you will have to set up your own interval

sterile cedar
#

sry im kinda confuse

wintry island
#

Well, I am a noob coder...I don't know whats a library and what I needd to to!

#

I wanna add server count to my bot

#

That's it

#

py library btw

hot axle
#

well don't just say you're a noob

#

learn

sullen nymph
#

I gave you two packages that can help you post your bot's server count to top.gg and since that's done via an HTTP request in the end, you can either use an official library to do that or post it yourself with an HTTP request library

wintry island
#
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))``` 

What the heck is this huge code?
hot axle
#

a class that manages posting to the top.gg api

sterile cedar
#

im so sry

restive otter
sullen nymph
wintry island
#

uhh ok

sullen nymph
#

By default the function itself will simply exist and not run, hence why the decorator (@tasks.loop)

#

Oh, nice, it doesn't get started in that snippet

sullen nymph
#

grrrr

sterile cedar
#

sry

sullen nymph
sterile cedar
#

hmm ok

sullen nymph
#

@wintry island as for you, add self.update_status.start() in the end of the __init__ function

sterile cedar
#

type that in our coding?

sullen nymph
#

to actually start the task that will run every 30.0 minutes

sullen nymph
sterile cedar
#

snippets?

sullen nymph
#

small parts of code

hot axle
#

a snippet is a piece of code

wintry island
#

well, I actually don't code bro! My friend coded the bot for meeh and he uses py! He and me are bot owners on top.gg

#

I am learning to code currently

sterile cedar
sullen nymph
#

Yell at your friend to read dblpy's documentation then

hot axle
sterile cedar
wintry island
#

m_Rofl SPAM!?!

sterile cedar
sullen nymph
#

In the message I linked before

sterile cedar
#

const poster = AutoPoster('topggtoken', client) // your djs client/shardingmanager or eris client```
#

this?

wintry island
sterile cedar
#

@sullen nymph

dim wren
sullen nymph
#

With brand new UI presumably

dim wren
#

ok

sterile cedar
#

k

sullen nymph
#

client is supposed to be your discord.js client

#

So I believe you got it right so far

#

Just... probably put it somewhere where it actually runs

sterile cedar
#

const poster = AutoPoster("topggtoken", client) u mean this? @sullen nymph

#

the client

sullen nymph
#

Quite literally, the client variable

sterile cedar
sullen nymph
#

Bleh

#

Just try it

sterile cedar
#

i paste ```const AutoPoster = require("topgg-autoposter");

const poster = AutoPoster("topggtoken", client); // your djs client/shardingmanager or eris client

rapid kettle
#

can I see the new Discord.Client

#

That line

sterile cedar
#

me?

rapid kettle
#

Yes

sterile cedar
#

this?

sullen nymph
#

Bismillah

rapid kettle
#

no, the line where you create your client

sullen nymph
#

Where you create/initialize your discord.js client

sterile cedar
#

bruh sry lol im very confuse

rapid kettle
#

where is your discord.js client

sterile cedar
rapid kettle
#

that’ll do

#

now run the code

sterile cedar
#

put the top.gg token of my bot in const poster = AutoPoster("topggtoken", client); // your djs client/shardingmanager or eris client right?

#

i mean the ("topggtoken", client)

#

@rapid kettle

rapid kettle
#

yes

#

in the topggtoken bit

sullen nymph
#

Replace topggtoken with your bot's top.gg token

sterile cedar
sullen nymph
sterile cedar
#

oh

#

i copied and paste it but it still the same didnt showed

sullen nymph
#

Make sure there are no unnecessary spaces and wait a bit

tame orchid
#

dbl.postStats(totalGuilds, bot.shard.count) How come this doesn’t work? (Total guilds is defined as the amount of servers the bot is in)

sullen nymph
#

I highly doubt you can post shard count and server count just like that

tame orchid
#

It was working when I was just doing server count

#

But broke when I added the bot.shards.count

sullen nymph
#

Then yeah

rapid kettle
#

it’s uhh

sullen nymph
#

that ain't gonna work chief

rapid kettle
#

bot.shard.ids iirc

#

first

sullen nymph
#

You either send an array with guild counts per each shard

median river
#

Hi, so i am really struggling how to do anything and like get a webhook etc... Could anyone please help me

sullen nymph
#

or you only post the server count as an integer

rapid kettle
#

shiv that’s not true

#

wait am I being a twat again

#

fuck I am

sterile cedar
#

the bot status didn't work after coding ```const AutoPoster = require("topgg-autoposter");

const poster = AutoPoster("topggtoken", client); // your djs client/shardingmanager or eris client``` right?

sullen nymph
#

Matt I tried it multiple times when fucking around when adding official support for posting list of server counts

#

I think I poked Xetera about it in the past as well

#

trying to post server count to a specific shard ID didn't work either

rapid kettle
#

I just imagine you visiting xet irl with like one of those pokey finger sticks, going poke and running away

sullen nymph
#

Nae, it's either poke until he gets very pissed at me or nothing at all

#

(Yelling to check DMs included)

spark parcel
#
Traceback (most recent call last):
  File "/usr/src/discord-bot/app/discord_bot.py", line 203, in on_guild_join
    await self.topgg.post_guild_count()
  File "/usr/local/lib/python3.9/site-packages/dbl/client.py", line 160, in post_guild_count
    await self.http.post_guild_count(guild_count, shard_count, shard_id)
  File "/usr/local/lib/python3.9/site-packages/dbl/http.py", line 168, in post_guild_count
    await self.request('POST', '/bots/stats', json=payload)
  File "/usr/local/lib/python3.9/site-packages/dbl/http.py", line 93, in request
    async with rate_limiter:  # this works but doesn't 'save' over restart.
  File "<string>", line 6, in __aenter__
TypeError: object Lock can't be used in 'await' expression
#

Getting this error when trying to update the guild count

#

All I'm doing is

import dbl as topgg
await self.topgg.post_guild_count()
sullen nymph
#

Use Python 3.8 for now with dblpy

#

A completely new and separate release will support 3.9 and have support for multiple webhooks

restive otter
#

r u guys using discord.js?

#

i

sullen nymph
#

Not everyone here does

crystal nacelle
#

Hi I need some help with the python api, on_dbl_test()

crystal nacelle
wild sinew
sullen nymph
#

See pins

wild sinew
#

thx

final wigeon
#

Any idea on why setting the webhook on my bot, I keep getting an error?

plush falcon
#

Is there an example of checking if a user has voted on top.gg using dbl?

median badger
#

yes, read the docs

willow spindle
plush falcon
#

I need an example, like a shown code

bronze axle
#

hey

#

How can I get a token?

#

So I can use the API

median badger
#

its literally just a get request

bronze axle
#

Seriously though, how would I get the Token for my bot?

#

Not the discord token obviously

plush falcon
bronze axle
#

404

plush falcon
#

Insert your bot id instead of :botid

regal harbor
#

anyone know what is this?

[20:50:18]: [ApoBot]: TopGGAPIError [Top.GG API Error]: 404 Not Found
    at Api._request (/root/apo-bot/node_modules/@top-gg/sdk/dist/structs/Api.js:74:19)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async Util.xp (/root/apo-bot/src/Structures/Utils.js:39:15)
    at async module.exports.run (/root/apo-bot/src/Events/discord/message/message.js:16:3) {
  response: '<!DOCTYPE html>\n' +
    '<html lang="en">\n' +
    '<head>\n' +
    '<meta charset="utf-8">\n' +
    '<title>Error</title>\n' +
    '</head>\n' +
    '<body>\n' +
    '<pre>Cannot GET /api//bots/check</pre>\n' +
    '</body>\n' +
    '</html>\n'
}
toxic thorn
#

Hey guys, need some help with vote rewards implementing 😣

I guess before anything else I'll ask what does the "your.server.ip" stand for?

I put there my Aamazon Web Service instance's public IPv4, but it doesn't seem to forward the vote object to my app

toxic thorn
regal harbor
toxic thorn
#

yesyes

regal harbor
#

what service of amazon you use?

toxic thorn
#

the code snippet is also put before client.on("ready" and "message" if that could have smth to do with it?

#

it's free EC2 plan

regal harbor
restive otter
#

I wanna use the fetch method

restive otter
#

I'm blind thanks

plush falcon
#

Np

worldly saddle
#

where is docs for the vote logs thing?

#

djs

fast agate
marsh ginkgo
#

How do I want to show the number of servers that the bot has in the site?

#

What is the code ؟

cold ledge
#

@marsh ginkgo first of all what language is the bot in?

worn lion
#

..

marsh ginkgo
#

javascript

worn lion
#

Programming language

cold ledge
marsh ginkgo
#

😂

worn lion
cold ledge
#

Check the pins there's a package that will help u post it

lusty oar
#

how do they make apis?

worn lion
#

http

marsh ginkgo
#

I am an Arab and I do not know much in English @cold ledge

worn lion
#

Check pins

lusty oar
#

is it possible to make apis on a cell phone?

worn lion
lusty oar
#

where?

worn lion
#

But why would you?

regal harbor
#

$$

cold ledge
lusty oar
#

I would make apis for my bot commands

worn lion
#

But like why tho

#

That is not a reason to make an API lol

marsh ginkgo
#

@cold ledge ok
I just need how I want to appear on a site top.gg The number of server in the bot

lusty oar
#

to add do API and do special commands?

worn lion
#

Well then thats using an API yea you can do thst

cold ledge
#

@marsh ginkgo check the pinned messages in this channel, there is a npm package you can install that will help you

lusty oar
#

How am I supposed to make an API? XD

cold ledge
#

@worn lion I don't think they really know what an API actually is

lusty oar
#

APIS use Javascript?

cold ledge
#

An API can use any language

lusty oar
#

What language does bdb and bdfd use?

cold ledge
#

No idea

#

JavaScript maybe

wary lily
#

ts

cold ledge
#

Same difference

lusty oar
#

ts?

cold ledge
#

Typescript

lusty oar
#

that language use?

plucky wigeon
#

hi

#

how use the api?

regal harbor
plucky wigeon
#

the docs is very confused

#

@regal harbor

regal harbor
crisp tendon
#

"The docs is"? 😡

plucky wigeon
#

😳

lusty oar
#

Where do I find the pins and what are they?

worn lion
#

New to discord?

#

Mobile or PC?

near hill
worn silo
#

so uhh

#

with the dbl api

#

i already made a simple system so that the bot's server count updates

#

it already tells you how to do that

#

but how do you see if some specific user's id voted

#

like if someone votes

#

it does something

near hill
#

webhook

regal harbor
#

@near hill i resolve that problem using the db to not request everytime the relevant info to the dbl api

near hill
#

wat

#

oh is every 10 seconds too quick

regal harbor
#

Rate limit

near hill
#

that's how fast my bot updates it's status

#

it has like 26 different ones and most of them are inside jokes

#

what interval should I set it to (a multiple of 10 seconds preferably)

regal harbor
worn silo
#

my bot cycles through every 2 mins

#

also this is a simple question dont ask here

lusty ingot
near hill
regal harbor
#

You need to post stats every 1800000 ms

sterile cedar
#

no cant it still havent change

#

wait wrong ping

#

the server count in top.gg of the bot

#

lemme find that helper yesterday

#

@sullen nymph yeah u are here

sullen nymph
#

Show your code

sterile cedar
#

and the custom bot status didn't showed after i add this code...it works before

smoky marten
#

Is there any event for DBL like ```js
dbl.on("vote", (user) = > {
//Do the rest
});

#

Anyone ?

willow spindle
#

vote event is for webhook

smoky marten
#

so I have to use a webhook to mark a user who votes the bot

#

nvm I figured it out

willow spindle
smoky marten
#

Naaah I'm good
I'll switch when I have around 1k servers

#

BTW thank you NMWO3

sterile cedar
#

i already paste ```const AutoPoster = require('topgg-autoposter')

const poster = AutoPoster('topggtoken', client) // your djs client/shardingmanager or eris client``` this in the bot coding but why the bot server count still dindt show in top.gg website

rain heart
#

any errors?

restive otter
#

bruh

lusty ingot
#

o

rain heart
#

@sacred shell ads btw

willow spindle
#

You have all been waiting for spotlight
no, we are not

formal sparrow
#

Hi, I sent the following data

{ server_count: 3578, shard_count: 4, shard_id: 3 }

in a POST request to this URL https://top.gg/api/bots/530082442967646230/stats but somehow it doesn't work correctly, server count is being 2x as the original count, what would be the reason Thonk

bronze axle
#

Been experiencing this with the API since I started using it:

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.google.gson.internal.reflect.UnsafeReflectionAccessor
rain heart
#

Java? Or am i wrong?

#

using java 8 by any chance?

formal sparrow
rain heart
#

Remove the shard data, and see if it changes

#

iirc that posts the guild count for each shard, not sure tho

formal sparrow
#

Lemme try rq

sterile cedar
#

i cant did that

formal sparrow
#

Well, it's just sent through the API so you can send whatever server count you want but that's probably not allowed @sterile cedar

#

@rain heart Tried sending just server count

#

worked

#

But I want to send shard count too Thonk

rain heart
#

Try it without posting shard_id maybe

formal sparrow
#

Tried that, that too worked

#

Then why not with shard id

#

Well, added shard_id too and still works

#

It's like wtf

#

Doesn't work before and now works

#

Sent ```js
{ server_count: 3570, shard_count: 4, shard_id: 3 }

#

Somehow the same data works this time

dim wren
#

Hello anyone knows how to do with the new @top-gg/sdk module to make a system or when someone votes for my bot it sends a message please I can't find it.

#

(ping me in case of answers)

formal sparrow
#

Just fetch the user inside app.post (given in the example) and send them the message

formal sparrow
# sterile cedar wdym

What I meant is that you can fake the server count of your bot using the API but I don't think you're allowed to do it

sterile cedar
#

oh

dim wren
plucky lance
#

Doesn’t matter what lib you use.
You simply send a POST request to top.gg including your JSON string as data which contains the server count etc.

#

As described in the docs.

bold quiver
#

Hello, I have a problem with the api, I get her when I do the test button on my bot page: POST /votes 422 4883.061 ms - 29 code :

#
const { Router } = require('express');
const config = require('../config.json');
const Topgg = require('@top-gg/sdk');
const webhook = new Topgg.Webhook(config.bot.dbl.authorize);

module.exports.Router = class Home extends Router {
    constructor() {
        super();
        this.get('/', function(req, res) {
            res.status(200).render('votes.ejs', {
                config: req.config,
                bot: req.bot,
                user: req.user,
                is_logged: (req.isAuthenticated())
            });
        });
        this.post('/', webhook.middleware(), (req, res) => {
            
            console.log(req.vote.user) // 221221226561929217
            
        });
    };
};

module.exports.name = '/votes';
#

the configuration page dbl is check to good

toxic thorn
#

Hi guys! I noticed the server count sometimes changes to "2 servers" instead of the real number on top.gg, any ideas why? Lately I didn't see any other number than 2 at all,~~ could it be because my bot reached over 100 servers and wasn't verified yet? (I can't verify it yet because it was put as an exception for unnatural grow and allowed to continue unverified until 250 guilds)~~

EDIT: It swapped to real number again, so only why is it sometimes real number and sometimes "fixed" 2?

formal sparrow
#

@toxic thorn Do you have test bot running?

formal sparrow
toxic thorn
formal sparrow
#

You use the same API token

formal sparrow
#

That sends your test bot's server count which is why it's 2 sometimes cuz your test bot is in 2 servers @toxic thorn

formal sparrow
dim wren
formal sparrow
#

So what you're telling me is you don't know how to fetch a user and DM them or you just don't know where to put that code?

#

Well it's more like going towards #development but still kinda related to API since you wanna do that when a user votes so not sure whether what we're talking about is still not offtopic to this channel

dim wren
#

in fact I know how to send a message but I can not put it and I do not know how the API works to watch the votes of my bot @formal sparrow

formal sparrow
dim wren
#

ok

formal sparrow
#

So there req.vote.user is the ID of the user who voted, use it to fetch the user and then send them a message

dim wren
#

so I have to do: js let member= req.vote.user; member.send('somthing')

#

@formal sparrow

formal sparrow
#

You gotta fetch the user first

#

This is now definitely #development, I guess we can move there

dim wren
#

ok

#

thank

sly lintel
#

does anyone know how to put the voting API, using heroku? It's my dream

dire sand
#

I'm using the dblpy stuff, but whenever I reload the cog my dblpy thingy is in, it won't post the bot's shards/servers. Any reason why?

#

Scratch that, I think I need to use the autopost

#

That works now

sullen nymph
#

Yeah

#

Not really

#

If you use the tasks example, you need to add self.update_stats.start() at the end of init

fickle basalt
#

I wanna send guild count data to top.gg but I don't have shard system. How can I send data to top.gg?

worn silo
#

in case you dont have it

#

the console.log is optional

#

also this is really obvious but if you aren't using d.js then what i said wont work

hearty lintel
dark furnace
#
dbl.on('posted', post => {
    console.log('This api as posted ! -> ' + post);
});

//API TOP ERROR
dbl.on('error', e => {
    console.log("Error : " + e);
});

//API TOP RUNNING
dbl.webhook.on('ready', async hook => {
    console.log(`Le webhook run sur : http://${hook.hostname}:${hook.port}${hook.path}`);
});

//VOTE API FUNCTION
dbl.webhook.on('vote', async vote => {
    console.log(`User with ID ${vote.user} just voted!`);
    client.channels.cache.get('736165989204361236').send({embed: {
        color: "RANDOM",
        title: 'Thank for your vote ! \n Love you ' + vote.user + ' 🥰'
    }});
});```
#

I can do everything, it doesn't work

covert lark
#

Hey, using node-sdk, I'm getting req.vote.user is undefined, ie, req.vote is, any fixes?

hot axle
#

What is your code

covert lark
#

Uhh

#

kinda complex but

hot axle
#

Or any relevant info for this

covert lark
#

okay

hot axle
#

Like your webhook route

covert lark
#

okay okay

#
app.post('/webhooks/dbl', wh.middleware(), (req, res) => {
  console.log(req.vote.user); // of-undefined
})
hot axle
#

Does it throw an error?

covert lark
#

well yea

#

cant read user of undefined

hot axle
#

More or less what i expected

covert lark
#

0|Spencer | /root/Spencer/dist/src/routes/Hook Routes/DBLRoute.js:9
0|Spencer | await EconomySchema.increment({ User: req.vote.user }, 'Coins', req.vote.isWeekend ? 2000 : 1000);
0|Spencer | ^
0|Spencer | TypeError: Cannot read property 'user' of undefined
0|Spencer | at Object.run (/root/Spencer/dist/src/routes/Hook Routes/DBLRoute.js:9:52)

hot axle
#

Hm

covert lark
#

i also said it was erroring

#

but like sure

hot axle
#

Tbh i dont know what might be the problem

#

Since i dont use the top-gg/sdk

covert lark
hot axle
#

Maybe you need to add express.json?

covert lark
#

what is express.json

hot axle
#

A middleware that comes with express

#

To parse json bodies

covert lark
#

body-parser exists

hot axle
#

Yeah

#

Its basically the same

covert lark
#

I'll try body-parser

hot axle
#

But i just use express.json to reduce my imports

#

Like

#

Theyre the same thing so

covert lark
#

if you want the full code here

#

    public serve(): http.Server {
        const preDefinedMidllewares: Array<{ name: string; value: Middleware }> = [
            { name: 'dbl', value: this.client.dblWebhook.middleware },
        ];
        this.client.routes.map((value: Route) => {
            const middlewares: Array<Middleware> = [];
            if (value.middlewares?.length)
                value.middlewares.map((value: string) => {
                    if (preDefinedMidllewares.find((value_) => value_.name == value)) {
                        preDefinedMidllewares.find((value_) => value_.name == value).value;
                    }
                });
            this.server[value.method](
                value.path,
                ...middlewares.map((value: Middleware) => {
                    return (req: Request, res: Response, next: NextFunction) =>
                        value(req, res, next);
                }),
                (req, res, next) => value.run(this.client, req, res, next)
            );
        });

        return this.server.listen(this.client.config.webPort, () =>
            this.client.logger.success(
                `Webhook server listening on port ${this.client.config.webPort}`
            )
        );
    }````
hot axle
#

panik

covert lark
#

value(req, res, next);

#

in this case it is the .middleware function

hearty lintel
#

body-parser isnt required btw as the middleware does it itself

#

if i had to guess with your code, you're not using the middleware correctly, but i'm unsure

#

oh i see

#

@covert lark .middleware() returns a function that is the actual middleware

#

try

        { name: 'dbl', value: this.client.dblWebhook.middleware },

to

        { name: 'dbl', value: this.client.dblWebhook.middleware() },
covert lark
#

i know

#

i tried that

#

same issue

median river
#

Hi, so i am trying to log when someone votes for my bot but it does not work at all could someone please help

const Topgg = require('@top-gg/sdk')
const api = new Topgg.Api(process.env.DBL_KEY)
const webhook = new Topgg.Webhook('')
  client.on("ready", () => {
    setInterval(() => {
      api.postStats({
        serverCount: client.guilds.cache.size
      });
    }, 1800000);
  });

 app.post('/dblwebhook', webhook.middleware(), (req, res) => {
    console.log(`User with ID ${req.vote.user} just voted!`)
    //const check = client.guilds.cache.get('734018985812688987')
   // if(check.members.cache.has(req.vote.user)) {
      //const userID = req.vote.user;
      //const member = check.members.cache.get(userID)
     // member.roles.add('782380266848518155')
 //}
});
app.listen(5000)
hearty lintel
#

make sure your port is open to the internet

median river
#

Wym

hearty lintel
#

are you using a vps?

median river
#

Yes

hearty lintel
#

open the port in your firewall

median river
#

How

#

I have 0 experience sorry

hearty lintel
#

ufw enable && ufw allow 5000

median river
#

I cannot

#

But can that be any port?

hearty lintel
#

yeah

#

i recommend doing some research on firewalls and webservers

median river
#

This is a joint project my friend does the website you see can it be same port as that?

hearty lintel
#

if the app you use is shared it can yeah

median river
#

@hearty lintel But it says adress is already in use?

hearty lintel
#

then it doesnt share the same app

jaunty plank
#

because the app isnt shared.

median river
#

Damn ok, is there a way i can make it shared?

jaunty plank
#

ideally in those cases, you should host the web hook separate from the bot process within the website.

hearty lintel
# covert lark same issue

i don't really know how to help since you're using a custom codebase, and i cant really comprehend it. if you want to stick with it I recommend doing the parsing yourself, or understanding our codebase and integrating the library properly

covert lark
#

it works with all other wrappers

#

well i got an issue which was internal

#

to node-sdk

#

cannot read _parse sometihng

#

but like

#

i debugged and couldn't find what happpened

hearty lintel
#

can you show where you define .dblWebhook?

covert lark
#

sec

#

if(this.config.webPort) this.dblWebhook = new Webhook(...);

before you ask, webPort was valid

#

also i console.logged it and it was an instance of it

hearty lintel
#

yeah if you're getting requests from testing the webhook it being open shouldnt be the issue

#

you're using the test button on top.gg right?

covert lark
#

yesa

hearty lintel
#

oh

#

update the package please

covert lark
#

i did

#

its up to date

hearty lintel
#

._parse isnt used anymore

covert lark
#

yes i knwo

#

it was _parse something

#

i cant remember

#

as it was a few hours ago

hearty lintel
#

oh waaait

#

this is a this scoping issue

covert lark
#

_parseRequest

#

great

hearty lintel
#

since you're running the middleware out of context this._parseRequest doesnt exist

covert lark
#

can we just like how about move that code into the middle ware function

#

its private so it wouldnt changte anything

hearty lintel
#

that's not something im gonna do as i plan on leaving it there and using it elsewhere in the future, you can however .bind() the function with the webhook object

covert lark
#

bind the function .middleware() returns?

hearty lintel
#

yes

covert lark
#

thanks

#

happy new years

hearty lintel
#

{ name: 'dbl', value: this.client.dblWebhook.middleware().bind(this.client.dblWebhook) },

#

np, u too!

median river
#

@hearty lintel Ok, i have put them on same port and the website listens to the port anyways so that is fixed so should it work now?

#

Wait how do i know what my webhook is?

hearty lintel
#

i'd ask your friend on how to attach to their existing webserver

median river
#

Ok but is the webhook url the host:port/dblwebhook right?

hearty lintel
#

yea

median river
#

@hearty lintel I got it to work now anyways i did not have webhook setup properly

flint olive
#

What does the top.gg api do? Pls tell me

smoky marten
winter basin
#

Hey how to add server count in top.gg ?

#

Pls help me

rain heart
#

@winter basin

odd carbon
#

Hello, how do i check if user voted today, Java Library

regal harbor
#

@odd carbon

regal harbor
odd carbon
#

Yes

regal harbor
#

then this

odd carbon
#

Ok thanks anyway

#

Umm...

#

It only checks if user has voted

#

Maybe last month

#

I mean that day

regal harbor
#

i don't think the api return that data but you can track that info by yourself using a db

odd carbon
#

But, i dont see any vote event

rain heart
#

Vote event has to be done by yourself through a webhook for example

#

@odd carbon see above

odd carbon
#

Vote weebhook?

odd carbon
rain heart
#

You can use webhooks to get a request to the url you entered to get the webhook event

#

For example if a user votes, top.gg makes a request to your webhook and you can use the Data inside that request to reward the user for example

odd carbon
#

Discord Webhook?

rain heart
#

It does not work with Discord webhooks, you'll need to host a webhook for yourself

#

For example through the library i sent

odd carbon
#

I need an open port?

rain heart
#

Yup

odd carbon
#

No problem with that

#

I have 1

#

Ok thanks

upper nebula
#

Can anyone explain a way to use the API to check if a user has voted for the bot and if yes then add a role for 12 hours?

willow spindle
#

There is check endpoint

odd carbon
upper nebula
#

I got it already and vote cooldown last 12 hours THONK

minor kestrel
#

Hi, I want to add my bot to top.gg. Do I need to give them my bot token?

restive otter
#

No

minor kestrel
restive otter
#

#support

#

h

minor kestrel
#

Sorry, wrong channel. Thought I was on support.

rain heart
#

@lone comet the endpoint is botid/check with sending the userid as a parameter

lone comet
#

ah

#

thanks

flint olive
#

why does it say that?

#

unknown lib?

restive otter
#

library field is deprecated

flint olive
#

????

sullen nymph
#

The library field that bot owners used was removed but removing it from the widgets is a task of low priority

#

It's planned to be removed eventually after some other major changes

flint olive
#

i am the bot owner

#

what is the library field?

#

@sullen nymph

sullen nymph
#

It's removed

#

You can't set a bot's library

flint olive
#

?

rain heart
#

lib

flint olive
#

so why is it there?

rain heart
#

Library

sullen nymph
#

Because it used to be a thing before

#

Now it's not

flint olive
#

o

rain heart
#

Will be removed eventually

flint olive
#

can i remove it?

sullen nymph
#

hence, "removed" and not "never existed"

#

no

flint olive
#

like from the code

sullen nymph
#

What

#

The widget?

flint olive
#

The lib part in the widget

sullen nymph
#

You can't remove the lib field from the widget as it's not generated by you

#

So you'll have to wait

flint olive
#

oof

#

can I write the code for top.gg

#

ik how to make widgets

sullen nymph
#

Good luck

#

No

#

You can't apply for a full-time job just to fix one thing

flint olive
#

lol it would be easy to it would just be deleting some studd

flint olive
#

thay pay there workers?

#

someone told me they didn't

sullen nymph
#

And it's a low priority task currently as there are bigger and better changes developers are focused on

#

For developers they definitely do

flint olive
#

o

sullen nymph
#

As for moderators and bot reviewers, there's no definite "no" or "yes"

flint olive
sullen nymph
#

It will be displayed for everyone, yes. You can't set it, however

dull thicket
#

Can someone Please help me make a event for when someone votes for my bot? its in python

#

I have no clue on how to do one

sullen nymph
#

What do you have so far?

dull thicket
#

just this

#
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 = 'Im hiding this'
        self.dblpy = dbl.DBLClient(self.bot, self.token, webhook_path='111.11.111.1:8175/dblwebhook', webhook_auth='password', webhook_port=8175)

    @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))```
sullen nymph
#

Right

dull thicket
#

is their anything wrong?

sullen nymph
#

webhook_path is still poorly documented

#

it's just the route that comes after the URL

dull thicket
#

oh

sullen nymph
#

aka ip:port/webhook_path

dull thicket
#

webhook_path='111.11.111.1:8175/dblwebhook'

sullen nymph
#

/dblwebhook

dull thicket
#

I have my IP for my server

#

and a port

#

their

sullen nymph
#

Remove anything that's not /dblwebhook

dull thicket
#

?

sullen nymph
dull thicket
#

so I have to have http://?

sullen nymph
#

Are you okay

dull thicket
#

um

#

im kinda dumb

sullen nymph
#

If you plan on using ip:port/dblwebhook as your URL, set webhook_path to /dblwebhook

dull thicket
#

as my url?

#

can you please explain further im confsued

sullen nymph
#

as the link to your webserver

dull thicket
#

self.dblpy = dbl.DBLClient(self.bot, self.token, webhook_path='111.11.111.1:8175/dblwebhook', webhook_auth='password', webhook_port=8175)

#

so this..

rain heart
dull thicket
rain heart
#

Would work, yeah

sullen nymph
#

hq[weoiwoqriwer

#

not in webhook_path

#

please

dull thicket
#

please

#

im confused

sullen nymph
#

just

#

set webhook_path to /dblwebhook

dull thicket
#

uh

sullen nymph
#

give me a second

dull thicket
#

okay...

restive otter
#
"pain."
dull thicket
#

ahhhh

#

im really confsued

#

so...

#

this is right?

#

self.dblpy = dbl.DBLClient(self.bot, self.token, webhook_path='/dblwebhook', webhook_auth='password', webhook_port=8175

sullen nymph
dull thicket
#

ah

hot axle
#

Grafic desing

dull thicket
#

so that...

#

righttttt...

sullen nymph
#

webhook_path="/dblwebhook"

#

do this

#

yes

dull thicket
#

bruh

#

what

#

so I have this...

sullen nymph
#

Fuck all of that

dull thicket
#

IM CONFUSED

dull thicket
sullen nymph
#

You got your IP and port, you enter them on top.gg

#

yes

dull thicket
#

HUH

#

WHERE

sullen nymph
#

yes

dull thicket
#

so

dull thicket
sullen nymph
#

http://ip:port/dblwebhook go there

#

edit ip and port obviously

dull thicket
#

okie

#

pls work

sullen nymph
#

also

#

Authorization will be password for you as you did webhook_auth="password"

dull thicket
#

oh ok

#

so what about this?

#

webhook_port=8175

#

like is my port correct?

sullen nymph
#

If you have it open on your hosting, yes

dull thicket
sullen nymph
dull thicket
#

what does it mean by that

dull thicket
sullen nymph
#

Nothing you need to know right now

dull thicket
#

im gonna try hope it works

#

IT WORKS!!!!!!!!

#

@sullen nymph

#

wait

#

your the AUTHOR

#

of the libary?

sullen nymph
#

Yes

dull thicket
#

cool

#

wait

#

would this still work

#

if I had my thing running on my pc?

#

instead of the host

#

no right

sullen nymph
#

You would have to forward ports and open ports in your router's settings

#

That aside, sure

dull thicket
#

oh ok

#

im just gonna use this lol

sullen nymph
#

The webhook is just a listener for HTTP requests

dull thicket
#

im not gonna mess with my router

sullen nymph
dull thicket
#

what that means

#

but

#

it works

#

and I still dont understand

#

yay

sullen nymph
#

Then yeah, good idea to keep everything as it is

dull thicket
#

XD

#

thank you so much

#

for helping

#

❤️

sullen nymph
#

You're welcome

dull thicket
#

01.01 12:33:53 [Bot] {'bot': '762361400903204925', 'user': '618209006837825547', 'type': 'upvote', 'query': '', 'isWeekend': True}

#

soo

#

thats cool

carmine pilot
#

is there a way i can get the server api?

#

okay thanks

restive otter
#

Quick question. What does the API do? Does it allow me to check if someone has voted, they unlock a privelige?

hot axle
#

Yeah, you can use it for that

restive otter
#

k

exotic escarp
#

Can i have a vote tracking system for my bot that will track a server votes ?

jaunty plank
#

you can use the top.gg webhooks to make whatever you want.

dull thicket
#

@sullen nymph

#

umj

#

can you help me again..

#

Im getting this error

sullen nymph
#

error error go away never come again any other day

dull thicket
#

01.01 13:16:07 [Bot] OSError: [Errno 98] error while attempting to bind on address ('ip'', 8175): address already in use

sullen nymph
#

Webhook is already running on that port

dull thicket
sullen nymph
#

Only one thingy wingy can be running on one port, meaning that two webhooks can't run on the same port

#

Are you reloading the TopGG cog?

dull thicket
#

yea

#

is that y?

#

do I need to resert the entire bot?

sullen nymph
#

You'd need to use discord.py's cog_unload event and use .close on the webhook

dull thicket
#

How do I .close it

#

will it close auto if I resetart the entire bot or no

sullen nymph
#

Actually, hold on

dull thicket
#

ok

#

@sullen nymph can I or no lol

#

im trying to make it send a DM to who ever voted

sullen nymph
#

In the event, do something like self.dblpy.loop.run_until_complete(self.dblpy.close())

uncut granite
#

Does someone know how to setup the API for Discord.Py?

white trellis
#

Does the large widget automatically update?

#

like if i used the html code topgg generates for me on my bots website, will the widget also update on my bots website?

lusty oar
#

How do I create an API for BDFD?

jaunty plank
#

dont think bdfd allows you to create an api

jaunty plank
#

oh its absolutely what he means, but not at all what he asked 🤷‍♂️.
awhile back i decided its better to answer the question asked rather than trying to figure out what they mean.

restive otter
#

Guys how to Make an API call to the bot
Discord.js ??

fast valve
uncut kelp
restive otter
#

Hi, I'm having problems receiving votes. I'm not sure why cuz i think i have done everything correctly. 🤔 Here is my code: https://sourceb.in/kkT91LiZcX (its just for testing). And dbl's webhook ready event is also fired with this output:

#

But when i press the test button nothing happens

rain heart
#

You need to save the webhook url on your bot page before being able to test it

#

by submitting it

restive otter
#

the save button?

rain heart
#

As if you would submit an edit

#

oh wait

restive otter
#

Idk, i saved multiple times and tried re-running the bot nothing worked

rain heart
#

nah press save

#

test it using postman then

restive otter
#

postman?

#

What is that

rain heart
#

With any request client

#

Any api request client

restive otter
#

hmm ok

regal harbor
#

try to not request things so fast

uncut kelp
#

may i need to increase 1 day interval

regal harbor
#

I thing is a server error but try to set it to 30mins it solved for me

sullen nymph
#

How do "404" and "Internal Server Error" make you think "ratelimits"

wintry canopy
#

how can i make when some one vote the bot on top gg the bot send a message with the name of voter

rain heart
wintry canopy
#

from where i can get this

#

when i use this command

dbl.webhook.on('ready', hook => {
  console.log(`Webhook running at http://${hook.hostname}:${hook.port}${hook.path}`);
});```
rain heart
#

that's the ip of your server

wintry canopy
#

it just give me 0.0.0.0

rain heart
#

You need to get the external ip of your server your bot is hosted on

wintry canopy
#

if my bot hosted on glitch or ripl it?

rain heart
#

the project url i think

#

not sure

wintry canopy
#

if my bot on vps how can i get the ip @rain heart

rain heart
#

it should be the ip of your vps then

#

The one you use to connect to ssh with

wintry canopy
#

ok thanks

kindred walrus
#

I need some help with the new library webhook

#

both ports are open, the only difference is which port each library is using

#

theres no trigger on the new lib

kindred walrus
#

Found a bug, already reported/commited

#

@wintry canopy ask here

wintry canopy
#

@rain heart

glossy berry
#

Hi i have an error how i can fix that?

#

dbl.webhook.on('vote', vote => {
^

TypeError: Cannot read property 'on' of undefined

wraith raptor
#

Can someone help me with webhooks?

flint olive
rain heart
#

In any channel you could've posted this, you decide to post it inside a channel dedicated to the top.gg api

wraith raptor
rain heart
#

More input

#

what library

#

what are you trying to achieve

#

what language

wraith raptor
#

discord.py, I want it to send a message when someone votes, English.

wraith raptor
#

Where is that?

modest oar
wraith raptor
#

This is all I could find for tracking votes and it doesn't seem to have anything to do with webhooks

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

where do you want to send the message?

wraith raptor
#

In a channel in the support server

modest oar
#

so basically

#

you see the init right?

wraith raptor
#

Yes

modest oar
#

go onto your bot

#

and go to edit and webhooks

wraith raptor
#

Ok

#

It's just this https://web.hook/andromeda

modest oar
#

In webhook url?

wraith raptor
#

Yes

modest oar
#

There must stand http://IP:Port/dblwebhook

#

In IP the IP Adress your machine is getting hosted on

#

and Port I've put the port of my hoster

wraith raptor
#

How do I get the IP adress?

modest oar
#

Are you doing a localhost?

#

just google up whatsmyip or something

wraith raptor
#

Ok

#

I have it

modest oar
#

alr

wraith raptor
#

What do I do with it?

modest oar
#

Just put it in webhook url

#

then in Authorization put a password of your choice

wraith raptor
#

Ok

#

Do I put just the ip in the webhook url?

modest oar
#

No

#

as i said

#

http://IP:Port/dblwebhook

wraith raptor
#

Ok