'discord bot: client.start(Token) not working

trying to run a discord bot

this is the code

import discord
from discord.ext import commands

TOKEN: str = "Token"

client = commands.Bot(command_prefix = '.')

@client.event
async def on_ready():
    print('Connected')

client.start(TOKEN)

I get this error:

C:\Users\josep\AppData\Local\Programs\Python\Python38\python.exe C:/Users/josep/Desktop/unsettler/unsettler.py
C:/Users/josep/Desktop/unsettler/unsettler.py:12: RuntimeWarning: coroutine 'Client.start' was never awaited
  client.start(TOKEN)
RuntimeWarning: Enable tracemalloc to get the object allocation traceback

I tried using client.run instead of client.start, but it triggers more errors. How do I fix this?

edit: the errors I got from client run:

Traceback (most recent call last):
  File "C:\Users\josep\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\http.py", line 291, in static_login
    data = await self.request(Route('GET', '/users/@me'))
  File "C:\Users\josep\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\http.py", line 245, 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 "C:/Users/josep/Desktop/unsettler/unsettler.py", line 12, in <module>
    client.run(TOKEN)
  File "C:\Users\josep\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\client.py", line 708, in run
    return future.result()
  File "C:\Users\josep\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\client.py", line 687, in runner
    await self.start(*args, **kwargs)
  File "C:\Users\josep\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\client.py", line 650, in start
    await self.login(*args, bot=bot)
  File "C:\Users\josep\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\client.py", line 499, in login
    await self.http.static_login(token.strip(), bot=bot)
  File "C:\Users\josep\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\http.py", line 295, in static_login
    raise LoginFailure('Improper token has been passed.') from exc
discord.errors.LoginFailure: Improper token has been passed.
Exception ignored in: <function _ProactorBasePipeTransport.__del__ at 0x00000216FCD9FDC0>
Traceback (most recent call last):
  File "C:\Users\josep\AppData\Local\Programs\Python\Python38\lib\asyncio\proactor_events.py", line 116, in __del__
    self.close()
  File "C:\Users\josep\AppData\Local\Programs\Python\Python38\lib\asyncio\proactor_events.py", line 108, in close
    self._loop.call_soon(self._call_connection_lost, None)
  File "C:\Users\josep\AppData\Local\Programs\Python\Python38\lib\asyncio\base_events.py", line 711, in call_soon
    self._check_closed()
  File "C:\Users\josep\AppData\Local\Programs\Python\Python38\lib\asyncio\base_events.py", line 504, in _check_closed
    raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed


Solution 1:[1]

According to the traceback for client.run, the RuntimeError at the bottom was derived from this exception:

LoginFailure('Improper token has been passed.')

Essentially, check that you copied the correct token into the TOKEN variable. When you go to the developer portal and click on your application, make sure that you copy the bot token (you will find it in the Bot tab on the left) and not the client secret or client ID.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 thegamecracks