'Need advice on architecture of a Discord bot

What is discord Role?

A role is a group created by server admins. The role has permissions, a hierarchy, and a name. What's essential in this case is that players can refer to multiple players at once ("ping" them) by referring to their role like this @RoleName.

Context

I'm developing a bot that issues temporary roles to users. Users take Roles so that others can ping them. A Role is given for the duration user's desires. The bot is being written in Go. The whole app primarily consists of handlers of both Mongo events and commands that users type to the bot.

Each time user takes a role by typing a command to the bot, the Discord id of that user is stored inside the Mongo database with expiration time. Once a time stored within the document is reached, the document is deleted by Mongo (TTL index is used for this). Then via handling Mongo events, the bot handles deletion by taking away roles from users. (Also, the user may remove his role preemptively. In this case, the role is being taken away and the corresponding record from the database.)

Question

When a user decides to remove his role, the Mongo deletion event handler is fired despite the user's record already being deleted inside the user command handler. So, I thought it was possible to control the bot exclusively inside Mongo's event handlers. Instead of giving and removing roles inside handlers corresponding to commands users gave, I can do so inside Mongo events. For example, to take away a role from the user, I need to remove his record from the database inside the command handler. Then role will be taken away automatically inside the corresponding Mongo event handler.

My experience does not let me foresee how this would affect future bot development, so I'm asking you for advice on this. Would this be a good idea? If not, what would be an excellent way to deal with Mongo handlers being fired in such cases as one above?

I suck at writing, so don't be shy to ask for clarifications.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source