#topgg-api

1 messages ยท Page 151 of 1

restive otter
#

oh ok

#

still doesnt work

#

hmm

wide nexus
#

use this event for testing

restive otter
#
    @commands.Cog.listener()
    async def on_dbl_vote(self, data):
#

yes

wide nexus
restive otter
#

Ye, the logic is pretty simple, everytime TopGG makes a request to your server, you make a request to Discord API.

#
    @commands.Cog.listener()
    async def on_dbl_test(self, data):
        vote_data = data
        print(vote_data)
#

i have this too

#

@restive otter thx

wide nexus
#

Ooo

restive otter
#

its not working

wide nexus
#

hmm wait

#

You auth kay {self.auth}

#

check it's same as the top.gg website

restive otter
#

huh

#

it is smae

wide nexus
wide nexus
restive otter
#

so

#

im confused still

#

wait holy fuck

wide nexus
#

try to use port: 8080

restive otter
#

i think i found the error

wide nexus
#

lol

#

ok

restive otter
#

url issue

#

nvm still doesnt work

#

ffs

jaunty plank
#

doesnt repl come with https?

wide nexus
#

Yaa

#

but

restive otter
#

idk i read up they said dont use https

#

il try it!

wide nexus
#

I used http for webhook

jaunty plank
#

if you dont have https, dont. but repl has it afaik.

restive otter
#

404: not found

jaunty plank
#

thats normal

wide nexus
#

yaa it's normal

restive otter
#

oh

#

should i remove

wide nexus
restive otter
#

        logger.info("Received an upvote")
restive otter
jaunty plank
#

its working right. 404: not found is what the py lib responds with when you get request it

#

as its a webhook, your not supposed to get request it

restive otter
#

ok

jaunty plank
#

ie, its not supposed to go in your browser.

restive otter
#

8080 still doesnt work

jaunty plank
#

๐Ÿ‘€ are you not reading what im saying

restive otter
#

im confused

jaunty plank
#

this url right here is correct

restive otter
#
class TopGG(Cog):

    def __init__(self, bot):
        self.bot = bot
        self.token = os.environ.get("TOPGG_KEY")
        self.auth = os.environ.get("TOPGG_AUTH")
        self.dblpy = dbl.DBLClient(self.bot, self.token, webhook_path="/dblwebhook", webhook_auth = f"{self.auth}", webhook_port = 8080)
        self.update_stats_channel = self.bot.get_channel(828347053331185704)
        self.update_stats.start()


    @tasks.loop(minutes=30.0)
    async def update_stats(self):
        
        await self.update_stats_channel.send('Attempting to post server count on top.gg')
        try:
            await self.dblpy.post_guild_count()
            await self.update_stats_channel.send('Posted server count on top.gg ({})'.format(self.dblpy.guild_count()))
        except Exception as e:
            await self.update_stats_channel.send('Failed to post server count on top.gg\n{}: {}'.format(type(e).__name__, e))

    @commands.Cog.listener()
    async def on_dbl_test(self, data):
        vote_data = data
        print(vote_data)
jaunty plank
#

add your path on the end, put it in the webhook section

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

lmao you did a mistake @restive otter

restive otter
#

oh right

wide nexus
#

Bot

restive otter
#

omfg

wide nexus
#

caps

restive otter
#

im so dumb

#

yes it worked

#

omfg it worked ty!

wide nexus
#

๐Ÿ˜‚

restive otter
#

how do i get the data for weekend

#
w = str(data["weekend"])
#

i tried this

restive otter
#

It's isWeekend afaik

#

data["isWeekend"]

#

Also, better leave it as bool instead of casting it as str

#

As "false" is truthy

#

kk

#

Or "False", w/e you got the gist

jaunty plank
restive otter
#

It does return 405 afaik

jaunty plank
#

Not the py library

restive otter
#

Oh yeah mb, that wasn't even the webhook endpoint

tired minnow
#

Has anyone tried opening ports with Google Cloud VMs for the webhook?

#

Idk if it would even work

restive otter
#

You can make a new firewall rule that targets your vm or a network tag the vm has

restive otter
#

I meant the dashboard

tired minnow
#

Do you know what the webhook URL would look like in that scenario?

#

Oh yeah I did that but nothing was showing up in logs for me

#

Idk what I'm doing wrong tbh

#

Do I need to have the bot online for it to fire?

restive otter
#

For what to fire?

tired minnow
#

For me to receive the data

restive otter
#

You need to run a webserver

#

Allowing through the firewall doesn't do anything if there's nothing running on the port

tired minnow
#

Is apache okay

warm crystal
#

How do I make a vote mandatory command in my bot with dbd.js?

sullen nymph
#

Yes, with webhooks

#

Are you familiar with the definition of a webhook?

storm mist
#

Lol

lean wolf
#

How would I implement the authorization code into my Nginx proxy

warm crystal
warm crystal
toxic tiger
#

How can i do vote required command

#

Anyone can tell me

warm crystal
kindred swift
warm crystal
rain heart
#

post your code, explain your approach etc

kindred swift
#

UH

kindred swift
#

worked now

warm crystal
rain heart
warm crystal
#

I looked through that site a lot, but did not understand anything.

#

๐Ÿ˜ฆ

sterile crypt
#

Hello How I can Add Like The

rain heart
spice helm
warm crystal
#

Thank you. I read so what do I do now?

rain heart
#

follow the steps on there

warm crystal
#

I'm using dbd.js

#

I follow the steps

restive otter
#

<coroutine object DBLClient.get_bot_upvotes at 0x0000015653B780C0> he send me this

