What are the best practices?

Using defer reply for all type of api and database calls ? Or should I use reply . Just want to figure out best user case of defer reply and reply System I am using Dedicated server from ovh rise 1 Database pg and redis All in local host and doesn’t have docker containers
8 Replies
d.js toolkit
d.js toolkitβ€’2w ago
Amgelo
Amgeloβ€’2w ago
generally you defer when the reply isn't immediate most commonly when you consult a database, a file, an api, etc which tend to be async calls
Spaxter
Spaxterβ€’2w ago
My rule of thumb is that if whatever happens in the interaction could take longer, I defer.
!                 𝐂𝐙‒ Solo
When handling ChatInputCommands, if the command is simple like '/ping's -> 'Pong!', it's better to .reply(). If the process is time-taking like fetching large data from Discord or your DB, etc. it's recommended to .deferReply() as soon as possible. Pros of deferReply: gives you extra 15 minutes to handle the interaction. Cons: it adds a little delay when using in short processes and may affect user experience. In case of components interaction: When handling short processes, do .reply() when handling long processes, do .deferReply() when handling a process which doesn't need to be replied to, use .deferUpdate(). This is helpful when making navigation buttons in an Embed or ComponentsV2 container. Also: do not defer or reply if you need to show a modal via the command or component. Modals cannot be shown via a replied or deferred interaction.
souji
soujiβ€’6d ago
like preparing an Embed, ComponentsV2 message
that's by no measure heavy processing
do not defer or reply if you need to show a modal
you cannot defer modal responses
Amgelo
Amgeloβ€’6d ago
and you'd definitely reply when doing pagination, your reply would be the update
!                 𝐂𝐙‒ Solo
I was thinking more into the fetching data from Database and Discord, but yes making simple Embeds and ComponentsV2 message don't take much time. I meant do not defer before showing a modal 😭

Did you find this page helpful?