JohnnyJayJay / instant-poll

A Discord bot that lets you create polls in your server
MIT License
42 stars 9 forks source link

Polls can't be closed properly after more than 15 minutes #2

Closed JohnnyJayJay closed 3 years ago

JohnnyJayJay commented 3 years ago

When a poll is open for longer than 15 minutes, its message option and "Close Poll" buttons are not removed anymore. The poll is closed and you won't be able to vote anymore, but this is confusing from a UI standpoint.

Limitations

Unfortunately, this is not a bug in this code, but a Discord limitation, because interaction tokens expire after 15 minutes. There is one workaround, but it requires the bot to be part of the server (i.e. to be invited through the bot OAuth2 scope). Then it is possible to edit the poll message by its message id.

Close Poll Behaviour

For the "Close Poll"-button, one nice way to integrate this behaviour would be to simply send both a request through the interaction token and the message id, both requests attempting to remove the message components. That way, it would still work like before if the bot is not a member of the server but additionally also work at any time if the bot is a member of the server.

Auto-Close Behaviour

The trickier question is how this should work for auto-closing polls. It would still be done through the message id of course, but it is not clear what the best way is to actually obtain that message id. When the poll time runs out, there is nothing that provides the id (unlike when someone clicks the Close Poll button, which includes the message object). So far, I see two ways to obtain the message id ahead of time:

JohnnyJayJay commented 3 years ago

An alternative for the "Close Poll" button that's probably better: Instead of responding to the interaction with "@ user closed this poll", an Update Message response could be sent that removes the components and notes who closed the poll in the edited message content. That way, the bot need not be in the server.

JohnnyJayJay commented 3 years ago

Closed by #11