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
• 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.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
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? 😄
Sure thing, good luck!
🙏
@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 anymoreYou can use this in the interactionCreate event listener so you can access both the interaction and the reactions in the same place
Cool I'll check that out thanks