#Heartbeater Raised An Exception Error

1 messages · Page 1 of 1 (latest)

merry turret
#

After Some Time, my Bot seems to just randomly go off with the given Exception. I can't catch (try except) it by just catching the bot.run(). What exactly causes the Exception, or is there atleast a way to catch it to automatically run the bot again?

The heartbeater raised an exception!
Traceback (most recent call last):
  File "/home/container/.local/lib/python3.11/site-packages/aiohttp/connector.py", line 1155, in _create_direct_connection
    hosts = await asyncio.shield(host_resolved)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/container/.local/lib/python3.11/site-packages/aiohttp/connector.py", line 874, in _resolve_host
    addrs = await self._resolver.resolve(host, port, family=self._family)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/container/.local/lib/python3.11/site-packages/aiohttp/resolver.py", line 33, in resolve
    infos = await self._loop.getaddrinfo(
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/asyncio/base_events.py", line 867, in getaddrinfo
    return await self.run_in_executor(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/socket.py", line 962, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
faint citrusBOT
#

Hey! Once your issue is solved, press the button below to close this thread!

merry turret
#
socket.gaierror: [Errno -3] Temporary failure in name resolution
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
  File "/home/container/.local/lib/python3.11/site-packages/interactions/api/gateway/websocket.py", line 279, in run_bee_gees
    await self._start_bee_gees()
  File "/home/container/.local/lib/python3.11/site-packages/interactions/api/gateway/websocket.py", line 303, in _start_bee_gees
    await self.reconnect(resume=True)
  File "/home/container/.local/lib/python3.11/site-packages/interactions/api/gateway/gateway.py", line 279, in reconnect
    await super().reconnect(resume=resume, code=code, url=url)
  File "/home/container/.local/lib/python3.11/site-packages/interactions/api/gateway/websocket.py", line 259, in reconnect
    self.ws = await self.state.client.http.websocket_connect(url or self.ws_url)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/container/.local/lib/python3.11/site-packages/interactions/api/http/http_client.py", line 575, in websocket_connect
    return await self.__session.ws_connect(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/container/.local/lib/python3.11/site-packages/aiohttp/client.py", line 779, in _ws_connect
    resp = await self.request(
           ^^^^^^^^^^^^^^^^^^^
#
  File "/home/container/.local/lib/python3.11/site-packages/aiohttp/client.py", line 536, in _request
    conn = await self._connector.connect(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/container/.local/lib/python3.11/site-packages/aiohttp/connector.py", line 540, in connect
    proto = await self._create_connection(req, traces, timeout)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/container/.local/lib/python3.11/site-packages/aiohttp/connector.py", line 901, in _create_connection
    _, proto = await self._create_direct_connection(req, traces, timeout)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/container/.local/lib/python3.11/site-packages/aiohttp/connector.py", line 1169, in _create_direct_connection
    raise ClientConnectorError(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host gateway.discord.gg:443 ssl:default [Temporary failure in name resolution]
grave inlet
#

That error is caused by a network issue, where the server your bot is running on loses connection to discord

merry turret
merry turret
gray basalt
#

you dont usually

#

you usually have some sort of external program to detect the program doing down, and then reboot it

#

there's not a great way for ipy to handle these types of errors itself

#

typically pm2 and systemctl are commonly used

merry turret
#

Can't really find a good way to use pm2 within the host I am currently Using.

While being rather unpractical, I am able to somewhat Restart the bot by saving all the data and then executing the main bot python file afterwards to redo the process. However, this way I have the issue of the RAM from previous scripts stacking up... And with the bot having to reconnect like once per day when it's running good, this adds up quickly to use up all the RAM...

Is there a way to safely remove the RAM Usage from previous scripts that aren't in use anymore? (I guess this is more of a general python help)

gray basalt
#

i mean, stopping the program properly will do that

merry turret
#

Yeah, but how can you do that while still executing the main bot file afterwards (or I guess stopping the program once you have executed the main bot file)?

gray basalt
#

...um, just stop it as a normal thing?

#

just do control c?

#

or i guess you could shutdown the bot by running bot.stop() in a command

merry turret
#

Even after using bot.stop or the bot disconnecting, simply executing os.system(bot.py path) will still clog up the RAM of all the previous executions...

gray basalt
#

if you're doing await bot.stop() and the previous ram is still there, then your host is fucked

merry turret
#

My code is that have a simply command that executes await bot.stop()

and then still has this (extension/cog) to actually execute the main bot file again

import interactions as i
import os

class onDisconnect(i.Extension):
    def __init__(self, client):
        self.client: i.Client = client
        
    @i.listen()
    async def on_disconnect(self, message):
        bot = self.bot
        os.system("python3 " + self.bot.path + "bot.py")
gray basalt
#

if youre resorting to this, yeah, your host is the issue 😅

#

cant help you there

merry turret
#

Are there any hosts you would recommend?

faint citrusBOT
#
Hosting Your Bot

Often, you'll need some sort of server or host to run your bot 24/7. There are a number of options available:

Affordable Paid Hosting

These hosts offer 24/7 VPSs, are usually very affordable, and are trustworthy. Which one is best for you depends on where you live, your budget, and what features you need.

Free Tiers Services

These hosts have a free tier that you can use for your bots. These usually will require a credit card to verify yourself.

  • Oracle Cloud gives an incredible 24 GB of RAM and 4 VCPUs (1 VCPU is usually one core of a CPU the host uses) for its free tier, as well as two Oracle Linux 1 GB RAM 1 VCPU VMs. Note, though, that support may be lackluster, and it may not work in certain regions.
  • Google Cloud Platform offers a respectable 1 GB of RAM and 0.25 VCPUs (Discord bots typically do not need much when starting out) for its always free tier.
  • With the GitHub Student Developer Pack, you can get enough in free credits (renewed annually) to sustain a bot on Microsoft Azure as well as other goodies, all without a credit card. Note that this requires some sort of proof that you are a student, from an email to a report card/transcript.
  • Amazon Web Services offers an EC2 instance (which you can run a bot on) for free for 12 months.

Self-Hosting

Self-hosting poses its own challenges, as you usually need to ensure that you have a device capable running 24/7 and is either immune or able to avoid any power outages/disruptions to your internet. However, if you can guarantee that, or are okay with facing downtime, then virtually any modern-day device is able to run a bot - Python doesn't take much to run. A Raspberry Pi is often used for this purpose, but any (ideally spare) computer can be used - installing Linux can make even the oldest computers usable for basic bots.

Special care should be taken to make sure your internet and device is protected from any malicious attacks.

Other Options

  • From time to time, you may hear about a service that requires running a webpage alongside a bot and pinging the page every once in a while to keep the program alive. These services are not recommended and not supported in interactions.py. Running a webpage to keep pinging means taking away a sizable amount of resources from your bot to do that, and with the limited free tiers that these services provide, that often can become a big issue. You're also just not using these services to their intended purpose - the hosts have all the right to control these attempts at hosting bots on their services.
  • There may be more services out there claiming to run a Discord bot for free. View these services with skepticism - at the very worst, they could be stealing your Discord tokens to hijack your bot and destroy servers it's in. Remember: if you're not paying for a product, you are the product.
merry turret
#

thanks a ton 🫂