Poll

The Poll class builds a native Discord poll payload that you can attach to any message or interaction reply.

Creating a poll

JavaScript
const { Poll } = require("syntx.js");

const poll = new Poll({
  question: "What's your favorite season?",
  answers: ["Spring", "Summer", "Autumn", "Winter"],
});

Options

OptionTypeRequiredDefaultDescription
questionstringYesThe poll question. Truncated to 300 characters.
answers(string | { text, emoji })[]Yes1 to 10 answers. Each answer's text is truncated to 55 characters.
durationnumberNo24How long the poll stays open, in hours (1768, i.e. up to 32 days).
multiplebooleanNofalseWhether voters can select more than one answer.

Warning

More than 10 answers, an empty answers array, or a duration outside 1–768 throws a SyntxError as soon as you call new Poll(...).

Answers with emoji

Pass an object instead of a string to attach an emoji to an answer:

JavaScript
const poll = new Poll({
  question: "Pick a game mode",
  answers: [
    { text: "Casual", emoji: "🎮" },
    { text: "Ranked", emoji: "🏆" },
  ],
  multiple: true,
  duration: 48,
});

build()

Returns the raw poll object expected by discord.js's poll send option.

JavaScript
channel.send({
  content: "Vote now!",
  poll: poll.build(),
});

Tip

It also works in an interaction reply: interaction.reply({ poll: poll.build() }).

Note

Polls are a native Discord feature; Discord closes the poll automatically once duration elapses. syntx.js does not run any timers of its own for this.