spice helm
#

Looks like you might need to await it @restive otter

stuck forge
#

Hmm

restive otter
wet fjord
#

how can i create

#

a

#

command like it will say how many vote we have?

rain heart
#

You can only do it once your bot is approved

#

as you need an api key

restive otter
#

@rain heart I don't know how to print the number of votes my bot has

rain heart
#

see above

restive otter
#

<coroutine object DBLClient.get_bot_upvotes at 0x0000015653B780C0>

#

this is what i get

restive otter
rain heart
#

You can only do it once your bot is approved

restive otter
#

My Bot is approved

rain heart
#

why don't you have the role then

#

ask with your main account

#

not your alt

warm crystal
jaunty plank
warm crystal
#

okey

spice helm
restive otter
#

do i have to put self.json.dumb in cog

#

dumb ๐Ÿ—ฟ

restive otter
night ingot
#

@restive otter don't spam emojis in every channel please

restive otter
#

So i've port forwarded the other router

#

But it still doesn't work

#

but

#

at least i get this now on reqbin

#

does that mean that i've port forwarded correctly?

rain heart
#

Yes, but you're requesting to nothing

#

Make sure the endpoint is correct

restive otter
#

umm

#

i think so

#

it says TL-WR841N

#

which is the model of my router

rain heart
#

?

restive otter
#

wait i think i have it confused

#

what is the endpoint?

#

is it not this?

#

ohhh

#

wait no

#

is it myipadress:5000/dblwebhook?

rain heart
#

Yes

restive otter
#

well

#

i put my ipv4 in

#

if i put my router's it doesn't even show me this

#

but for now it just shows me that

rain heart
#

You cannot make GET requests

#

meaning you can't just visit your webhook using your browser

#

or make a get request through postman

#

use reqbin to test it please

restive otter
#

i did

restive otter
#

i put the same thing in

rain heart
#

Then dblwebhook does not exist

#

check your code

restive otter
#
const express = require('express');
const Topgg = require('@top-gg/sdk');
const topgg = new Topgg.Api(topgg_id);
const app = express();
const webhook = new Topgg.Webhook(webhook_authenticator);
app.post('/dblwebhook', webhook.listener(vote =>
{
    console.log(vote);
    console.log(vote.user);
}));
app.listen(5000);
rain heart
#

now see

#

app.post

restive otter
#

yeah?

rain heart
#

means you can ONLY make post requests

#

not get

restive otter
#

what should i have put?

rain heart
#

use reqbin

#

it's visibly more easier for you

restive otter
#

ohhhh

#

yeah

#

ok i put it to post

#

and it says error 403

rain heart
#

Authorization header missing

restive otter
#

I never understood that

rain heart
#

re-read the docs please

restive otter
#

I don't know where to put this

#

I have the token

night ingot
#

That should be in the header of your request

restive otter
#

Is this the request?

night ingot
#

You don't need an auth header for vote webhooks, no

restive otter
#

i'm sorry i'm very confused

night ingot
#

that's only for when you're making a request to the API

restive otter
#

wait i just realised

#

i'm supposed to put it in reqbin

rain heart
#

You need an Authorization header for your webhook

#

You defined one

#

otherwise it would not respond with that

#

webhook_authenticator

#

Whatever is defined as that

#

is your Webhook Authorization

#

which you need to define as a Header with the request

restive otter
#

so this is the top.gg token, not the webhook authenticator?

rain heart
#

something you define yourself

#

like a password to authorize the request

#

just read what I sent

restive otter
#

does it matter which one of these three i choose?

rain heart
#

custom

#

as your authorization is just a string

restive otter
#

yes

#

ohhh

#

ook

#

now i have a new error

rain heart
#

It's a bot right

restive otter
#

yes

rain heart
#
{
"bot": "12345",
"user": "12345",
"type": "test",
"isWeekend": false,
"query": "?random=true&code=123"
}
#

wait

restive otter
#

wut

rain heart
#

use this as test data

#

use this in your request body

#

in the content

restive otter
#

ok

#

is that good?

rain heart
#

2xx meaning success

#

just responds with 204 as there's nothing to return after you made a request

#

check your console

restive otter
#

woah

#

ok this is nice

#

does that mean that the invite command should work

#

not command

#

listener

rain heart
#

?

#

the listener yes

#

now try making a test request through top.gg

scarlet cobalt
#

One message removed from a suspended account.

restive otter
#

i agree

restive otter
#

for that

abstract mothBOT
#

@scarlet cobalt

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.

scarlet cobalt
#

One message removed from a suspended account.

#

One message removed from a suspended account.

restive otter
#

wait

#

no

#

what

#

i didn't realise what that was

rain heart
#

the url you need to add is http://ip:port/dblwebhook

#

to your top.gg webhook settings

restive otter
#

i did that

#

and i tried this

#

and it failed

rain heart
#

wdym failed

#

what's the response you're getting

#

fetch is making a get request

#

just saying

restive otter
#

FetchError: request to https://ipaddress:5000/dblwebhook failed, reason: write EPROTO 25216:error:1408F10B:SSL routines:ssl3_get_record:wrong version number:c:\ws\deps\openssl\openssl\ssl\record\ssl3_record.c:332:

#

oh yeah

#

bruh

#

i can't do that can i

#

ok anyway

#

i tried what you said

#

it does this

#

and then nothing

rain heart
#

it has to be your public ip address

restive otter
#

ohhhh

#

ok

#

should i still put the :5000

rain heart
#

yes

#

that is needed

restive otter
#

