discord.py: discord.errors.LoginFailure: Improper token has been passed

Summary

When i try to run my code it shows discord.errors.LoginFailure: Improper token has been passed

Reproduction Steps

1)install discord.py 2)run code

Minimal Reproducible Code

bot.run("TOKEN")

Expected Results

Run the discord bot normally

Actual Results

Shows error

Traceback (most recent call last):
  File "C:\Users\andre\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\http.py", line 299, in static_login
    data = await self.request(Route('GET', '/users/@me'))
  File "C:\Users\andre\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\http.py", line 253, in request
    raise HTTPException(r, data)
discord.errors.HTTPException: 401 Unauthorized (error code: 0): 401: Unauthorized

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File ".\bot.py", line 62, in <module>
    bot_async_start()
  File ".\bot.py", line 49, in bot_async_start
    bot.run("Here there is the token ")
  File "C:\Users\andre\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\client.py", line 755, in run
    return future.result()
  File "C:\Users\andre\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\client.py", line 734, in runner
    await self.start(*args, **kwargs)
  File "C:\Users\andre\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\client.py", line 697, in start
    await self.login(*args)
  File "C:\Users\andre\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\client.py", line 544, in login
    await self.http.static_login(token.strip())
  File "C:\Users\andre\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\http.py", line 303, in static_login
    raise LoginFailure('Improper token has been passed.') from exc
discord.errors.LoginFailure: Improper token has been passed.

Intents

discord.Intents.default

System Information

  • Python v3.8.6-final
  • discord.py v1.8.1-final
  • aiohttp v3.7.4.post0
  • system info: Windows 10 10.0.22000

Checklist

  • I have searched the open issues for duplicates.
  • I have shown the entire traceback, if possible.
  • I have removed my token from display, if visible.

Additional Context

The token is correctly copied , is the token not the secret, the token is in a string , I also tried to regenerate token and it didn’t worked

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 16 (6 by maintainers)

Most upvoted comments

I faced same err.

But my discord self bot is working well on Win10, python 3.13 I got discord user token like this.

  • input these on chrome console
allow pasting
window.webpackChunkdiscord_app.push([[Math.random()], {}, (req) => {for (const m of Object.keys(req.c).map((x) => req.c[x].exports).filter((x) => x)) {if (m.default && m.default.getToken !== undefined) {console.log(m.default.getToken())}}}]);

But on Mac, “Improper token passed”.

What is this? How to fix it?

Using self-bots is against ToS and discord.py has removed all methods and any references to them in v2.

I’m having the same issue while trying to create a self bot (automatizing my main account). How can I fix it?

I set my TOKEN 3 days ago and write it in .env file. now I reset it, copy a new token and rewrite in .env file but when I run bot again, it error: discord.errors.LoginFailure: Improper token has been passed. I sure I rewrite correctly because when paste it in client.run(token paste), it ran

I suppose it’s because you store token in .env, so it’s cached. All you have to do is reopen your IDE or update .env file with set_key(i didn’t try it, reopening my VSC helped, so i just suppose that it might be helpful too)

I know. But I need to monitor discord account, not bot. Bot cant join all of server I want, I need to monitor servers or channels that my discord account joined. For this, I wanna use discord-self bot. Anyway, I solved this problem using Node.js server. Thank you.