0

Hi I'm getting an issue where I get a pretty long error returning Shard ID %s heartbeat blocked for more than 10s seconds.

I originally thought that I could be happening due to the database returning any information because it's empty. I tried to prevent the error by checking for None and returning it but the error still persists.

> Message: 'Shard ID %s heartbeat blocked for more than %s seconds.\nLoop thread traceback (most recent 
call last):\n  File "/app/run.py", line 270, in <module>\n    bot.run(token)\n  File 
"/app/.jack/python/lib/python3.9/site-packages/discord/client.py", line 713, in run\n    
 loop.run_forever()\n  File "/app/.jack/python/lib/python3.9/asyncio/base_events.py", line 596, in 
run_forever\n    self._run_once()\n  File "/app/.jack/python/lib/python3.9/asyncio/base_events.py", 
line 1890, in _run_once\n    handle._run()\n  File 
"/app/.jack/python/lib/python3.9/asyncio/events.py", line 80, in _run\n    
self._context.run(self._callback, *self._args)\n  File "/app/.jack/python/lib/python3.9/site- 
packages/discord/client.py", line 343, in _run_event\n    await coro(*args, **kwargs)\n  File 
"/app/cogs/mods.py", line 339, in mute_check\n    cursor.execute("SELECT username FROM blacklist 
WHERE username=%s", (user.id, ))\n

> : Arguments: (None, 10)

Here is what I'm working with:

@tasks.loop(seconds=60)
async def mute_check(self):
    await self.bot.wait_until_ready()
    self.ready = True
    guild = self.bot.get_guild(ID)
    for member in guild.members:
        conn = psycopg2.connect(DATABASE_URL, sslmode='require')
        cursor = conn.cursor()
        # Changed the query so that NULLs (which will be cast as None) are not returned
        cursor.execute("SELECT time FROM blacklist WHERE username=%s AND time IS NOT NULL", (member.id, ))
        # no index needed, multiple stamps are returned 
        results = cursor.fetchall()

        for result in results:
            if result is None:
                return
            # first and only returned element
            timestamp = result[0] 

            restricted_role = get(guild.roles, name="Restricted")
            datestamp = datetime.now()

            datetimestring = str(datestamp.now().strftime("%Y%m%d%H%M%S"))
            dateonlystring = timestamp.strftime("%Y%m%d%H%M%S")
            
            if (datetimestring > dateonlystring):
                await member.remove_roles(restricted_role, reason='Restricted role removed (auto timer).')
            
        cursor.close()
        conn.close()

Help would be greatly appreciated.

Joe
  • 25
  • 6
  • Does this answer your question? [Discord.gateway warning "Shard ID None heartbeat blocked for more than 10 seconds." while using pandas](https://stackoverflow.com/questions/65881761/discord-gateway-warning-shard-id-none-heartbeat-blocked-for-more-than-10-second) – Łukasz Kwieciński Apr 09 '21 at 19:40
  • No unfortunately not what I was looking for. – Joe Apr 09 '21 at 21:23

0 Answers0