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
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
My rule of thumb is that if whatever happens in the interaction could take longer, I defer.
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.like preparing an Embed, ComponentsV2 messagethat's by no measure heavy processing
do not defer or reply if you need to show a modalyou cannot defer modal responses
and you'd definitely reply when doing pagination, your reply would be the update
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 π