Discord Bot Issue

My Code

import discord
import os

client = discord.Client()

async def on_ready():
  print('We have logged in as {0.user}'.format(client))

async def on_message(message):
  if message.author == client.user:

  if message.content.startswith('$hello'):
    await message.channel.send('Hello')



data = await self.request(Route('GET', '/users/@me'))
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/http.py", line 254, 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 "main.py", line 18, in <module>
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 723, in run
    return future.result()
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 702, in runner
    await self.start(*args, **kwargs)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 665, in start
    await self.login(*args, bot=bot)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 511, in login
    await self.http.static_login(token.strip(), bot=bot)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/http.py", line 304, in static_login
    raise LoginFailure('Improper token has been passed.') from exc
discord.errors.LoginFailure: Improper token has been passed.

It is extremely difficult to help from a screenshot. Can you please post your code?

1 Like

Fixed is that better?

On the .env file ‘TOKEN’ is spelled the same as in the main? If it is, try to regenerate the token and replace it.

I have the same problem, I tried to regenerate a new token and checked all the things but it stills not work, please someone helps me

create your own topic with your code to get help

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.