DiSky DiSky v5.0.0-b1

Polls

guide

Read a poll attached to a message, list its voters, end it early, and react when someone votes.

messagespolls

This page covers a poll that is already on Discord: read its question and answers, list who voted, end it before its deadline, and react to votes as they come in. Sending one is covered in creating polls. You're assumed to have a bot named "my-bot" logged in and to know how to read a message.

How polls work

tells you whether a message carries one; when it does, the message gives back a messagepoll with a poll question and a list of poll answers, along with , and .

on message received seen by "my-bot":
    if event-message has a poll:
        set {_poll} to poll of event-message
        reply with "%poll question of {_poll}%"
        loop poll answers of {_poll}:
            reply with "%answer text of loop-value%: %answer votes of loop-value% votes"

Answers

Each element of poll answers is a pollanswer.

Property

Returns

the option's text

the number of votes it has, as a plain number

the emoji shown next to it, if the poll has one; none otherwise

its number, from 1 in the order the answers were declared

whether the bot itself voted for it

answer votes never needs await: the count travels with the message itself, not a separate fetch. answer emote prints as the emoji itself, so it can go straight into a message.

on message received seen by "my-bot":
    if discord content of event-message is "!poll-winner":
        set {_poll} to poll of event-message
        set {_best} to first element of (poll answers of {_poll})
        loop poll answers of {_poll}:
            if answer votes of loop-value > answer votes of {_best}:
                set {_best} to loop-value
        reply with "leading: %answer text of {_best}% (%answer votes of {_best}%)"

Listing voters

lists the users who picked one answer. The answer is a pollanswer or its answer id; the message is the one carrying the poll, not the poll itself. The list is fetched from Discord, every page of it, so the line requires await.

on message received seen by "my-bot":
    if discord content of event-message is "!voters":
        set {_m} to {poll::release}
        loop poll answers of (poll of {_m}):
            await set {_voters::*} to the voters of poll answer loop-value of {_m}
            reply with "%answer text of loop-value%: %{_voters::*}%"
            delete {_voters::*}

{poll::release} holds a message sent from a message builder, the only way to keep the poll's message. An answer number the poll does not have is a readable error (this poll has no answer numbered <n>).

expression Poll VotersCore · Expressions[the] [poll] voters of [poll] answer %number/pollanswer% (of|in|from) [the] [message] %message%The users who voted for one answer of a poll. The answer is a poll answer object or its number (answers are numbered from 1 in the order they were declared); the message is the one carrying the poll, not the poll itself. Every page of voters is fetched.list of Usersince 5.0.0-a2

Ending a poll

closes a poll before its deadline; nobody can vote on it after this runs.

on message received seen by "my-bot":
    if discord content of event-message is "!end-poll":
        end the poll of event-message

is true once the poll's deadline has passed and no more votes are accepted; is true once Discord has settled the vote counts as definitive, which end the poll of also does immediately. end the poll of refuses a message with no poll, and a poll that is already expired or finalized.

effect end pollMessageend [the] poll of [the] [message] %message% [now]Ends the poll attached to a message immediately, preventing any further vote.since 5.0.0-a1

Vote events

and fire per vote. event-message, event-member and event-user are fetched from Discord before the trigger starts, so none of them need await (see cache and await); event-member is none for a vote cast in a DM.

Event

Values

on message poll vote added

event-channel, event-guild, event-member, event-user, event-message

on message poll vote removed

event-channel, event-guild, event-member, event-user, event-message

on message poll vote added seen by "my-bot":
    send "%event-user% voted on a poll in %event-channel%" to console

Neither event says which answer was voted on: only who voted, and on which message. Read the voters of each answer if you need to know which option changed.

event Poll Vote AddEvents[message] poll vote add[ed]Fired when a user adds their vote to a poll in a message.since 5.0.0-a1

Errors you may see

Message (console)

Cause

Fix

IllegalStateException: this message carries no poll

end the poll of was called on a message with no poll attached

Check first

IllegalStateException: this poll is already over

end the poll of was called on a poll that is already expired or finalized

Check is expired/is finalized before calling it, or only call it once

Message Poll type 7 syntaxes The Message Poll entity and its Skript syntaxes.
Was this page helpful?
An unhandled error has occurred. Reload 🗙

Rejoining the server...

Rejoin failed... trying again in seconds.

Failed to rejoin.
Please retry or reload the page.

The session has been paused by the server.

Failed to resume the session.
Please retry or reload the page.