ok i did it

#

and nothing

rain heart
#

Then the port isn't open or the IP not correct

restive otter
#

well i mean

#

it says webhook tested

#

is that what i need?

#

or something else?

rain heart
#

try using your public ip on reqbin

restive otter
rain heart
#

don't use the chrome extension though, as you want your webhook to work externally

restive otter
#

i tried without and it does nothing

rain heart
#

This is one of the reasons why I suggest only using webhooks on vps, as you don't have to go through the portforwarding mumbo jumbo

restive otter
#

but i did

#

i port forwarded through both routers

#

in exactly the same way as the minecraft server

#

with only port changed to 5000

#

and i gave it a pass on the firewall with inbound rules

#

for both TCP and UDP

#

is there anything else i need to do?

rain heart
#

Then I'm clueless from my end

restive otter
#

wait lemme show you

#

this is on the router i am connected to which is not connected to the internet but to the other router

#

this is on the router my router is connected to that is also connected to the internet

rain heart
#

Again I have no other clue if that doesn't work

restive otter
#

And there's no chance that something is wrong in the code?

#

it's 100% the port forwarding's fault?

plucky lance
#

Are you using your public IPv4 address as host?

restive otter
#

i am using my public ip address

#

that google gave me

#

when typing what is my ip

plucky lance
restive otter
#

ipv4

#

the same that google gave me

#

ok can someone tell me now how i could make ```py
global trophy
with open('trophy.json') as f:
trophy = json.load(f)

#

its in my main.py but i also want it for my topgg cog

plucky lance
#

Alright, that probably means your ISP is still blocking the traffic (even if your router allows port forwarding)

restive otter
#

I have a minecraft server that my friends can join to

#

Does that mean anything?

#

It isn't blocking that

#

And it's port forwarded in exactly the same way

plucky lance
#

Did you see the status is off?

restive otter
#

๐Ÿคฆโ€โ™‚๏ธ

#

it was

#

it works now

plucky lance
#

And btw. it's a TCP connection; not needed to forward UDP connections on that port

restive otter
#

i had turned it off to test

#

but then i didn't save'

#

when i turned it back on

#

oh

#

ok

#

does it matter at all?

#

i mean i know there is a difference (UDP is slower but more secure i think)

#

but will it make it slower or something

plucky lance
#

Yes, never open up protocols or ports you don't wanna open up!

restive otter
#

Oh ok

plucky lance
#

The connection will never use UDP as protocol.

restive otter
#

I'll turn it off on everything

#

ok can someone help me

plucky lance
#

It's a TCP connection.

restive otter
#

Just out of curiosity, can i ask why it's TCP and not UDP?

#

i don't know python my guy i'm on javascript

#

oh

plucky lance
#

lmao... that may be a good question for Google; instead of me copy&pasting Wikipedia lol

#

they are connection (oriented) protocols

restive otter
#

Is it normal for app.listeners() to be 0?

plucky lance
plucky lance
restive otter
#

this

#

ok it seems to be fine

#

apparently it is normal

#

thanks for all the help Aurel and Fake

plucky lance
#

The TCP connection is being started and closed if you respond, which means it may is closed already if you try to log the connection

#

But I'm not sure about that one tbh

restive otter
#

๐Ÿ‘

plucky lance
#

np, I will send u the bill

restive otter
#

you can have some military grade ink

#

if you want

next pendant
#

still getting multiple calls for votes with the new webhooks, closing each connection, and responding with 200

#

reported this error multiple times

#

devs seem not to be looking into the issue

#

for reference

#

@elfin solstice

#

Ever since you updated the webhooks, it's sending multiple calls from diff servers

elfin solstice
#

First off you are the only one complaining about it, couple of hundred people using it without any issue and that is the reason i doubt its a fault on our side

#

second off, you are using the officially lib right?

#

i bet its something on your side with versions cause they added support for it in a later patch version

#

you can just try to use express directly without that lib and see if that works

#

i would try that for now

lean wolf
#

How would I implement the authorization code into my Nginx proxy

lean wolf
#

Anyone?

next pendant
elfin solstice
#

yea cause as i said already before

#

it was broken

#

for years

#

and then i actually fixed it and people doing it wrong then had issues

#

it was just working because it was super broken on our side

#

and when i fixed it all people not following standards were getting hit

#

and fixed there stuff

next pendant
#

oo

#

I'm using klasa-dash-hooks

#

and it hasn't been updated, so I'm wondering if its any issue there

lean wolf
#

Does anyone know how to block inputs without the authorization code with Nginx?

lean wolf
#

Ok thank you for the information. I will try it out

vivid dagger
#

Does this look all correct? No errors yet, but no updated guild count to top.gg either

knotty garnet
#

you really copypasted the example didn't you?

vivid dagger
hushed reef
#

try declaring the dbl module through the on_ready() listener event. again, horrible practice but the problem is the dblpy module won't initialize the guild count, it only updates it further from here

#

there's something with 3.9+ that seems to make dblpy not want to work at all

#

@sullen nymph i believe is aware of the issue since i was sharing it with him

#

I had to tweak the source code of dblpy numerous times to get mine to work on 3.9+

vivid dagger
#

So the example is a horrible coding practice? Fstarwars

hushed reef
#

my example, yes

#

the official example is how it currently works on any python versions below 3.9

vivid dagger
#

Alright, I am using py 3.8.2

lean wolf
jaunty plank
#

so nginx sends a request to an internal server, if it gets a valid auth response back it passes the request along.

lean wolf
#

Also what would http://my_backend be?

jaunty plank
#

the internal server, the webhook server

lean wolf
#

So would I point it to the server?

jaunty plank
#

yeah, like a normal proxy pass

lean wolf
jaunty plank
#

I never have used uwsgi, but I would guess so?

lean wolf
#

I am new to this so I dont really understand

jaunty plank
#

proxy_pass https://idp.example.com/oauth/token;
seems to be the internal webserver that will be determining if the auth is correct.

proxy_set_body "token=$http_apikey&token_hint=access_token";
seems to be the format the headers should be in.

#

these are the headers your internal webserver will be responding with.

lean wolf
#

Ok, so I am going to have to make a page at /oauth/token with the token?

jaunty plank
#

yep, and that endpoint can just check if the supplied auth is valid or not.

lean wolf
#

How would I do that?

jaunty plank
#

depends on the webserver you use.

lean wolf
#

I am using flask

jaunty plank
#

I dont know flask or python

lean wolf
#

I gtg but will brb in about 30 minutes

lean wolf
lean wolf
jaunty plank
#

yep

lean wolf
#

Ok

#

I will try to figure it out

vivid dagger
hushed reef
#

IDK

toxic tiger
#

how can i do vote required command

restive otter
#

hello

#

i need an api help

#

i need a api like this

#
https://meme-api.herokuapp.com/gimme
#

but i needd indian meme api

hushed reef
arctic musk
#

how do i make it so when someone votes for my bot on top.gg my bot sends a message to a channel i picked

sullen nymph
#

The fucking ratelimiter that was used before is a shitshow that isn't even maintained KEKW

restive otter
#

I'm curious why you need another lock to lock the lock creation, what's wrong with instantiating asyncio.Lock in __init__?

sullen nymph
#

Why? No idea, but that'll be changed in a bit

#

Thanks for pointing it out

potent roost
#

my token is correct
i used @top.gg/sdk module

const DModule = require(@top.gg/sdk')
const dbl = new DModule.Api("token", client)
can anyone help

potent roost
#

is there anyone who can help

restive otter
#

you did not tell anything about what issue do you have

#

so we cant

potent roost
#

i get an error
(node:12806) UnhandledPromiseRejectionWarning: Top.GG API Error: 401 Unauthorized (You need a token for this endpoint)
@restive otter

restive otter
rain heart
#

print out your token and check if it matches the one you entered

potent roost
#

matches

#

site is giving unauthorized tokens.

rain heart
#

then you aren't passing it correctly

#

post your code and wait for someone who can help

potent roost
#

i sent it and I'm talking to you right now

#

do you have a chance to check my token?

rain heart
#

reset your token and try again then

#

maybe your token is just bad

potent roost
#

i tried many times

#

A close friend of mine also checked the token when I renewed it and it was unauthorized.

#

does anyone have the authority to control

rain heart
#

then your code is definitely wrong

#

use postman and make a manual request to post your server stats for example

potent roost
# rain heart then your code is definitely wrong
const dbl = new DModule.Api("my token") 
dbl.hasVoted(message.author.id).then(voted => {
      if(voted) {

my code

           } else {
        const embed = new Discord.MessageEmbed()
        .setColor('YELLOW')
        .setTitle(`You Must Vote To Use This Command`)
        message.channel.send(embed)
      }
  })```
