DEV Community

Artem Tanyhin
Artem Tanyhin

Posted on

One finished Discord poll feature!

Hello there! This week, I worked on finally finishing the poll feature for Wego Overseer that I have talked about in my two previous posts. Make sure to check those out, too!

This week was not as easy as previous one, and some work required workarounds, so let me tell you more about it!

Where we left off

Last week, I implemented a simple voting using simple text and 3 hard-coded reactions. From that point I wanted to implement nicer poll message and custom emotes.

Using Discord embeds for nicer message

Embeds are card-like components from Discord.js that have Title, Description, Footer, Color, and such properties.

For nicer messages, I used embeds with question as a title and an optional description that the user might want to set as voting options explanation / elaboration / etc. As the Footer, I set user's avatar and name, as well as a timestamp.

Custom emojis

There was quite a lot of difficulties with setting custom emojis mostly because there are a lot of variations to check for. There are Unicode ones, Discord general ones, and guild ones (from a given server).

Since Discord emojis are not single characters, I used comma-separation for splitting the voting options. I then extracted emoji Id if it was from Discord (using client.emojis.find()), or used the entry itself, if it's a Unicode emoji, which were afterwards reacted to the message with.

If there was error parsing emoji, a separate ephermal message (i.e. only the poll creator can see) will be sent with those entries which couldn't be reacted with.

All of the code can be viewed here.

Some more work to do

After my initial commit, I wanted to implement voting using Discord buttons. They are much better-looking and allow for broader logic.

However, for implementing buttons, it is needed to design database entries and events, for which I sadly did not have time because of deadlines week at college.

After the busy weeks, I might actually come back to the feature to implement the buttons logic!

Top comments (1)

Collapse
 
tdaw profile image
TD

Nice work!