How to differentiate an defer interaction
Hi
I would like to know how I can differentiate the method used to defer the interaction since there is
deferReply
and deferUpdate
.
Is it even possible ? If yes, how because I only see one property deferred
set to true by both of the method ?
NodeJS : 18.x
DiscordJS: 14.14.15 Replies
- What's your exact discord.js
npm list discord.js
and node node -v
version?
- Not a discord.js issue? Check out #other-js-ts.
- Consider reading #how-to-get-help to improve your question!
- Explain what exactly your issue is.
- Post the full error stack trace, not just the top part!
- Show your code!
- Issue solved? Press the button!I'm not entirely sure why you need to, whats your situation?
Ok, I will try to explain it :
I listen to the "interactionCreate" event and call a function that depends on the ID of the button clicked. This function performs various tasks and may generate an error (unauthorized user, invalid parameter, etc.). This error is taken into account in the interaction creation event to send a response to the user, informing them of the system's status.
But when the function throws an error and I catch it, I call editReply or reply depending on the
deferred
property to display the error message. There are three possible scenarios:
- The function has never called a defer method: the behavior is correct.
- The function called deferReply()
before throwing an error: the behavior is correct.
- The function called deferUpdate()
before throwing an error: the initial message is updated with the error message, whereas I'd like to keep it and send another message containing the error.
I can provide you a little piece of code if it can help you 👍Gotcha, thanks
Whats the behaviour if you use
followUp
insteadIf I use
followUp
the behavior after a deferUpdate
is good (this is what I want) but not after a deferReply
:/
I would like to keep using editReply()
after a deferReply
but I would like to use followUp()
after deferUpdate
.
Here is a little piece of code that can help to understand the problem:
To be a little more precise for this:
but not after a deferReplyIt's because, DiscordJS throw an error if you are using
followUp
without a full reply
Maybe it could be interesting to add two property:
- updateDeferred
- replyDeferred
And change the deferred
property to a getter equal to updateDeferred || replyDeferred
Suggestion added in #Split "deferred" property in Interaction class in two, to better reflect previous actions in case there is no other way to do it
I forgot to answer and you was right, I don't know why in my previous tests the result was different
For real, I know: the problem was me and I surely made an error in my code 😂