State management

I'm building a bot and am wondering the best way to manage state within the app? For example, once a user executes a command we begin a flow that asks them various questions and then will provide them with a custom message at the end based on all of the answers they've given. Is there a standard to maintain state in discord.js that will allow us to keep all these answers? Thanks!
8 Replies
d.js toolkit
d.js toolkit2y ago
• What's your exact discord.js npm list discord.js and node node -v version? • Post the full error stack trace, not just the top part! • Show your code! • Explain what exactly your issue is. • Not a discord.js issue? Check out #useful-servers.
Squid
Squid2y ago
When the interactionCreate/messageCreate event emits, you can treat everything within that event listener's callback function as one state Just handle everything within that one callback function, and you can assume the state hasn't changed
h3rm3s
h3rm3sOP2y ago
Oh yeah that does sound like it would work. I'm going to try that out now. Thanks!! If I have any issues with that can I tag you on this thread? 😄
Squid
Squid2y ago
Sure thing, good luck!
h3rm3s
h3rm3sOP2y ago
🙏 @Squid Is there any way to use this across events? Like for example I'm using buttons to get input from the user but I want to use a ◀️ reaction as a "back" button. So the majority of the logic is in interactionCreate and so that works fine for state management, but in order to use a reaction I need to use messageReactionAdd and then it won't have the state anymore
d.js docs
d.js docs2y ago
Suggestion for @h3rm3s:guide Popular Topics: Reaction collectors read more
Squid
Squid2y ago
You can use this in the interactionCreate event listener so you can access both the interaction and the reactions in the same place
h3rm3s
h3rm3sOP2y ago
Cool I'll check that out thanks
Want results from more Discord servers?
Add your server