Skip to content

Support for Polls #130

@PedroANeves

Description

@PedroANeves

Polls were introduced in discord.py version 2.4 (docs reference), allowing bots to send messages with polls using the poll keyword argument and access them via Message.poll.

Currently, dpytest does not support this. When testing a command that sends a poll, get_message().poll always returns None, even though the bot runs fine when executed normally.

Minimal reproducible example:

from datetime import timedelta
import discord
from discord.ext import commands
from discord.ext.commands import Cog, command
import discord.ext.test as dpytest
import pytest
import pytest_asyncio


class Misc(Cog):
    @command()
    async def pollme(self, ctx):
        poll = discord.Poll(question="Test?", duration=timedelta(hours=1))
        poll.add_answer("Yes")
        await ctx.send("Poll test", poll=poll)


@pytest_asyncio.fixture
async def bot():
    intents = discord.Intents.default()
    intents.message_content = True
    b = commands.Bot(command_prefix="!", intents=intents)
    await b._async_setup_hook()
    await b.add_cog(Misc())
    dpytest.configure(b)
    yield b
    await dpytest.empty_queue()


@pytest.mark.asyncio
async def test_poll(bot):
    await dpytest.message("!pollme")
    message = dpytest.get_message()
    assert message.content == "Poll test"
    assert message.poll is not None  # Fails: poll is None

Expected behavior:
message.poll should return a discord.Poll object matching the sent poll.

Actual behavior:
message.poll is always None.

Environment:

  • discord.py: 2.5.2
  • dpytest: 0.7.0
  • Python: 3.12.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions