Skip to content

Creating Polls

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

This is an extended section of the configuration file.

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

Receiving Events

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

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

Ending Event

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

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

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

Commands

Quick examples of 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
1
import { AutoLoad, Declare, Command } from 'seyfert';
2
3
@Declare({
4
name: 'poll',
5
description: 'Poll command!',
6
})
7
@AutoLoad()
8
export default class PollCommand extends Command {}