Reputation: 9
Traceback (most recent call last):
File "C:\Users\youssef\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\http.py", line 300, in static_login
data = await self.request(Route('GET', '/users/@me'))
File "C:\Users\youssef\AppData\Local\Programs\Python\Python39\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 "e:\all in one bot\cafe-musain-bot\bot.py", line 79, in <module>
client.run('OTU1NjAyMjY1NzEwOTQ0Mjc2.YjkD9g.n0Qqhng0EA63JOcxwzajjm--wi0')
File "C:\Users\youssef\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\client.py", line 723, in run
return future.result()
File "C:\Users\youssef\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\client.py", line 702, in runner
await self.start(*args, **kwargs)
File "C:\Users\youssef\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\client.py", line 665, in start
await self.login(*args, bot=bot)
File "C:\Users\youssef\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\client.py", line 511, in login
await self.http.static_login(token.strip(), bot=bot)
File "C:\Users\youssef\AppData\Local\Programs\Python\Python39\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 0x0000022765565550>
Traceback (most recent call last):
File "C:\Users\youssef\AppData\Local\Programs\Python\Python39\lib\asyncio\proactor_events.py", line 116, in __del__
self.close()
File "C:\Users\youssef\AppData\Local\Programs\Python\Python39\lib\asyncio\proactor_events.py", line 108, in close
self._loop.call_soon(self._call_connection_lost, None)
File "C:\Users\youssef\AppData\Local\Programs\Python\Python39\lib\asyncio\base_events.py", line 746, in call_soon
self._check_closed()
File "C:\Users\youssef\AppData\Local\Programs\Python\Python39\lib\asyncio\base_events.py", line 510, in _check_closed
raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed
here is the code:
import asyncio
import discord
from discord.ext import commands
import random
token = 'Token'
intents=discord.Intents.all()
client = commands.Bot(command_prefix='?')
@client.event
async def on_ready():
print("bot is ready")
the rest...
client.run(token)
i tried restting the token multiple times and checked that the token is a string nothing happens same error, tried making a new discord application guessing that the problem is in the one im already using got the same error asked in the discord.py guild no one knew how to fix it.
Upvotes: -1
Views: 1873
Reputation: 46
Here is the improved code. First make sure to create a config.py
file in your main directory containg the following:
TOKEN="Your Token"
And here is the main.py
code:
import asyncio
import discord
from discord.ext import commands
import random
from config import TOKEN
client = commands.Bot(command_prefix='?', intents=intents)
@client.event
async def on_ready():
print("bot is ready")
'''
The rest Goes Code Here
'''
client.run(TOKEN)
Upvotes: 0
Reputation: 62
Without code, it's hard to give an accurate answer, but this sounds like your bot token is incorrect.
The line of the error that suggests your token is incorrect/improper:
raise LoginFailure('Improper token has been passed.') from exc
How to ensure the bot starts correctly:
token = ''
bot.run(token) # client.run(token)
You can find your token here. You need to ensure that the token is correct - otherwise, authentication will not succeed.
Upvotes: 2