Skip to content

Creating Polls

In Seyfert, the ability to create polls is just around the corner!
This section shows the basic creation of polls, events and examples.

This is an extended section of the configuration file.

seyfert.config.js
module.exports = config.bot({
//... other options
intents: ['GuildMessagePolls', 'DirectMessagePolls'],
});

Receiving Events

Currently there are 2 events for polls: messagePollVoteAdd and messagePollVoteRemove.

addVote.ts
export default createEvent({
data: { name: 'messagePollVoteAdd' },
run: (data) => {
//You can do whatever you want with the data
console.log(`The user: ${data.userId} added a vote to the poll: ${data.messageId}`);
},
});

Ending Event

The way to check when a poll is ended is to use the messageUpdate event.

Here is a quick example that edits the message when a poll is completed:

messageUpdate.ts
export default createEvent({
data: { name: 'messageUpdate' },
//This is [oldMessage, newMessage]
//But in this example we only need newMessage
run: ([, newMessage]) => {
if (newMessage.poll?.results?.isFinalized) {
console.log(`The poll with the id: ${newMessage.id}'s ended`)
}
},
});

Commands

Quick examples on how to create a poll and how to end it.

It’s suppose you have the following directory structure:

  • src
  • Directorycommands
    • Directorypoll
      • start.command.ts
      • end.command.ts
      • parent.ts
  • index.ts
  • seyfert.config.js
  • package.json
  • tsconfig.json
poll.parent.ts
import { AutoLoad, Declare, Command } from 'seyfert';
@Declare({
name: 'poll',
description: 'Poll command!',
})
@AutoLoad()
export default class PollCommand extends Command {}