rain heart
#

making a manual request works perfectly for me

#

test it using reqbin

potent roost
#

I will renew my token and try again

rain heart
#

if it doesn't work, it's top.gg's fault

#

if it does, it's your code

potent roost
#

My 20th refresh worked.

#

I will ask something, the token refresh button and the page refresh button function the same, is this normal?

rain heart
#

?

#

What token did you use?

#

where exactly did you get the token for the code

nova root
#

How do i get it to send a webhook in my server whenever a upvote or something happens on top.gg

fathom dawn
nova root
#

for it to send the webhook

#

i thought i could put my webhook in there

restive otter
nova root
#

ok

nova root
#

@restive otter so i put in the top.gg status thing

#

but i dont understand what the webhook auth would be

rain heart
#

something you create yourself

#

re-read the docs please

brittle spoke
#

@rain heart

#

@jolly hornet

jolly hornet
#

man

brittle spoke
#

kid was typing again zoomeyes

storm ledge
#

hello

jolly hornet
#

-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.

storm ledge
#

someone here

jolly hornet
storm ledge
#

thaks

restive otter
#

Is there a python library to handle votes but for servers not bots? Please dm/ping me if anyone has an answer.

rain heart
#

Not sure if the official one supports webhooks without a top.gg token

#

otherwise, don't think so

scarlet cobalt
#

One message removed from a suspended account.

#

One message removed from a suspended account.

#

One message removed from a suspended account.

rain heart
#

poor shivachinningalla

restive otter
#

lol

#

Please dm/ping me if anyone has an answer.

restive otter
#

V1 officially supports it iirc. Though, technically you can use the bot vote handler for handling server votes as it provides you the raw data, can't you?

restive otter
#

how do I create voting perks when a user votes for my bot

spice helm
mental wasp
#

9780077477394-69861658

nova root
#

Something weird is going on with my bot

nova root
#

everytime i refresh it changes the server amount number

#

but when i run a direct query with my botinfo command it shows 55 servers

restive otter
#

Good evening, stupid question but where to find my top.gg token?

spice helm
restive otter
#

I searched myself and found it on webhook settings, thx

spice helm
#

Np

supple egret
#

How do we get vote logs?

rain heart
#

by using webhooks

supple egret
rain heart
#

read the docs

restive otter
rain heart
#

