Need help persisting interaction data between consecutive interactions in Sapphire
Description
I'm currently working on a project using the Sapphire framework and I'm facing an issue with persisting interaction data between consecutive interactions. I would appreciate any guidance or advice on how to solve this problem.
Current Setup
- I have a slash command registered in Sapphire that makes a userSelectMenu.
- When the userSelectMenu is triggered, it generates a menu with selectable options for the user.
- Upon selecting an option from the userSelectMenu, a modal is created and displayed.
- The user can submit a form within the modal, triggering a modalSubmit interaction.
I need to access the user ID of the userSelectMenu within the modalSubmit interaction. However, since these interactions are separate and not directly connected, I'm struggling to find a way to pass and retrieve the user ID between them.
I'm wondering if there's a way to persist the necessary data (in this case, the user ID) between these consecutive interactions. Is there a recommended approach or best practice for achieving this within Sapphire?
versions
Solution:Jump to solution
There are no real best practises but your options pretty much boil down to using a cache of sorts. Either in memory by exporting some object, or a Collection (
import { Collection } from 'discord.js'
, which is just an extension of native Map
btw) or externally through a fast caching service like Redis.
Either. way they are all key/value storages so keys will be customids/snowflakes/etc whatever you can use to identify later, and values whatever data you want....1 Reply
Solution
There are no real best practises but your options pretty much boil down to using a cache of sorts. Either in memory by exporting some object, or a Collection (
import { Collection } from 'discord.js'
, which is just an extension of native Map
btw) or externally through a fast caching service like Redis.
Either. way they are all key/value storages so keys will be customids/snowflakes/etc whatever you can use to identify later, and values whatever data you want.