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
"@sapphire/decorators": "^6.0.1",
"@sapphire/discord.js-utilities": "6.0.7",
"@sapphire/framework": "^4.4.3",
"@sapphire/plugin-i18next": "^5.0.3",
"@sapphire/plugin-logger": "^3.0.3",
"@sapphire/utilities": "^3.11.1",
"@skyra/env-utilities": "^1.2.0",
"@skyra/i18next-backend": "^2.0.3",
"colorette": "^2.0.20",
"discord.js": "^14.10.2",
"moment": "^2.29.4"
"@sapphire/decorators": "^6.0.1",
"@sapphire/discord.js-utilities": "6.0.7",
"@sapphire/framework": "^4.4.3",
"@sapphire/plugin-i18next": "^5.0.3",
"@sapphire/plugin-logger": "^3.0.3",
"@sapphire/utilities": "^3.11.1",
"@skyra/env-utilities": "^1.2.0",
"@skyra/i18next-backend": "^2.0.3",
"colorette": "^2.0.20",
"discord.js": "^14.10.2",
"moment": "^2.29.4"
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....
Jump to solution
1 Reply
Solution
Favna
Favna12mo ago
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.