best is to just check if the json has "guild" or "bot"

low quail
#

it was working fine before, it just happened today

#

and yes, i send a 200 as a result and i tested with insomnia and it works

desert bolt
restive otter
#

There isnt any

desert bolt
#

yes there is, nvm I found it

jaunty plank
#

๐Ÿ‘€ can you link to it? I dont know of any top.gg server api

desert bolt
#

Shows both bot and server upvotes

#

well upvotes, anyway lmao

restive otter
#

Thats not api tho

#

Thats a webhook

desert bolt
#

well still

#

documentation for the api

restive otter
#

Thats not a api

desert bolt
#

either way

#

still found it ๐Ÿ˜›

steady gulch
#

Hi, just wondering, how would i check who voted for the bot?

jaunty plank
steady gulch
#

hmm alright

#

um

jaunty plank
#

@keen cargo dont post links like that, thanks.

elfin anvil
#

How do i setup webhook so that i know who voted

jaunty plank
#

programming language?

elfin anvil
#

python

elfin anvil
#

Thank you

#

And what is vote credit?

jaunty plank
abstract mothBOT
#

@elfin anvil

Auction Credits

What are they?

  • If enough people vote for your bot or server per month, you have the ability to get credits that you can then use for auctions.
  • Donโ€™t know what auctions is? See here for how to apply.
  • These auction credits can be used to pay for any winning bids you may make
  • You CANNOT โ€œwithdrawโ€ them for real money

How does the System Work?

  • Each month, bot monthly votes reset
  • If you get 100 votes on your bot in the month, you can redeem $15 worth of voting credits (canโ€™t redeem till you actually get 101 votes)
  • Any vote after 100 will be worth $1 per 1000 votes (or $.001 per 1 vote)

How Can I Redeem Them?

  • At the end of the month, you will be eligible to redeem your credits (you redeem them on your bot or server's Votes page on your botโ€™s dashboard). You will have 30 days to redeem them before they expire.
  • After you redeem them, you have 31 days to use them before they expire (so you can technically stack 2 months worth)

**How can I Use them to Pay? **

  • When you pay for your winning bid, you have the option to use your credits
  • If your winning bid cost is more than the amount of credits you have, make sure to apply the credits first and then pay the rest with the supported payment providers

A more simplified, less detailed version can be found in #580510490074152961 after you get auctions access and any questions can be asked in #auctions-general.

tough ledge
sullen nymph
#

@restive otter What do you think about this? ๐Ÿ˜›

#

Considering the fact that I'm not logging anything in case an exception occurs in the autopost

restive otter
#

Pog, you should probably as well implement default autopost_error handler just like how d.py implements default command_error

sullen nymph
#

imo logging the dispatching in the module seems unnecessary with the fact that d.py logs it already

#

But default error handler sounds nice

restive otter
#

Xd, I personally never set up my logging level lower than info

sullen nymph
restive otter
#

@sullen nymph do you use a specific formatter?

sullen nymph
#

Nada

sullen nymph
restive otter
#

Something like this, I'm testing it

sullen nymph
#

Oh, I think I see where you're getting at

restive otter
#

oof, that superfluous f string doe blobweary

sullen nymph
#

Though I'm not sure how that could be applied to Client objects k3llyhmm

restive otter
#

Users can override that with @<Client>.event

sullen nymph
#

Ah

restive otter
#

@<Client>.event basically just sets the coroutine as the bot's method, so ig it works on both Client and Bot extension, lemme test it

sullen nymph
#

Makes sense

sullen nymph
#

@restive otter Any result? I'm thinking of calling client.on_autopost_error and in case that fails, rely on Bot.extra_events, else just use a default handler

restive otter
sullen nymph
#

... ya, didn't see the notification

restive otter
#

What's the odd of user setting the autopost_error event before insantiating DBLClient lmao? Cuz if they do that, it'll get replaced with the default one we provided

teal matrix
#

hey how do i know what servers my bot is onยฟ

sullen nymph
#

I usually prefer to think that whoever uses dblpy is a newbie, so anything is possible

restive otter
#

Shall I check if it exists first, the thing is it could be an arbitrary function that doesn't even take an Exception object mmulu

sullen nymph
#

It's probably better to check if it exists first lol

restive otter
#

alright, ig this suffices

sullen nymph
#

Do you think we should go with

try:
    self.bot.on_autopost_error
except AttributeError:
    self.bot.on_autopost_error = self.on_autopost_error
```?
restive otter
#

I personally prefer this if statement xd

sullen nymph
#

๐Ÿ˜‚ makes sense

solid crest
#

how does the voting webhook for servers work exactly?
so not for the bot

elfin anvil
#

i have a question too do i need a website to get webhook?

solid crest
#

no

#

you can us your own ip with an open port

spice helm
elfin anvil
#

THX

vital anvil
#

boys

#

we did it

#

I ported an entire library to full TypeScript within a night because i was so salty it didn't support the library I wanted to use

hushed reef
#

so.. new api soon? ๐Ÿ‘€

kind path
#

there's a way with the api to make a command which make able people to vote without go to the top.gg page and click the vote stuff?

#

like:

x: !vote
bot: Thanks! You voted me on top.gg

and it log the top.gg vote normally like when someone go on the site and vote a bot in the normal way

ruby kiln
#
Traceback (most recent call last):
  File "/home/pi/Desktop/BotDiscord/SmallGames/cogs/topgg servers.py", line 36, in update_stats
    await self.dblpy.post_guild_count()
  File "/usr/local/lib/python3.7/dist-packages/dbl/client.py", line 157, in post_guild_count
    await self._ensure_bot_user()
  File "/usr/local/lib/python3.7/dist-packages/dbl/client.py", line 106, in _ensure_bot_user
    await self.bot.wait_until_ready()
  File "/usr/local/lib/python3.7/dist-packages/discord/client.py", line 890, in wait_until_ready
    await self._ready.wait()
  File "/usr/lib/python3.7/asyncio/locks.py", line 293, in wait
    await fut
concurrent.futures._base.CancelledError
failed to send the server count```

got this error on one of my bots. is that normal ?
novel phoenix
#

can someone tell me a bot for reaction posts?

abstract mothBOT
#

@novel phoenix

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.

novel phoenix
#

I`m sorry

ruby kiln
# ruby kiln ```CancelledError: Traceback (most recent call last): File "/home/pi/Desktop/...

that's my code ```py
class TopGG(commands.Cog):
"""Handles interactions with the top.gg API"""

@commands.Cog.listener()
async def on_ready(self):
    print("TopGG Server cog ready !")


def __init__(self, client):
    self.bot = client
    self.token = 'my TOKEN'
    self.dblpy = dbl.DBLClient(self.bot, self.token)
    self.update_stats.start()

@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))
        print("failed to send the server count")

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

