Skip to main content

discord-py-win-aiodns

日本語 README

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:

  1. aiodns with the DNS servers detected by c-ares.
  2. Cloudflare DNS (1.1.1.1 and 1.0.0.1) through aiodns.
  3. 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:

  1. Update version in pyproject.toml and CHANGELOG.md.
  2. Commit and push the release changes.
  3. 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.

Metadata

Release files for discord-py-win-aiodns 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for discord-py-win-aiodns 0.1.2
File Size Uploaded Provenance
discord_py_win_aiodns-0.1.2.tar.gz 9.3 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for discord-py-win-aiodns 0.1.2
File Interpreter ABI Platform
discord_py_win_aiodns-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 16.9 kB

Release files / discord_py_win_aiodns-0.1.2.tar.gz

Download URL discord_py_win_aiodns-0.1.2.tar.gz
Size 9.3 kB
Tags Source
SHA-256 checksum
How to use checksums
62cdd5fb8218577351d338c727dae312fff63aec65e0fc63c55396438bd46bb9
BLAKE2b-256 checksum
How to use checksums
8caa6aab22540b73973164002e621a9299d23c56001f69674a89cda6c7253883
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 14, 2026.

Transparency log

Release files / discord_py_win_aiodns-0.1.2-py3-none-any.whl

Download URL discord_py_win_aiodns-0.1.2-py3-none-any.whl
Size 7.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
34ac098744d5eafabccb74165d4193ec174727c45d54f75d273fdbd553e4e0a7
BLAKE2b-256 checksum
How to use checksums
ab83b69e76d077d2f9f4bf58f44fdeca510933e2abeec34dcc467780d92e34c6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 14, 2026.

Transparency log

Security for discord-py-win-aiodns 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for discord_py_win_aiodns-0.1.2.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 14, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page