Ошибка в коде дискорд бота
Не могу понять, где ошибся. Бот должен брать информацию с rotten tomatoes и выводить по названию фильма в чат. Сам код:
import os
from datetime import datetime
from datetime import timedelta
import aiohttp
import discord
from discord.ext import commands
from pretty_help import PrettyHelp
TOKEN = '--'
intents = discord.Intents.all()
class YourBot(commands.Bot):
def __init__(self):
self.description = "Отличный бот для поиска информации о фильмах"
super().__init__(
command_prefix={"rt."},
owner_ids={'--'},
intents=discord.Intents.all(),
help_command=PrettyHelp(),
description=self.description,
case_insensitive=True,
start_time=datetime.utcnow(),
)
async def on_connnect(self):
self.session = aiohttp.ClientSession(loop=self.loop)
cT = datetime.now() + timedelta(
hours=5, minutes=30
) # GMT+05:30 is Our TimeZone So.
print(
f"[ Log ] {self.user} Connected at {cT.hour}:{cT.minute}:{cT.second} / {cT.day}-{cT.month}-{cT.year}"
)
async def on_ready(self):
cT = datetime.now() + timedelta(
hours=5, minutes=30
) # GMT+05:30 is Our TimeZone So.
print(
f"[ Log ] {self.user} Ready at {cT.hour}:{cT.minute}:{cT.second} / {cT.day}-{cT.month}-{cT.year}"
)
print(f"[ Log ] GateWay WebSocket Latency: {self.latency * 1000:.1f} ms")
bot = YourBot()
@bot.command(hidden=True)
@commands.is_owner()
async def load(ctx, extension):
bot.load_extension(f"cogs.{extension}")
await ctx.send("Done")
@bot.command(hidden=True)
@commands.is_owner()
async def unload(ctx, extension):
bot.unload_extension(f"cogs.{extension}")
await ctx.send("Done")
@bot.command(hidden=True)
@commands.is_owner()
async def reload(ctx, extension):
bot.unload_extension(f"cogs.{extension}")
bot.load_extension(f"cogs.{extension}")
await ctx.send("Done")
for filename in os.listdir("Cogs"):
if filename.endswith(".py"):
bot.load_extension(f"Cogs.{filename[:-3]}")
print('Loaded', filename[:-3])
bot.loop.run_until_complete(bot.run(TOKEN))
Ошибка:
Loaded Commands
Traceback (most recent call last):
File "C:\Users\bvasi\PycharmProjects\pythonProject4\venv\lib\site-packages\discord\http.py", line 300, in static_login
data = await self.request(Route('GET', '/users/@me'))
File "C:\Users\bvasi\PycharmProjects\pythonProject4\venv\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 "C:\Users\bvasi\PycharmProjects\pythonProject4\main.py", line 81, in <module>
bot.loop.run_until_complete(bot.run(TOKEN))
File "C:\Users\bvasi\PycharmProjects\pythonProject4\venv\lib\site-packages\discord\client.py", line 723, in run
return future.result()
File "C:\Users\bvasi\PycharmProjects\pythonProject4\venv\lib\site-packages\discord\client.py", line 702, in runner
await self.start(*args, **kwargs)
File "C:\Users\bvasi\PycharmProjects\pythonProject4\venv\lib\site-packages\discord\client.py", line 665, in start
await self.login(*args, bot=bot)
File "C:\Users\bvasi\PycharmProjects\pythonProject4\venv\lib\site-packages\discord\client.py", line 511, in login
await self.http.static_login(token.strip(), bot=bot)
File "C:\Users\bvasi\PycharmProjects\pythonProject4\venv\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 0x0000019FDEF19EA0>
Traceback (most recent call last):
File "C:\Users\bvasi\AppData\Local\Programs\Python\Python310\lib\asyncio\proactor_events.py", line 116, in __del__
self.close()
File "C:\Users\bvasi\AppData\Local\Programs\Python\Python310\lib\asyncio\proactor_events.py", line 108, in close
self._loop.call_soon(self._call_connection_lost, None)
File "C:\Users\bvasi\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 750, in call_soon
self._check_closed()
File "C:\Users\bvasi\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 515, in _check_closed
raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed
Process finished with exit code 1