rain heart
#

regenerate the top.gg token and try again

ruby kiln
#

that's the only one bot which has this error, my 2 others bots don't have it

ruby kiln
#

but don't fix

#

why do I have this error ? Unauthorized: Unauthorized (status code: 401)

#

the token is right

rain heart
#

have you updated the token after resetting

ruby kiln
#

I refreshed the web page and the token changed again....

rain heart
#

It is a bit like discord tokens

#

they will still be valid

ruby kiln
rain heart
#

then you didn't update your token on your production or smth

ruby kiln
#

but token is right

rain heart
#

reset it again

ruby kiln
#

I just reseted it 10 times because I always have this error

#

@rain heart if you want I can send you the code (with token) in DM to see if there is an error, but it is the first time I got this

rain heart
#

try it in 5-10 minutes then

#

as you probably got ratelimited during resetting your token

cosmic pendant
#

How would I go about implementing the Top.gg Api to make a command only runnable if someone has voted for the bot?

ruby kiln
spice helm
finite sequoia
#

Quando tento usar shards, ocorre um erro no topgg-autoposter. O que devo fazer para corrigi-lo?

#

opa

#

sorry

#

language

#

languaje

#

haa

#

1 second

#

When I try to use shards, an error occurs in topgg-autoposter. What should I do to fix it?

#

now is correct

rain heart
#

Can't help without any code or without the error

delicate quiver
#

Alguรฉm com api cadsus

ruby kiln
#

still have this error since yesterday
Can anyone help me ?

Failed to post server count
Unauthorized: Unauthorized (status code: 401)
Traceback (most recent call last):
  File "/home/pi/Desktop/BotDiscord/SmallGames/cogs/topgg servers.py", line 36, in update_stats
    await self.dblpy.post_guild_count()
  File "/usr/local/lib/python3.7/dist-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.7/dist-packages/dbl/http.py", line 168, in post_guild_count
    await self.request('POST', '/bots/stats', json=payload)
  File "/usr/local/lib/python3.7/dist-packages/dbl/http.py", line 144, in request
    raise errors.Unauthorized(resp, data)
dbl.errors.Unauthorized: Unauthorized (status code: 401)

This is the right token

restive otter
ruby kiln
#

and I have it since yesterday, and only on this bot, not on my others bots

#

Sometimes I got Response 200, and sometimes 401

spice helm
#

@ruby kiln maybe it's worth using something like burpsuite to watch the request pass through?

ruby kiln
spice helm
#

Maybe some of the request is getting cut off though, probably the auth token if its 401, i had that happen to me a while back

sullen nymph
ruby kiln
sullen nymph
#

Since as I see it, HTTPException gets raised after the first iteration anyway

restive otter
#

Ig it is, the loop will only break on exception other than 429

#

And 2xx

#

Actually no lmao, 2xx will break it

sullen nymph
#

Shouldn't I handle 5xx outside of the async with then?

restive otter
#

You wanna retry on 5xx?

sullen nymph
#

I'm not sure if I want to retry at all

#

Since 429 just sleeps until ratelimit is over

restive otter
#

Oh yeah, ig the loop isn't necessary then

sullen nymph
#

ty

restive otter
#

I'll check it out again later

sullen nymph
#

Sure, no problem

restive otter
#

@sullen nymph What's the chance of it getting rate limited again even after sleeping? Like for instance, the user makes arbitrary requests without the rate limit context manager?

#

Ig _global_over isn't necessary, because it isn't even used. Isn't there supposed to be await self._global_over.wait()?

sullen nymph
#

There's no way of detecting how many requests are left until ratelimit with v0 API, hence the local ratelimiter

sullen nymph
restive otter
# sullen nymph Their fault for hitting 429 <:KEKW:727825308404940800>

Right dboatsMmlol but ig you still need to keep the loop to avoid duplicate of codes nonetheless. Maybe you can just take it down to 2 from 5 iterations instead of removing the loop, or maybe recursively call itself after sleeping? Not sure if it'd be a deadlock bloblul the latter is a terrible idea

sullen nymph
#

LMFAO no recursion ty

restive otter
#

After sleeping, you need to make a request again. So, if you remove the loop, you'll need to handle the exception again, which is just redundant duplicates ig. Ofc, you can wrap it in an inner function so that you only need to call it. But imo loop is way better lol

