Reliable aiodns resolution for discord.py bots on Windows
Project description
discord-py-win-aiodns
discord-py-win-aiodns is an opt-in Windows runner for discord.py bots that
uses aiodns without modifying or monkeypatching discord.py.
It runs the bot in a selector event loop and supplies a public aiohttp
connector to the discord.py client. Its default resolver strategy is designed
for Windows environments where c-ares detects an unusable DNS server.
This project is not affiliated with Discord, discord.py, aiohttp, aiodns, or Cloudflare.
What it does
In the default auto mode, DNS resolution proceeds in this order:
aiodnswith the DNS servers detected by c-ares.- Cloudflare DNS (
1.1.1.1and1.0.0.1) throughaiodns. - aiohttp's threaded system resolver, which uses Windows name resolution.
The package logs a warning when it changes stage. Once a fallback resolves a
host successfully, it logs one INFO message naming the active stage. A
normal successful automatic aiodns lookup produces no extra log entry.
Fallback-oriented modes (auto, public, and custom) use one 1-second
aiodns attempt per stage so an unreachable DNS server does not delay startup
for the resolver's default retry period. The strict aiodns mode preserves
aiodns's own timeout and retry defaults.
Only DNS resolution is affected. This package does not guarantee that a bot as a whole will be faster, and it does not hide connection failures.
Requirements
- Windows
- Python 3.9 or newer
- discord.py 2.5 or newer
Python 3.9 installs the compatible aiodns 3.6 series. Python 3.10 and newer install aiodns 4 or newer. Python 3.10 or newer is recommended for production, so current security fixes in the dependency ecosystem are available.
Installation
py -3 -m pip install -U discord-py-win-aiodns
The package installs discord.py, aiohttp, and aiodns as dependencies when
they are not already installed.
Usage
Build the bot in a factory that accepts an aiohttp connector. Call run
instead of bot.run.
import os
import discord
from discord.ext import commands
from discord_win_aiodns import run
def create_bot(connector):
intents = discord.Intents.default()
return commands.Bot(command_prefix='!', intents=intents, connector=connector)
run(create_bot, os.environ['DISCORD_TOKEN'])
Never hard-code or commit a Discord bot token. Set it for the current PowerShell session before starting the bot:
$env:DISCORD_TOKEN = 'your-token'
py .\bot.py
Resolver modes
| Mode | Behaviour |
|---|---|
auto |
Use c-ares autodetection, then Cloudflare DNS, then the Windows resolver. This is the default. |
aiodns |
Use only the DNS servers detected by c-ares. A DNS transport failure is raised. |
public |
Use Cloudflare DNS through aiodns, then the Windows resolver if it cannot be reached. |
custom |
Use DNS servers supplied through nameservers, then the Windows resolver if they cannot be reached. |
system |
Use only aiohttp's threaded Windows system resolver. |
Use an explicit public-DNS-only first stage:
run(create_bot, os.environ['DISCORD_TOKEN'], resolver='public')
Use a specific DNS server:
run(
create_bot,
os.environ['DISCORD_TOKEN'],
resolver='custom',
nameservers=['1.1.1.1'],
)
Keep auto from contacting Cloudflare DNS:
run(create_bot, os.environ['DISCORD_TOKEN'], public_fallback=False)
Privacy and network policy
The default auto mode can send DNS lookups to Cloudflare after c-ares DNS
autodetection fails. Select system, or use
public_fallback=False, when the bot must not use public DNS servers. Use
custom when the deployment has an approved DNS resolver.
Diagnostics
diagnose.py tests aiodns without a bot token:
py diagnose.py
py diagnose.py --public
py diagnose.py --host gateway.discord.gg --nameserver 1.1.1.1
Use diagnostics before choosing a custom nameserver. Do not publish private
network addresses or DNS settings in an issue.
Development
py -3 -m pip install -e .
py -3 -m unittest discover -s tests -v
py -3 -m build
Releases and PyPI publishing
The CI workflow runs pytest with coverage, Ruff, mypy, pip-audit, and
distribution checks on Windows for every pull request and push to main.
CodeQL scans the Python source on pull requests, pushes to main, and weekly.
After CI succeeds on main, its publish job compares the local version with
PyPI. It publishes only when the local version is newer than the latest
released version. It uses PyPI Trusted Publishing, so no PyPI token is stored
in GitHub secrets.
Before the first release, configure a PyPI pending publisher for this GitHub
repository with workflow file ci.yml and environment pypi. Then:
- Update
versioninpyproject.tomlandCHANGELOG.md. - Commit and push the release changes.
- Merge the version change into
main. CI and the publish workflow handle the build and distribution.
Contributing
See CONTRIBUTING.md. Security reports are covered by SECURITY.md.
License
This project is licensed under the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file discord_py_win_aiodns-0.1.0.tar.gz.
File metadata
- Download URL: discord_py_win_aiodns-0.1.0.tar.gz
- Upload date:
- Size: 8.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8351a2b687fce94e738432b59e0808921ff7033ed43ad9e8f4fc704272eef24e
|
|
| MD5 |
f3ffdafe451e4386a77cd98dd23e629c
|
|
| BLAKE2b-256 |
80f44bec70de6672e5ce747ba6c7e26d49393b50685a18a3b6a3d0c0c997a7eb
|
Provenance
The following attestation bundles were made for discord_py_win_aiodns-0.1.0.tar.gz:
Publisher:
ci.yml on disnana/discord.py-win-aiodns
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
discord_py_win_aiodns-0.1.0.tar.gz -
Subject digest:
8351a2b687fce94e738432b59e0808921ff7033ed43ad9e8f4fc704272eef24e - Sigstore transparency entry: 2140771387
- Sigstore integration time:
-
Permalink:
disnana/discord.py-win-aiodns@7975ed266c6ed72389e8032bf58b0b9a3995941b -
Branch / Tag:
refs/heads/main - Owner: https://github.com/disnana
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@7975ed266c6ed72389e8032bf58b0b9a3995941b -
Trigger Event:
push
-
Statement type:
File details
Details for the file discord_py_win_aiodns-0.1.0-py3-none-any.whl.
File metadata
- Download URL: discord_py_win_aiodns-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
588d8944e994a172b57c827cebc84cdb9bb912f804f73a84358aba451a7a70ac
|
|
| MD5 |
a8a869c22337f3c2cce2aa501d41b1d1
|
|
| BLAKE2b-256 |
86467baaf15945f642bc24f42e1dff3ca9171164a512c6c943cb1f422bc89196
|
Provenance
The following attestation bundles were made for discord_py_win_aiodns-0.1.0-py3-none-any.whl:
Publisher:
ci.yml on disnana/discord.py-win-aiodns
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
discord_py_win_aiodns-0.1.0-py3-none-any.whl -
Subject digest:
588d8944e994a172b57c827cebc84cdb9bb912f804f73a84358aba451a7a70ac - Sigstore transparency entry: 2140771391
- Sigstore integration time:
-
Permalink:
disnana/discord.py-win-aiodns@7975ed266c6ed72389e8032bf58b0b9a3995941b -
Branch / Tag:
refs/heads/main - Owner: https://github.com/disnana
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@7975ed266c6ed72389e8032bf58b0b9a3995941b -
Trigger Event:
push
-
Statement type: