I'm using discord.py v0.16.12, and I occasionally get this traceback that crashes the bot. The token is present and valid even though the traceback leads you to believe otherwise.
Traceback (most recent call last):
File "main.py", line 94, in <module>
bot.run(auth.get('discord', 'TOKEN'))
File "/home/ubuntu/.local/lib/python3.6/site-packages/discord/client.py", line 519, in run
self.loop.run_until_complete(self.start(*args, **kwargs))
File "/usr/lib/python3.6/asyncio/base_events.py", line 484, in run_until_complete
return future.result()
File "/home/ubuntu/.local/lib/python3.6/site-packages/discord/client.py", line 491, in start
yield from self.connect()
File "/home/ubuntu/.local/lib/python3.6/site-packages/discord/client.py", line 448, in connect
yield from self.ws.poll_event()
File "/home/ubuntu/.local/lib/python3.6/site-packages/discord/gateway.py", line 431, in poll_event
yield from self.received_message(msg)
File "/home/ubuntu/.local/lib/python3.6/site-packages/discord/gateway.py", line 390, in received_message
func(data)
File "/home/ubuntu/.local/lib/python3.6/site-packages/discord/state.py", line 256, in parse_message_update
message.embeds = data['embeds']
KeyError: 'embeds'
This was an issue that was fixed with v1.2.0 of discord.py.
v0.16.12 is an outdated version of discord.py that isn't supported anymore.
You should look into migrating to v1.
Related
RuntimeError: Event loop is closed error when trying to run any bot in discord when connected to my wifi network. When connected to another network, everything works as it should.
Code example:
import discord
from discord.ext import commands
bot = commands.Bot(command_prefix='!', intents=discord.Intents.all())
bot.run(TOKEN)
I am getting the above error when trying to run this code. I am accurately passing the correct access token and have all intents enabled:
I'm using py-cord, but the problem also occurred when using the discord-py library.
I have the latest version of py-cord==2.0.0b7 installed using the command
pip install git+https://github.com/Pycord-Development/pycord
Full text of the error:
Traceback (most recent call last):
File "C:\Users\denisnumb\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\client.py", line 550, in connect
self.ws = await asyncio.wait_for(coro, timeout=60.0)
File "C:\Users\denisnumb\AppData\Local\Programs\Python\Python38\lib\asyncio\tasks.py", line 483, in wait_for
return fut.result()
File "C:\Users\denisnumb\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\gateway.py", line 330, in from_client
socket = await client.http.ws_connect(gateway)
File "C:\Users\denisnumb\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\http.py", line 214, in ws_connect
return await self.__session.ws_connect(url, **kwargs)
File "C:\Users\denisnumb\AppData\Local\Programs\Python\Python38\lib\site-packages\aiohttp\client.py", line 769, in _ws_connect
raise WSServerHandshakeError(
aiohttp.client_exceptions.WSServerHandshakeError: 503, message='Invalid response status', url=URL('wss://gateway.discord.gg/?encoding=json&v=10&compress=zlib-stream')
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "PythonCode.py", line 11, in <module>
bot.run(TOKEN)
File "C:\Users\denisnumb\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\client.py", line 715, in run
return future.result()
File "C:\Users\denisnumb\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\client.py", line 694, in runner
await self.start(*args, **kwargs)
File "C:\Users\denisnumb\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\client.py", line 658, in start
await self.connect(reconnect=reconnect)
File "C:\Users\denisnumb\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\client.py", line 610, in connect
ws_params.update(sequence=self.ws.sequence, resume=True, session=self.ws.session_id)
AttributeError: 'NoneType' object has no attribute 'sequence'
Exception ignored in: <function _ProactorBasePipeTransport.__del__ at 0x00000173E3CD74C0>
Traceback (most recent call last):
File "C:\Users\denisnumb\AppData\Local\Programs\Python\Python38\lib\asyncio\proactor_events.py", line 116, in __del__
self.close()
File "C:\Users\denisnumb\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\denisnumb\AppData\Local\Programs\Python\Python38\lib\asyncio\base_events.py", line 719, in call_soon
self._check_closed()
File "C:\Users\denisnumb\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
If the problem occurs only in a specific Wi-Fi network, it is probably worth trying to restart the router - this was the solution to the problem
I wrote a telegram bot on the aiogram framework. The bot worked fine for over a week, with no problems. The customer started complaining about the bot freezing. I downloaded the log file and saw a bunch of different TraceBacks. This situation has been happening for two days now. List of 3 TraceBacks, for example:
First
Traceback (most recent call last):
File "/usr/local/lib/python3.7/dist-packages/aiohttp/connector.py", line 986, in _wrap_create_connection
return await self._loop.create_connection(*args, **kwargs) # type: ignore[return-value] # noqa
File "/usr/lib/python3.7/asyncio/base_events.py", line 959, in create_connection
raise exceptions[0]
File "/usr/lib/python3.7/asyncio/base_events.py", line 946, in create_connection
await self.sock_connect(sock, address)
File "/usr/lib/python3.7/asyncio/selector_events.py", line 464, in sock_connect
return await fut
File "/usr/lib/python3.7/asyncio/selector_events.py", line 469, in _sock_connect
sock.connect(address)
OSError: [Errno 101] Network is unreachable
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/local/lib/python3.7/dist-packages/aiogram/bot/api.py", line 139, in make_request
async with session.post(url, data=req, **kwargs) as response:
File "/usr/local/lib/python3.7/dist-packages/aiohttp/client.py", line 1138, in __aenter__
self._resp = await self._coro
File "/usr/local/lib/python3.7/dist-packages/aiohttp/client.py", line 536, in _request
req, traces=traces, timeout=real_timeout
File "/usr/local/lib/python3.7/dist-packages/aiohttp/connector.py", line 542, in connect
proto = await self._create_connection(req, traces, timeout)
File "/usr/local/lib/python3.7/dist-packages/aiohttp/connector.py", line 907, in _create_connection
_, proto = await self._create_direct_connection(req, traces, timeout)
File "/usr/local/lib/python3.7/dist-packages/aiohttp/connector.py", line 1206, in _create_direct_connection
raise last_exc
File "/usr/local/lib/python3.7/dist-packages/aiohttp/connector.py", line 1187, in _create_direct_connection
client_error=client_error,
File "/usr/local/lib/python3.7/dist-packages/aiohttp/connector.py", line 992, in _wrap_create_connection
raise client_error(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host api.telegram.org:443 ssl:default [Network is unreachable]
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.7/dist-packages/aiogram/dispatcher/dispatcher.py", line 385, in start_polling
allowed_updates=allowed_updates
File "/usr/local/lib/python3.7/dist-packages/aiogram/bot/bot.py", line 110, in get_updates
result = await self.request(api.Methods.GET_UPDATES, payload)
File "/usr/local/lib/python3.7/dist-packages/aiogram/bot/base.py", line 232, in request
proxy=self.proxy, proxy_auth=self.proxy_auth, timeout=self.timeout, **kwargs)
File "/usr/local/lib/python3.7/dist-packages/aiogram/bot/api.py", line 142, in make_request
raise exceptions.NetworkError(f"aiohttp client throws an error: {e.__class__.__name__}: {e}")
aiogram.utils.exceptions.NetworkError: Aiohttp client throws an error: ClientConnectorError: Cannot connect to host api.telegram.org:443 ssl:default [Network is unreachable]
Second
future: <Task finished coro=<Dispatcher._process_polling_updates() done, defined at /usr/local/lib/python3.7/dist-packages/aiogram/dispatcher/dispatcher.py:407> exception=TelegramAPIError('Gateway Timeout')>
Traceback (most recent call last):
File "/usr/local/lib/python3.7/dist-packages/aiogram/dispatcher/dispatcher.py", line 415, in _process_polling_updates
for responses in itertools.chain.from_iterable(await self.process_updates(updates, fast)):
File "/usr/local/lib/python3.7/dist-packages/aiogram/dispatcher/dispatcher.py", line 235, in process_updates
return await asyncio.gather(*tasks)
File "/usr/local/lib/python3.7/dist-packages/aiogram/dispatcher/handler.py", line 116, in notify
response = await handler_obj.handler(*args, **partial_data)
File "/usr/local/lib/python3.7/dist-packages/aiogram/dispatcher/dispatcher.py", line 256, in process_update
return await self.message_handlers.notify(update.message)
File "/usr/local/lib/python3.7/dist-packages/aiogram/dispatcher/handler.py", line 116, in notify
response = await handler_obj.handler(*args, **partial_data)
File "/home/koval_pavlo03/TokenSaleBot/handlers/admin_commands.py", line 152, in do_adm
await message.answer_document(open('logs.txt', 'rb'))
File "/usr/local/lib/python3.7/dist-packages/aiogram/types/message.py", line 733, in answer_document
reply_markup=reply_markup,
File "/usr/local/lib/python3.7/dist-packages/aiogram/bot/bot.py", line 708, in send_document
result = await self.request(api.Methods.SEND_DOCUMENT, payload, files)
File "/usr/local/lib/python3.7/dist-packages/aiogram/bot/base.py", line 232, in request
proxy=self.proxy, proxy_auth=self.proxy_auth, timeout=self.timeout, **kwargs)
File "/usr/local/lib/python3.7/dist-packages/aiogram/bot/api.py", line 140, in make_request
return check_result(method, response.content_type, response.status, await response.text())
File "/usr/local/lib/python3.7/dist-packages/aiogram/bot/api.py", line 128, in check_result
raise exceptions.TelegramAPIError(description)
aiogram.utils.exceptions.TelegramAPIError: Gateway Timeout
Third
Traceback (most recent call last):
File "/usr/local/lib/python3.7/dist-packages/aiogram/dispatcher/dispatcher.py", line 385, in start_polling
allowed_updates=allowed_updates
File "/usr/local/lib/python3.7/dist-packages/aiogram/bot/bot.py", line 110, in get_updates
result = await self.request(api.Methods.GET_UPDATES, payload)
File "/usr/local/lib/python3.7/dist-packages/aiogram/bot/base.py", line 232, in request
proxy=self.proxy, proxy_auth=self.proxy_auth, timeout=self.timeout, **kwargs)
File "/usr/local/lib/python3.7/dist-packages/aiogram/bot/api.py", line 140, in make_request
return check_result(method, response.content_type, response.status, await response.text())
File "/usr/local/lib/python3.7/dist-packages/aiogram/bot/api.py", line 119, in check_result
exceptions.ConflictError.detect(description)
File "/usr/local/lib/python3.7/dist-packages/aiogram/utils/exceptions.py", line 140, in detect
raise err(cls.text or description)
aiogram.utils.exceptions.TerminatedByOtherGetUpdates: Terminated by other getupdates request; make sure that only one bot instance is running
01/21/2022 19:57:14 SSL error in data received
protocol: <asyncio.sslproto.SSLProtocol object at 0x7feef4858278>
transport: <_SelectorSocketTransport fd=9 read=polling write=<idle, bufsize=0>>
Traceback (most recent call last):
File "/usr/lib/python3.7/asyncio/sslproto.py", line 526, in data_received
ssldata, appdata = self._sslpipe.feed_ssldata(data)
File "/usr/lib/python3.7/asyncio/sslproto.py", line 207, in feed_ssldata
self._sslobj.unwrap()
File "/usr/lib/python3.7/ssl.py", line 767, in unwrap
return self._sslobj.shutdown()
On my computer everything works fine. The bot is hosted on Google Cloud Platform (Compute engine). I have already tried restarting the bot and the host machine - it did not help; the problem appeared again today. I also changed the bot token, also did not work. For the sake of completeness, below is a list of versions:
$ python3 --version
Python 3.7.3
$ python3 -m pip show aiogram
Name: aiogram
Version: 2.18
Summary: Is a pretty simple and fully asynchronous framework for Telegram Bot API
Home-page: https://github.com/aiogram/aiogram
Author: Alex Root Junior
Author-email: jroot.junior#gmail.com
License: MIT
Location: /usr/local/lib/python3.7/dist-packages
Requires: aiohttp, Babel, certifi
Required-by:
$ python3 -m pip show aiohttp
Name: aiohttp
Version: 3.8.1
Summary: Async http client/server framework (asyncio)
Home-page: https://github.com/aio-libs/aiohttp
Author:
Author-email:
License: Apache 2
Location: /usr/local/lib/python3.7/dist-packages
Requires: aiosignal, async-timeout, asynctest, attrs, charset-normalizer, frozenlist, multidict, typing-extensions, yarl
Required-by: aiogram
UPD
Here you can see log file (Google Drive)
The problem is that time on your host machine is different from world time.
I have noticed that Google Cloud compute engine doesn't have any time synchronization services. That explains why the bot works well for some time, and then he starts catching tracebacks.
Hey I'm pretty new to coding bots in python, I've gotten this error for quite a bit and I don't know what's wrong, could someone help please.
cogs = [levelsys]
client = commands.Bot(command_prefix="-", intents=discord.Intents.all())
for i in range(len(cogs)):
cogs[i].setup(client)
client.run("Token")
more of the error message:
> & C:/Users/User/AppData/Local/Programs/Python/Python39/python.exe d:/Bot/TheHubProjects/LevelSys/main.py
Traceback (most recent call last):
File "d:\Bot\TheHubProjects\LevelSys\main.py", line 9, in <module>
client.run("Token")
File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\client.py", line 723, in run
return future.result()
File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\client.py", line 702, in runner
await self.start(*args, **kwargs)
File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\client.py", line 666, in start
await self.connect(reconnect=reconnect)
File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\client.py", line 601, in connect
raise PrivilegedIntentsRequired(exc.shard_id) from None
discord.errors.PrivilegedIntentsRequired: Shard ID None is requesting privileged intents that have not been explicitly enabled in the developer portal. It is recommended to go to https://discord.com/developers/applications/ and explicitly enable the privileged intents within your application's page. If this is not possible, then consider disabling the privileged intents instead.
Exception ignored in: <function _ProactorBasePipeTransport.__del__ at 0x0000014FBE5BA280>
Traceback (most recent call last):
File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\asyncio\proactor_events.py", line 116, in __del__
self.close()
File "C:\Users\User\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\User\AppData\Local\Programs\Python\Python39\lib\asyncio\base_events.py", line 746, in call_soon
PS D:\Bot> & C:/Users/User/AppData/Local/Programs/Python/Python39/python.exe d:/Bot/TheHubProjects/LevelSys/main.py
Traceback (most recent call last):
File "C:\Users\User\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\User\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 "d:\Bot\TheHubProjects\LevelSys\main.py", line 12, in <module>
client.run("Token")
File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\client.py", line 723, in run
return future.result()
File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\client.py", line 702, in runner
await self.start(*args, **kwargs)
File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\client.py", line 665, in start
await self.login(*args, bot=bot)
File "C:\Users\User\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\User\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 0x000001BD6BABA280>
Traceback (most recent call last):
File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\asyncio\proactor_events.py", line 116, in __del__
self.close()
File "C:\Users\User\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\User\AppData\Local\Programs\Python\Python39\lib\asyncio\base_events.py", line 746, in call_soon
self._check_closed()
File "C:\Users\User\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
I hope thats not your actual discord bot token? And you have "commands_prefix="-" its just "command_prefix="-"
Edit: i believe its in the loading cog, try putting your cog class in its own folder called cogs. This function gets all files in cogs folder with .py, removes the .py and load them. You arnt using the load_extension so hopefully this works, other than this it must be a error in the cog class or an error with the "intents="
# Load All Categorys in cogs folder
Import os
for filename in os.listdir('./cogs'):
if filename.endswith('.py'):
client.load_extension(f'cogs.{filename[:-3]}')
Okay. This is complicated for me to explain, but I'll try my best:
it starts when one day I decide to run and test my Discord bot (using discord.py) when I'm greeted with this error:
TypeError: __new__() got an unexpected keyword argument 'deny_new'
If needed, the full traceback:
File "script.py", line 14, in <module>
bot.run('token')
File "C:\Users\44794\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\client.py", line 640, in run
return future.result()
File "C:\Users\44794\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\client.py", line 621, in runner
await self.start(*args, **kwargs)
File "C:\Users\44794\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\client.py", line 585, in start
await self.connect(reconnect=reconnect)
File "C:\Users\44794\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\client.py", line 499, in connect
await self._connect()
File "C:\Users\44794\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\client.py", line 463, in _connect
await self.ws.poll_event()
File "C:\Users\44794\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\gateway.py", line 471, in poll_event
await self.received_message(msg)
File "C:\Users\44794\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\gateway.py", line 425, in received_message
func(data)
File "C:\Users\44794\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\state.py", line 750, in parse_guild_create
guild = self._get_create_guild(data)
File "C:\Users\44794\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\state.py", line 725, in _get_create_guild
guild._from_data(data)
File "C:\Users\44794\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\guild.py", line 297, in _from_data
self._sync(guild)
File "C:\Users\44794\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\guild.py", line 324, in _sync
self._add_channel(TextChannel(guild=self, data=c, state=self._state))
File "C:\Users\44794\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\channel.py", line 107, in __init__
self._update(guild, data)
File "C:\Users\44794\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\channel.py", line 131, in _update
self._fill_overwrites(data)
File "C:\Users\44794\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\abc.py", line 294, in _fill_overwrites
self._overwrites.append(_Overwrites(id=overridden_id, **overridden))
TypeError: __new__() got an unexpected keyword argument 'deny_new'
I looked up this issue and found a resolution to this problem - to just reinstall discord.py. So:
> pip uninstall discord
Another error:
Unable to create process using 'C:\Users\44794\aanaconda3\python.exe C:\Users\44794\aanaconda3\Scripts\pip-script.py uninstall discord'
I'm sure that once I have the solution to this issue, the other problems can be fixed easily.
As always, I've only been properly using Python for two months or so. Please try to simplify the solution as best you can! Thanks in advance.
A couple days ago my discord bot suddenly went offline, i host my bot through repl.it and i cant get it to work as it gives a dirty error.
Traceback (most recent call last):
File "main.py", line 584, in <module>
bot.run("NTg0NjkyODA1NTcwNjU4MzEz.XPOnmw.VpE_ILHaDdQ6k--OIBRovc1h80o")
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 640, in run
return future.result()
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 621, in runner
await self.start(*args, **kwargs)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 585, in start
await self.connect(reconnect=reconnect)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 499, in connect
await self._connect()
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 463, in _connect
await self.ws.poll_event()
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/gateway.py", line 471, in poll_even
t
await self.received_message(msg)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/gateway.py", line 425, in received_
message
func(data)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/state.py", line 750, in parse_guild
_create
guild = self._get_create_guild(data)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/state.py", line 725, in _get_create_guild
guild._from_data(data)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/guild.py", line 297, in _from_data
self._sync(guild)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/guild.py", line 328, in _sync
self._add_channel(CategoryChannel(guild=self, data=c, state=self._state))
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/channel.py", line 726, in __init__
self._update(guild, data)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/channel.py", line 737, in _update
self._fill_overwrites(data)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/abc.py", line 294, in _fill_overwrites
self._overwrites.append(_Overwrites(id=overridden_id, **overridden))
TypeError: __new__() got an unexpected keyword argument 'deny_new'
this is in the console and i dont know what it means. we didnt change any code, nothing it just went offline and stop working.
Just update the discord.py module. Discord switched the api domain from discordapp.com to discord.com. That is the reason for the code crashing.
You can just go to packages and uninstall the current discord.py module. Then re-add it. There is no feature to directly update the discord.py module. SO u have to uninstall and re-install. [worked for me]