Skip to content
Advertisement

“TypeError: shield() got an unexpected keyword argument ‘loop'” when running discord.py bot

When I launch my discord.py bot with this code:

> from discord.ext import commands
> 
> bot = commands.Bot(command_prefix = ",", description = "Bot de eagle57")
> 
> bot.run("Mytoken")

I get this error:

C:UsersElèveAppDataLocalProgramsPythonPython310libsite-packagesaiohttpconnector.py:964: RuntimeWarning: coroutine 'TCPConnector._resolve_host' was never awaited
  hosts = await asyncio.shield(self._resolve_host(
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
Traceback (most recent call last):
  File "d:PythonBot_discordmain.py", line 5, in <module>
    bot.run("Mytoken")
  File "C:UsersElèveAppDataLocalProgramsPythonPython310libsite-packagesdiscordclient.py", line 723, in run
    return future.result()
  File "C:UsersElèveAppDataLocalProgramsPythonPython310libsite-packagesdiscordclient.py", line 702, in runner
    await self.start(*args, **kwargs)
  File "C:UsersElèveAppDataLocalProgramsPythonPython310libsite-packagesdiscordclient.py", line 665, in start
    await self.login(*args, bot=bot)
  File "C:UsersElèveAppDataLocalProgramsPythonPython310libsite-packagesdiscordclient.py", line 511, in login
    await self.http.static_login(token.strip(), bot=bot)
  File "C:UsersElèveAppDataLocalProgramsPythonPython310libsite-packagesdiscordhttp.py", line 
300, in static_login
    data = await self.request(Route('GET', '/users/@me'))
  File "C:UsersElèveAppDataLocalProgramsPythonPython310libsite-packagesdiscordhttp.py", line 
192, in request
    async with self.__session.request(method, url, **kwargs) as r:
  File "C:UsersElèveAppDataLocalProgramsPythonPython310libsite-packagesaiohttpclient.py", line 1012, in __aenter__
    self._resp = await self._coro
  File "C:UsersElèveAppDataLocalProgramsPythonPython310libsite-packagesaiohttpclient.py", line 480, in _request
    conn = await self._connector.connect(
  File "C:UsersElèveAppDataLocalProgramsPythonPython310libsite-packagesaiohttpconnector.py", 
line 523, in connect
    proto = await self._create_connection(req, traces, timeout)
  File "C:UsersElèveAppDataLocalProgramsPythonPython310libsite-packagesaiohttpconnector.py", 
line 858, in _create_connection
    _, proto = await self._create_direct_connection(
  File "C:UsersElèveAppDataLocalProgramsPythonPython310libsite-packagesaiohttpconnector.py", 
line 964, in _create_direct_connection
    hosts = await asyncio.shield(self._resolve_host(
TypeError: shield() got an unexpected keyword argument 'loop'

Does anyone have any idea why I have this error?

I have already removed everything that is not required in the code and I have updated all my pip freeze, but the error doesn’t change.

Advertisement

Answer

This is usually caused because of outdated aiohttp module

You can run

pip install -U aiohttp

and

pip install -U discord.py

This will fix your issue in most cases

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement