Olá, estava tentando criar um bot para discord para treinar meus conhecimentos de NLP
em uma interação com usuários reais. Como tudo tem um começo estava escrevendo as primeiras linhas de código quando me deparei com esse erro:
C:\Python38\python.exe C:/Users/evers/PycharmProjects/ValForDiscord/main.py
Traceback (most recent call last):
File "C:\Python38\lib\site-packages\discord\http.py", line 291, in static_login
data = await self.request(Route('GET', '/users/@me'))
File "C:\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/evers/PycharmProjects/ValForDiscord/main.py", line 15, in <module>
client.run(TOKEN)
File "C:\Python38\lib\site-packages\discord\client.py", line 708, in run
return future.result()
File "C:\Python38\lib\site-packages\discord\client.py", line 687, in runner
await self.start(*args, **kwargs)
File "C:\Python38\lib\site-packages\discord\client.py", line 650, in start
await self.login(*args, bot=bot)
File "C:\Python38\lib\site-packages\discord\client.py", line 499, in login
await self.http.static_login(token.strip(), bot=bot)
File "C:\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 0x000001DFD2C5F4C0>
Traceback (most recent call last):
File "C:\Python38\lib\asyncio\proactor_events.py", line 116, in __del__
self.close()
File "C:\Python38\lib\asyncio\proactor_events.py", line 108, in close
self._loop.call_soon(self._call_connection_lost, None)
File "C:\Python38\lib\asyncio\base_events.py", line 719, in call_soon
self._check_closed()
File "C:\Python38\lib\asyncio\base_events.py", line 508, in _check_closed
raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed
Meu código está assim:
import os
import discord
from dotenv import load_dotenv
load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')
client = discord.Client()
@client.event
async def on_ready():
print(f'{client.user} has connected to Discord!')
client.run(TOKEN)
Verifiquei e o Token estava correto. Ao pesquisar no Stack Overflow, descobri que o problema seria no async
, mas como não tenho nenhum conhecimento nesse elemento da linguagem, não consegui resolver meu problema. Alguém poderia me explicar o que aconteceu e como eu poderia resolver?