Forums

discord bot can't connect to discord

ok so basically i was following some tutorial and put my token then pressed run and then this happened:

Traceback (most recent call last):
  File "/home/rech2020/.local/lib/python3.10/site-packages/aiohttp/connector.py", line 992, in _wrap_create_connection
    return await self._loop.create_connection(*args, **kwargs)
  File "/usr/local/lib/python3.10/asyncio/base_events.py", line 1064, in create_connection
    raise exceptions[0]
  File "/usr/local/lib/python3.10/asyncio/base_events.py", line 1049, in create_connection
    sock = await self._connect_sock(
  File "/usr/local/lib/python3.10/asyncio/base_events.py", line 960, in _connect_sock
    await self.sock_connect(sock, address)
  File "/usr/local/lib/python3.10/asyncio/selector_events.py", line 500, in sock_connect
    return await fut
  File "/usr/local/lib/python3.10/asyncio/selector_events.py", line 535, in _sock_connect_cb
    raise OSError(err, f'Connect call failed {address}')
ConnectionRefusedError: [Errno 111] Connect call failed ('162.159.138.232', 443)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/rech2020/discord_bot/main.py", line 15, in <module>
    bot.run('yes token is here i just removed it from error')
  File "/home/rech2020/.local/lib/python3.10/site-packages/discord/client.py", line 860, in run
    asyncio.run(runner())
  File "/usr/local/lib/python3.10/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/local/lib/python3.10/asyncio/base_events.py", line 646, in run_until_complete
    return future.result()
  File "/home/rech2020/.local/lib/python3.10/site-packages/discord/client.py", line 849, in runner
    await self.start(token, reconnect=reconnect)
  File "/home/rech2020/.local/lib/python3.10/site-packages/discord/client.py", line 777, in start
    asyncio.run(runner())
    await self.login(token)
  File "/home/rech2020/.local/lib/python3.10/site-packages/discord/client.py", line 612, in login
    data = await self.http.static_login(token)
  File "/home/rech2020/.local/lib/python3.10/site-packages/discord/http.py", line 803, in static_login
    data = await self.request(Route('GET', '/users/@me'))
  File "/home/rech2020/.local/lib/python3.10/site-packages/discord/http.py", line 625, in request
    async with self.__session.request(method, url, **kwargs) as response:
  File "/home/rech2020/.local/lib/python3.10/site-packages/aiohttp/client.py", line 1187, in __aenter__
    self._resp = await self._coro
  File "/home/rech2020/.local/lib/python3.10/site-packages/aiohttp/client.py", line 574, in _request
    conn = await self._connector.connect(
  File "/home/rech2020/.local/lib/python3.10/site-packages/aiohttp/connector.py", line 544, in connect
    proto = await self._create_connection(req, traces, timeout)
  File "/home/rech2020/.local/lib/python3.10/site-packages/aiohttp/connector.py", line 911, in _create_connection
_, proto = await self._create_direct_connection(req, traces, timeout)
  File "/home/rech2020/.local/lib/python3.10/site-packages/aiohttp/connector.py", line 1235, in _create_direct_connection
    raise last_exc
  File "/home/rech2020/.local/lib/python3.10/site-packages/aiohttp/connector.py", line 1204, in _create_direct_connection
    transp, proto = await self._wrap_create_connection(
  File "/home/rech2020/.local/lib/python3.10/site-packages/aiohttp/connector.py", line 1000, in _wrap_create_connection
    raise client_error(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host discord.com:443 ssl:default [Connect call failed ('162.159.138.232', 443)]

did i do something wrong or discord bots are not possible on pythonanywhere

From a free account, you need to configure the library that you're using to connect through the proxy. Check the documentation of the library to see how to do that and the details that you need are here: https://help.pythonanywhere.com/pages/403ForbiddenError/

i am using discord.py

Unfortunately I don't think that the discord.py library is able to operate through a proxy, so you would need a paid account to use it.