Files
Discord.Net/docs/guides/polls/polls.md
Mihail Gribkov 3e7ab0915f [Docs] Document Polls (#2930)
* poll docs

* oopsie
2024-05-27 14:50:38 +03:00

1.9 KiB

uid, title
uid title
Guides.Polls Polls

Polls in Discord.Net

Polls are... Polls!

example poll

This guide will explain how to use polls in your applications.

Note

To get contents of polls sent by users other than your bot you need to enable GatewayIntent.MessageContent intent.

Creating polls

A poll is part of a message; to send one you need to pass a PollProperties object into the poll parameter of any method that can be used to send messages. (ex. SendMessageAsync, RespondAsync, etc)

[!code-csharpCreating polls]

Warning

Due to limitations of the Discord API it's not possible to send attachments in a messages with a poll.

Note

It is not possible to modify polls after them being created.

Managing polls

Ending polls

You can expire polls early by calling EndPollAsync on an IUserMessage with a poll.

[!code-csharpEnding polls]

Getting poll answer voters

To get voters for a specific answer call GetPollAnswerVotersAsync(answerId) on an IUserMessage with a poll.

[!code-csharpGetting poll answer voters]

Retrieving poll results

You can get results of a poll by simply getting an IUserMessage and checking the IUserMessage.Poll.Results property. Alteratively you can check the results on a MessageUpdated gateway event.

Gateway events

Poll votes

You can receive information about poll votes live using following events:

  • PollVoteAdded
  • PollVoteRemoved

Note

These events are only sent if the client has GatewayIntents.GuildMessagePolls or GatewayIntents.DirectMessagePolls intents enabled. It will receive events for polls in guild or dm channels respectively.

Poll expiry

On poll expiry the MessageUpdated event is fired.