{"id":15364117,"url":"https://github.com/psidex/discordhealthcheck","last_synced_at":"2025-04-15T07:31:14.322Z","repository":{"id":57418403,"uuid":"261035717","full_name":"psidex/DiscordHealthCheck","owner":"psidex","description":"A small library and command line app to automate Docker health checks for discord.py bots. Now updated for Discord.py v2!","archived":false,"fork":false,"pushed_at":"2022-12-14T01:25:35.000Z","size":33,"stargazers_count":14,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-12T21:46:26.103Z","etag":null,"topics":["discord","discord-bot","discord-py","docker","health-check","healthcheck","pypi","python-library","socket-server"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/discordhealthcheck/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/psidex.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-05-03T22:50:32.000Z","updated_at":"2025-01-20T04:06:23.000Z","dependencies_parsed_at":"2023-01-28T16:15:46.245Z","dependency_job_id":null,"html_url":"https://github.com/psidex/DiscordHealthCheck","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/psidex%2FDiscordHealthCheck","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/psidex%2FDiscordHealthCheck/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/psidex%2FDiscordHealthCheck/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/psidex%2FDiscordHealthCheck/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/psidex","download_url":"https://codeload.github.com/psidex/DiscordHealthCheck/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249026756,"owners_count":21200502,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["discord","discord-bot","discord-py","docker","health-check","healthcheck","pypi","python-library","socket-server"],"created_at":"2024-10-01T13:10:03.624Z","updated_at":"2025-04-15T07:31:14.033Z","avatar_url":"https://github.com/psidex.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Discord Health Check\r\n\r\n[![CI](https://github.com/psidex/discordhealthcheck/workflows/CI/badge.svg)](https://github.com/psidex/discordhealthcheck/actions)\r\n[![PyPI - Downloads](https://img.shields.io/pypi/dm/discordhealthcheck?colorA=35383d)](https://pypi.org/project/discordhealthcheck/)\r\n[![PyPI](https://img.shields.io/pypi/v/discordhealthcheck?colorA=35383d)](https://pypi.org/project/discordhealthcheck/)\r\n[![Black formatter](https://img.shields.io/badge/Code%20Style-Black-000000.svg?colorA=35383d)](https://github.com/psf/black)\r\n\r\nA small Python 3 library and command line app to automate Docker health checks for [discord.py](https://discordpy.readthedocs.io/en/latest/) bots.\r\n\r\n## Installation\r\n\r\n`pip install discordhealthcheck`\r\n\r\nThis will install both the Python library and the command line app, the python library is importable using `import discordhealthcheck` and the CLI app by using the command `discordhealthcheck`.\r\n\r\n## How It Works \u0026 Usage Examples\r\n\r\n### Python Library (Server)\r\n\r\nThe library has 1 function, `start`.\r\n\r\n`start` takes a `discord.Client` object as well as optional parameters, and returns an awaitable that produces a `asyncio.base_events.Server`:\r\n\r\n```python\r\ndef start(\r\n    client: discord.client,\r\n    port: int = 40404,\r\n    bot_max_latency: float = 0.5\r\n) -\u003e Awaitable[asyncio.base_events.Server]\r\n```\r\n\r\n`start` calls [`asyncio.start_server`](https://docs.python.org/3/library/asyncio-stream.html#asyncio.start_server), creating an asyncio TCP socket server which listens for connections. Once a client connects, it tests the discord client for various things that indicate its health (latency, login status, etc.), and the result of this health check is then sent to the healthcheck client.\r\n\r\nThe returned `Server` object can be used to stop the server (e.g. `healthcheck_server.close()`)\r\n\r\nThe default port for the socket server is `40404`, if you change it you will need to use the `--port` flag on the client as well.\r\n\r\nCall `start` once your event loop is running, generally a good place to call from is inside your [`setup_hook`](https://discordpy.readthedocs.io/en/stable/api.html#discord.Client.setup_hook) method:\r\n\r\n```python\r\nimport discord\r\nimport discordhealthcheck\r\n\r\nclass CustomClient(discord.Client):\r\n    def __init__(self, *args, **kwargs):\r\n        super().__init__(*args, **kwargs)\r\n\r\n    async def setup_hook(self):\r\n        self.healthcheck_server = await discordhealthcheck.start(self)\r\n        # Later you can close or check on self.healthcheck_server\r\n```\r\n\r\n### CLI App (Client)\r\n\r\nThe CLI app is a simple client that connects to the server and determines its exit code from what the server sends; `0`\r\nfor healthy, `1` for unhealthy.\r\n\r\nHere's an example of using in a Dockerfile:\r\n\r\n```dockerfile\r\nFROM python:3.11-slim-buster\r\n\r\n# Copy files, install requirements, setup bot, etc.\r\n\r\nRUN pip install discordhealthcheck\r\n\r\n# The `|| exit 1` isn't required but it's good practice anyway.\r\nHEALTHCHECK CMD discordhealthcheck || exit 1\r\n\r\nCMD [\"python\", \"/path/to/bot.py\"]\r\n```\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpsidex%2Fdiscordhealthcheck","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpsidex%2Fdiscordhealthcheck","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpsidex%2Fdiscordhealthcheck/lists"}