Best way to stay in the same context with awaitModalSubmit?

When I use <CommandInteraction>.awaitModalSubmit(), does the filter automatically make sure that it's a modal that was opened in the same context as the command, in any way? If not, my idea was to filter on user and customId to make sure I stay in the same context, as seen below.
// assuming I invoked interaction.showModal() with customId = "modal" prior to this
// "member" is the member that invoked this command
await interaction.awaitModalSubmit({
time: 1000 * 60 * 5, // 5min
filter: x => x.customId === "modal" && x.member?.user.id === member.id,
});
// assuming I invoked interaction.showModal() with customId = "modal" prior to this
// "member" is the member that invoked this command
await interaction.awaitModalSubmit({
time: 1000 * 60 * 5, // 5min
filter: x => x.customId === "modal" && x.member?.user.id === member.id,
});
Is there a better way of achieving this?
10 Replies
d.js docs
d.js docs3y 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.
LeMorrow
LeMorrowOP3y ago
None of the examples I've seen filter on member, only on customId, that's why I'm curious if there's something I'm missing Isn't there a risk that another user could "hijack" the command if they submit a modal with the same customId without the member filter?
Seren_Modz 21
Seren_Modz 213y ago
if the member is null, the filter won't work as it will return false so it'd be better to directly access the user instead of going through the member
LeMorrow
LeMorrowOP3y ago
Good point, thank you 👍 But in general you have to filter on userId?
Seren_Modz 21
Seren_Modz 213y ago
member id and user id are both the same but since the user id always exists, its more common that users get filtered from the user id
LeMorrow
LeMorrowOP3y ago
Yea I just meant either In general you have to filter on user/member*? (the person that invoked the command)
Seren_Modz 21
Seren_Modz 213y ago
are u asking if filtering the user is required? if so, its not a requirement, however, if multiple people run the command at the same time, submitting could (i don't know for sure) conflict with other users responses
LeMorrow
LeMorrowOP3y ago
Yeah that was my question, and that's the answer I expected too Thank you again 👍
Seren_Modz 21
Seren_Modz 213y ago
my apologies for misunderstanding ur previous messages
LeMorrow
LeMorrowOP3y ago
nah it's my fault for using ambiguous wording and weird grammar haha I'll archive this post
Want results from more Discord servers?
Add your server