noname
noname

Reputation: 1

Discord bot not running and event loop

Sorry for using a translator because I'm Korean.

My Code

from discord.ext import commands

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

@client.command()
async def hello(ctx):
    await ctx.send('Hello')

client.run('token')

I'm trying to learn the Discord bot, but I can't do it because of this error. Is there any solution?

Error

PS D:\FrostCatDiscord> & C:/Users/user/AppData/Local/Programs/Python/Python38/python.exe d:/FrostCatDiscord/Bot.py
Traceback (most recent call last):
  File "C:\Users\user\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\http.py", line 300, in static_login
    data = await self.request(Route('GET', '/users/@me'))
  File "C:\Users\user\AppData\Local\Programs\Python\Python38\lib\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 "d:/FrostCatDiscord/Bot.py", line 10, in <module>
    client.run('token')
  File "C:\Users\user\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\client.py", line 723, in run
    return future.result()
  File "C:\Users\user\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\client.py", line 702, in runner
    await self.start(*args, **kwargs)
  File "C:\Users\user\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\client.py", line 665, in start
    await self.login(*args, bot=bot)
  File "C:\Users\user\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\client.py", line 511, in login
    await self.http.static_login(token.strip(), bot=bot)
  File "C:\Users\user\AppData\Local\Programs\Python\Python38\lib\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.
Exception ignored in: <function _ProactorBasePipeTransport.__del__ at 0x000001E954830550>
Traceback (most recent call last):
  File "C:\Users\user\AppData\Local\Programs\Python\Python38\lib\asyncio\proactor_events.py", line 116, in __del__
    self.close()
  File "C:\Users\user\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\user\AppData\Local\Programs\Python\Python38\lib\asyncio\base_events.py", line 719, in call_soon
    self._check_closed()
  File "C:\Users\user\AppData\Local\Programs\Python\Python38\lib\asyncio\base_events.py", line 508, in _check_closed
    raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed

I'm using Visual Studio Code. I'm not sure why this error occurs. Is it a code error?

Upvotes: 0

Views: 96

Answers (2)

Fishball Nooodles
Fishball Nooodles

Reputation: 511

Firstly, make sure you are not posting the real token because that is as good as putting your password.

Even if this was the exact code you ran the token you used seems to be wrong. Ensure at the portal, you go to Bot and Copy token. Not Application ID

client.run("<your token>")

Upvotes: 0

kinshukdua
kinshukdua

Reputation: 2004

The error says discord.errors.LoginFailure: Improper token has been passed.

You probably passed the wrong token in

client.run('8KzdqZna4f2aI7vCsJefdNEKw3Q3n8E8')

Also I suggest you to not paste your private token on a public forum.

Upvotes: 1

Related Questions