#Unauthorized 401 on start after changing the bot in developer portal (new token, reinvite)

1 messages · Page 1 of 1 (latest)

stoic cliff
#

The following error appears:
hikari.errors.UnauthorizedError: Unauthorized 401: '401: Unauthorized' for https://discord.com/api/v10/gateway/bot
(full error in attachments)
All the intents are turned on in the developer portal
I have all scopes needed
I have all permisions (administrator) although i don't think it matters in this case

I really don't know what i've done wrong

The code is just:

# context: S stands for settings, it contains the token and some other stuff
bot = lb.BotApp(token=S.TOKEN,
                default_enabled_guilds=S.GUILDS,
                intents=hikari.Intents.ALL,
                banner=None,
               )

Does anyone know why this happens? Maybe i'm overlooking something...? I sometimes tend to not notice very simple mistakes.....

#

PS: @ping me if you have a solution

grizzled crag
#

are you sure your intents are all correct

#

and is the token parsed correctly

stoic cliff
#

I don't know how this happened but the token i copied and pasted exactly as it was didn't work.... after regenerating another time it worked... i should've checked that but i was 100% sure the token is correct

grizzled crag
#

might've been a problem with your token parsing

#

assuming you parsed it from a file

#

or your old token was invalidated

stoic cliff
#

I just have
settings.py

TOKEN = '...'

bot.py

import settings as S
bot = lb.BotApp(token=S.TOKEN,
                default_enabled_guilds=S.GUILDS,
                intents=hikari.Intents.ALL,
                banner=None,
               )
#

idk how it'd be invalidated but maybe i don't really know how discord internals work

#

either way it works now

grizzled crag
#

maybe you leaked it

stoic cliff
#

thanks for help

#

no

#

i didn't share it with anyone

grizzled crag
#

also you should keep your credentials in a file like .env or something

#

when you upload this code to a repository somewhere, you can just ignore the .env file

#

then you can load it as an environmental variable

stoic cliff
#

it's a brand new application the only thing i did was copy the token to settings.py

grizzled crag
#

yeah ik, i'm just suggesting some good practices

stoic cliff
#

yeah ik, i don't really use that because i find dotenvs confusing for some reason and having it just stored as a variable is fine for my application

grizzled crag
#

idk what's confusing about it lol

#

but you do you

stoic cliff
#

i'm a beginner, i like when i can just do import settings and it's working right away, no fuss with environment variables and github

grizzled crag
#

one moment or another you'll just accidentally upload your token to somewhere. that has happened to me, so if you continue on doing your way, you're going to have to remember to remove it every time you're sending the code to elsewhere

#

gl

stoic cliff
#

you have a point... althought i might just move secrets to secrets.py and hopefully remember not to send the secrets file along with other stuff