shut hedge
#

Hey ! I don't understand what is shard ?

rain heart
#

If you don't know what it is, just leave it empty

#

as it is a optional parameter nonetheless

shut hedge
rain heart
#

read the description of that parameter on the left

#

it contains an array of server counts of all of your shards combined

#

something like

shard 0 has 5 servers
shard 1 has 10 servers

[
 "5",
 "10"
]
shut hedge
#

Sorry I don't see ๐Ÿ‘€

rain heart
#

the description of the parameter

lean wolf
#

Does anyone know a simple way to implement the authorization codes with nginx?

#

I want a simple way because I am new to this

jaunty plank
#

Still having issues with it?

lean wolf
jaunty plank
#

Is there a reason it needs to be implemented in nginx and not your code?

lean wolf
jaunty plank
#

Yes all the auth headers are sent to your code.

lean wolf
#

Oh, how would I get them

jaunty plank
#

Your using flex right?

#

Flask

lean wolf
#

Yes

jaunty plank
lean wolf
#

Ok tysm

sullen nymph
#

request.headers.get ezpz

spice helm
#

When i used apache i had to enable some setting that allow auth codes to pass through in the config, idk if nginx has the same thing, so keep an eye on that if the auth headers don't come through

lean wolf
#

Or could I just do:

if not authorizationcode in str(headers):
  return
jaunty plank
#

@sullen nymph may be able to help more. I don't know python.

lean wolf
#

Ok

night ingot
#

Do you want to check the authorization from the webhook, or send one through a request?

lean wolf
sullen nymph
#

request.headers is a dict-like object (if not literally dict)

night ingot
#

That should be part of the data you recieve

sullen nymph
#

So use .get on request.headers

spice helm
#

I've done some flask, here's some code i use

try :
     auth = request.headers["Authorization"]
     if auth == "token" : # Validate the Authorization header, change this token to your own
         pass
     else :
         abort(403) # If the header is invalid
except KeyError :
    abort(403) # If there is no Authorization header
sullen nymph
#

or that

lean wolf
#

Ok

#

Thanks for the help

sullen nymph
#

I prefer to abort with 401 tho

lean wolf
#

Whats 401

#

Is that not found

spice helm
#

Unauthorised

lean wolf
#

Oh

spice helm
#

403 is forbidden

lean wolf
#

Wait 404 is not found

spice helm
#

Yeah

sullen nymph
#

Yeah

lean wolf
#

Thanks for the help

spice helm
#

Careful of the indents on that, i just ripped it from my example code lol

#

Np :)

lean wolf
lean wolf
spice helm
#

Yeah, i'll send the link to the gist

lean wolf
#

K

spice helm
lean wolf
#

And also can I call request.headers in a different function?

spice helm
#

Not 100% sure what you mean sorry

lean wolf
#

Or does it have to be in the Flask function

spice helm
#

Oh, if you call another function in the flask route thing?

lean wolf
#

Ya

#

Can I still get the headers in there

spice helm
#

Ah right, maybe if you passed the request object into the function aswell?

lean wolf
#

Ok I will just pass the key through it then

#

Because I have multiple pages because of multiple bot lists

#

And wanted it to be the easiest possible

sullen nymph
#

Jesus lord what are you doing

spice helm
#

Oh yeah, i have the same lol

#

It's a pain lol

sullen nymph
#

Oh dear lord have mercy on you people

lean wolf
#

I am confused

spice helm
#

Hold on, let me logon to my server and get something for you

#

Not perfect, but it works

@app.route("/top_gg", methods = ["POST"])
def top_gg():
    content = request.get_json(force=True)
    userid = content['user']
    # . . .

@app.route("/dbl", methods = ["POST"])
def dbl():
    content = request.get_json(force=True)
    userid = content['id']
    # . . .
sullen nymph
#

Why not have one route for all requests?

spice helm
#

Each webhook has a different json

lean wolf
#

Ok so one discordbotlist I got the error MissingAllowOriginHeader. And other then that it still lets it through with a wrong auth code

sullen nymph
#

I'm thinking of the wrong DBL here, disregard that

spice helm
lean wolf
#

It worked before

#

Before I added that thing

#

The auth protection

#
try:
    if auth == "Code":
        pass
    else:
        abort(403)
except KeyError:
    abort(403)
#

That is the code I put in

spice helm
#

Oh

lean wolf
#

Removed it and it worked

#

Could I try returning 403, then just return the function

spice helm
#

Maybe? I'm not sure, just best to try it

lean wolf
#

Ok

lean wolf
#

Also would abort end the function too?

#

Nvm It all works

#

Thank you for the help @spice helm

spice helm
#

Np :D

sullen nymph
#

I guess I'll simply reduce the retries to 2

#

Putting that aside, should I even use the global lock?

#

... maybe I should, yeah

#

or not since I'm using a ratelimiter

restive otter
#

The ratelimiter itself is already global, so I don't see that it's necessary

sullen nymph
#

Yeah, I guess I'll just remove it

restive otter
sullen nymph
#

Migrating from dblpy to topggpy is gonna be fun experience

restive otter
#

or pain blobweary

sullen nymph
#

Tbf not that many changes

hybrid crypt
#

end

#

doesn't work

#

refreshhed

#

:<

spice helm
#

Hmm, try going back and doing it again?

hybrid crypt
#

i did

#

but its stil the same

spice helm
#

Go to the home page of the site and try it from their? This is odd, i got an error but refreshing fixed it

hybrid crypt
#

there's no home page ._ .

spice helm
#

Did you follow the URL on the gist?

hybrid crypt
#

yesh

#

see it urself

spice helm
#

That was just an example, your not suppose to follow that

hybrid crypt
#

wha

spice helm
#

Go to the root, just the domain name

#

It says you should end up at a page like that

hybrid crypt
#

is this the site?

spice helm
#
hybrid crypt
#

;o

#

oop-

#

oof

#

my bad

spice helm
#

No worries

hybrid crypt
#

thanks ;-;

spice helm
#

Did it work?

hybrid crypt
#

yesh

#

im doing it

#

as u said in the guide

spice helm
#

Alright, super

hybrid crypt
#

wait i do have a bot

#

but

#

wait im confused

spice helm
#

Different language?

hybrid crypt
#

no

spice helm
#

Alright, what's confusing you?

hybrid crypt
#

it says

#

Sign into discordbotlist.com, go to your bot, and press Edit, scroll down and you will see a webhook section.

#

which bot ._.

#

;-;

glossy spear
#

Ez

spice helm
#

It will work with top.gg don't worry, i wrote this based on discordbotlist as an example

glossy spear
#

@spice helm is the real G

spice helm
#

Yeah, just do the same for top.gg

hybrid crypt
#

it says go to your bot

spice helm
spice helm
hybrid crypt
spice helm
#

Just paste the intergromat URL there

hybrid crypt
#

ok

#

lemme test

spice helm
#

Remember to save first

#

You might need to put an auth to save it first, put whatever

hybrid crypt
#

oh

#

ok

hybrid crypt
#

how will it know

#

which channel i have to put

spice helm
#

The guide gets to that

hybrid crypt
#

;o

#

wait so for the discord webhook

#

do i do everything again

#

brb

spice helm
#

Not as many steps for the discord webhook i think

hybrid crypt
#

Click on the right of the webhook icon, and click Add another module, search and pick HTTP, then Make a request. You will now have a blue HTTP icon linked to your webhook

#

where do i do this

spice helm
#

On the intergromat page

hybrid crypt
#

home page?

spice helm
#

No, the one with your webhook

hybrid crypt
#

;o

#

brb

#

this?

spice helm
#

That's it

hybrid crypt
#

ah

#

it works :>

#

lemme go forward

spice helm
#

Nice :D

hybrid crypt
#

how do i make the message embed

#

:o

spice helm
#

It mentions the discord webhook docs

#

Follow them

hybrid crypt
#

;o

hybrid crypt
#

cuz idk how to do it or

#

yk

#

:<

spice helm
#

I don't know how to do it sorry

hybrid crypt
#

oh ok

upper valley
#

Which module do I need to use to detect votes?

spice helm
#

I think there's a dblpy module, or something like it i'll get the link

spice helm
upper valley
#

for discord.js

spice helm
#

Oh, right

upper valley
#

...

spice helm
hybrid crypt
#

their different

spice helm
#

Hmm, did you get the data for the webhook?

hybrid crypt
#

uh?

spice helm
#

You have to click listen and then test the URL

hybrid crypt
#

yes

#

it works

#

but how do i do like, when someone votes, it mentions the user and saying "message"

spice helm
#

Try doing the listen thing again, but make sure you click ok when it's done, it might not have saved

hybrid crypt
#

listen

#

thing

spice helm
#

That button

#

The red one

hybrid crypt
#

yes

spice helm
#

Should be blue, then click it and test the webhook, and then click ok on it when you are done so it saves

hybrid crypt
#

i did

#

wait

#

what's that upvote trigger?

spice helm
#

I call it and upvote trigger because that what starts the process running

hybrid crypt
#

oh

#

its the name

#

._ ..

#

my bad

spice helm
#

Oh

#

But try the listen thing again

hybrid crypt
#

i did

#

i have the blue thing too

spice helm
#

Yes, now test the webhook

hybrid crypt
#

ok

spice helm
#

And click ok on that when the button isn't red anymore

hybrid crypt
#

k

cold root
#

umm

#

Its not responding.

#

๐Ÿ˜

#

at all

restive otter
hybrid crypt
#

when i clikc this

#

with the link

#

it doesn't respond

cold root
restive otter
cold root
spice helm
#

Not sure what you mean, plus i only have two buttons not three?

hybrid crypt
#

the work i did just now

spice helm
#

Not sure how it works, i think you need to update the webhook link and then test it but idk how with unapproved bots, try Only update i suppose?

hybrid crypt
#

it works

#

but

#

how do i do like when people vote this come with the username of the voter

#

;/

spice helm
#

Were you listening for the data so it had the red button?

hybrid crypt
#

i didn't do it like that

#

here

#

i did this

#

and then that came

spice helm
#

It doesn't work like that, you need to receive the data from top.gg to send it

hybrid crypt
#

how?

spice helm
#

Wrong image

hybrid crypt
#

what's that red lines

spice helm
#

You see how that button is red? If you look at it on your end, it should be blue, click it so its red

hybrid crypt
#

ok after that

spice helm
#

Click copy, paste it into top.gg and click update

#

Then click test, go back to the webhook, and it should be a green tick

hybrid crypt
#

ok

hybrid crypt
#

yup

#

its green

#

but the message didnt come

spice helm
#

That's right, now click ok

hybrid crypt
#

ok

#

done

#

i did

#

ok

#

:>

spice helm
#

Now go back to the HTTP thing

#

You got it?

hybrid crypt
#

ok

#

then

#

um

#

no

#

sorry

#

im bad at this

spice helm
#

Don't worry