Skip to main content

Async Python wrapper for Discord's native polling API.

Project description

Pollcord

Pollcord is a lightweight asynchronous Python wrapper for Discord’s poll API.
It handles poll creation, fetching, and expiration — while giving you a clean, extensible framework for running polls in bots or automation scripts.


Features

  • Async-first design – fully async/await compatible
  • Modular structure – clean separation of client, models, and errors
  • Context-managed sessions – automatic setup/teardown
  • Built-in rate limiting
  • Meaningful error hierarchy
  • Retries on transient failures (planned)
  • Extensible – easy to plug into your existing bot framework

Installation

pip install pollcord

Or if you’re testing locally / from source (should work right now):

git clone https://github.com/<yourname>/pollcord.git
cd pollcord
pip install -e .

Quickstart

Here’s a minimal example showing how to create and end a poll.

import asyncio
from pollcord import PollClient

TOKEN = "your_bot_token_here"

async def main():
    async with PollClient(TOKEN) as client:
        # Create a poll
        poll = await client.create_poll(
            channel_id=123456789012345678,
            question="What should we build next?",
            options=["Mega base", "PvP arena", "Mob farm"]
        )
        print(f"Created poll: {poll.message_id}")

        # Fetch results
        votes = await client.get_vote_counts(poll)
        print("Current votes:", votes)

        # End the poll manually
        await poll.end(client)
        print("Poll ended!")

asyncio.run(main())

Architecture Overview

Pollcord is built around three core layers:

Layer Description
PollClient The main entry point — handles auth, rate limiting, and session context
Poll A high-level model representing a poll, with helper methods for interacting with it
errors Custom exceptions with Discord response context for debugging

Testing

Tests are written with pytest and use async mocks for API responses. Run them with:

pytest -v

Covered:

  • Poll creation
  • Fetching poll data
  • Ending polls
  • Error handling

Example Scripts

See the examples/ directory for working demos:

  • basic.py — Basic poll creation, termination, and vote fetching
  • concurrency.py — Demonstration of concurrent poll handling
  • rate_limit.py — Demonstrates rate limit handling
  • lifecycle.py — Poll creation and periodic fetching of data

Logging

Pollcord uses Python’s built-in logging module. You can enable debug output to trace requests:

import logging
logging.basicConfig(level=logging.DEBUG)

Roadmap

  • Documentation that doesn’t completely suck :sweat_smile:
  • Request queuing

Contributing

Contributions are welcome! If you’d like to help with tests, documentation, or feature ideas:

  1. Fork the repo
  2. Create a feature branch (git checkout -b feature/my-improvement)
  3. Submit a PR with clear commit messages

Support


License

MIT License © 2025 [Myst1cS04p]
This project is unaffiliated with Discord Inc.


Credits

Inspired by real bot-development pain.
Developed by Myst1cS04p
Development assistance by Github Copilot
README, examples, and tests written by ChatGPT cuz I'm lazy

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pollcord-0.1b2.tar.gz (10.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pollcord-0.1b2-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file pollcord-0.1b2.tar.gz.

File metadata

  • Download URL: pollcord-0.1b2.tar.gz
  • Upload date:
  • Size: 10.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.2

File hashes

Hashes for pollcord-0.1b2.tar.gz
Algorithm Hash digest
SHA256 1763e2ef9b29a63eaed0535a919a620731199e8438210728988af8f8bfe49adf
MD5 e5dbea5b24c5075133c336423bc25ade
BLAKE2b-256 32c0932b3290f3b5648c801048553b36802463c814803197e94113e975ef0365

See more details on using hashes here.

File details

Details for the file pollcord-0.1b2-py3-none-any.whl.

File metadata

  • Download URL: pollcord-0.1b2-py3-none-any.whl
  • Upload date:
  • Size: 8.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.2

File hashes

Hashes for pollcord-0.1b2-py3-none-any.whl
Algorithm Hash digest
SHA256 5f0103fec1283adb99c6a5f9fe55093290e903e2431be7197d5d06a84ba9e83e
MD5 6b9ec85b445a963d1538a86e4bca00db
BLAKE2b-256 9d8a48eb87cbbf5096cc69d41d04a395af896b6170331d281bc323d08a574c4e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page