Search code examples
pythonpython-3.xdiscord.py

Can discord bots create polls? (discord.py)


I want to add a poll functionality to my bot. However, I want to make the polls not like basic reaction ones, but like the ones users can create normally. Is there a way to do that? From what I've seen, in the docs, I can't find it, but I want to know if there still is a way to do so.

Edit: I have done digging (not in the docs) and I found a Poll class, but there is a lack of documentation in this regard or I might just not have seen it.

Edit edit: I tried using:

p = discord.Poll(question="idk", duration=timedelta(hours=1.0))
p.add_answer(text="1")
p.add_answer(text="2")
await ctx.send(p)

And it just sent: <Poll duration=1:00:00 question="idk" answers=[<PollAnswer id=1 media=>, <PollAnswer id=2 media=>]>

I don't really know what to do: How do I send it in a way that it would become an actual poll?


Solution

  • Polls need to be passed using poll keyword argument:

    p = discord.Poll(question="idk", duration=timedelta(hours=1.0))
    p.add_answer(text="1")
    p.add_answer(text="2")
    await ctx.send(poll=p)
    

    Reference