SpectrixDev / Spectrum

A Discord bot with tons of features, written in Python, made for fun.
GNU General Public License v3.0
22 stars 11 forks source link

Discord Bot List API not working right (Unauthorized 401) #5

Closed SpectrixDev closed 6 years ago

SpectrixDev commented 6 years ago

It never works and I'm still getting errors now

Failed to post server count Unauthorized: Unauthorized (status code: 401): {"error":"Unauthorized"} Traceback (most recent call last): File "/home/Spectrix/cogs/dblUpdater.py", line 25, in update_stats await self.dblpy.post_server_count() File "/home/Spectrix/.local/lib/python3.6/site-packages/dbl/client.py", line 100, in post_server_count Unauthorized: Unauthorized (status code: 401): {"error":"Unauthorized"} await self.http.post_server_count(self.bot_id, self.guild_count(), shard_count, shard_no) File "/home/Spectrix/.local/lib/python3.6/site-packages/dbl/http.py", line 189, in post_server_count await self.request('POST', '{}/bots/{}/stats'.format(self.BASE, bot_id), json=payload) File "/home/Spectrix/.local/lib/python3.6/site-packages/dbl/http.py", line 158, in request raise Unauthorized(resp, data) dbl.errors.Unauthorized: Unauthorized (status code: 401): {"error":"Unauthorized"}

Basically, it's saying it's unauthorized, and i checked the api on github https://github.com/DiscordBotList/DBL-Python-Library/issues/5 So apparently it's a bug

Any other ways of posting to the discord bot list api that actually work?

brahmnw commented 6 years ago

probably using an outdated token tbh

ghost commented 6 years ago

o shit hello

SpectrixDev commented 6 years ago

i'd just like to confirm it's not an outdated token

samhza commented 6 years ago

Broh the dbl api won't just accidentally fuck up up your token, fix that shit. Also coding your tokens straight into the code is a bad idea cus you have to change it then change it back every single time you push to GitHub.

SpectrixDev commented 6 years ago

I know, that's why I'm changing that. I'm busy doing it all in the new branch Spectrum-main. But I'm afraid it's not a broken token. Token matches the website exactly.

brahmnw commented 6 years ago

There's a way to publish without using the dbl api. Just use aiohttp.ClientSession() to get it from the actual source.

brahmnw commented 6 years ago
import aiohttp

dbltoken = "token"
url = "https://discordbots.org/api/bots/" + bot.user.id + "/stats"
headers = {"Authorization" : dbltoken}

async def on_ready():
    payload = {"server_count"  : len(bot.servers)}
    async with aiohttp.ClientSession() as aioclient:
            await aioclient.post(url, data=payload, headers=headers)

async def on_server_join(server):
    payload = {"server_count"  : len(bot.servers)}
    async with aiohttp.ClientSession() as aioclient:
            await aioclient.post(url, data=payload, headers=headers)

async def on_server_remove(server):
    payload = {"server_count"  : len(bot.servers)}
    async with aiohttp.ClientSession() as aioclient:
            await aioclient.post(url, data=payload, headers=headers)
SpectrixDev commented 6 years ago

I'll try that soon. I've tried something similar before

SpectrixDev commented 6 years ago

Ok so after 27 days I actually tried it. Thanks.

SpectrixDev commented 6 years ago

And here's the code (I changed it to rewrite) if anyone has the same problem