#Issue with deferring replies
1 messages · Page 1 of 1 (latest)
I haven't yet, I'm not sure whether it's to do with the host server having high ping (it usually has about 200ms as I use a UK based host) or whether Discord's having any issues (I don't think they are). It's weird that it's only tonight and also that I've not changed any code
same issue man i am using digital ocean and tonight only i am having this issues
sometimes it not even register
Two things to say about deferred replies though:
1: Make sure there's nothing in the brackets (like: interaction.deferReply()) as I've already said
2: Make sure that deferring the reply is the first thing you do in code. Example here:
async execute(interaction) {
await interaction.deferReply()
<some code here>
interaction.editReply("Some content here")
}
okay so not even store things in variables at first
like this as i have some variables before it
No, I have it right at the very top. Just to avoid as many issues as possible. Although I'm using deferReply right(must be doing as I've had no issues before this) and still having some issues
But try that first
done lets see that
at the host i am trying to run it not even showing that it logged in
Just wait a bit first. I really want to know whether this is more widespread and an issue with Discord or not
see still it complaining about those lines
Weird. My host has been doing that where I start and it does that a couple of times, I have to restart. Then it just fixes. And then if I have to restart again then it does it again
Just tonight as well
yep same process
really give me a stress for rest of the day :c
you're using digital ocean?
i am using digital ocean standardised plan
Even more stress for me as I'm waiting for my bot to be approved for top.gg. Error only happened after I submitted as well. I'm worried that it'll cause issues when being tested
no, danbot.host . UK-based host
idk what should i do now
I've switched some of my commands to just reply (No defer and edit) and it works kinda, for the time being until I can fix it
however i am using pm2 and forever to make it active
I'm not using those and still having issues
have you tried using your old code (without changing to reply) in another machine to see if it works just fine?
that's what happens with my (similar) issue. it works perfectly ok, same code, if i run it on my dev machine over my raspberry pi
Yep, works fine on my local machine with my testing bot (same code as other one but with editReply), just not working on a host I use
if i try to see from my testing bot it works fine no issue but it only happens with the bot that is hosted
Add logs into your code to see what’s taking so long. The issue is literally either too much compute and not done quick enough to reach the reply, or your connection just isn’t strong enough to initially reply
There’s no other reason
I've also just tested on my local machine with the same bot (not an alternative testing one) and works fine, just the when used on the host. Weird as the other people having this issue are using different hosts. I'll try adding logs though
okay so i think it is working now
what i did was i reboot my host
its working now @elder rose
and without defer my bot will broke because it needs it to generate response as it will take time on that
That’s the thing, things which need time to do you need to accommodate for
Anything which requires a db fetch I defer
I added logs. There's like a 600 millisecond difference between the log below where I have deferReply and the one just before I edit the reply, but it gets stuck on defer. I also have a log just after the edit reply and that one isn't sending. For some reason when on the host it doesn't edit, when on my PC it works fine. It also worked on the host fine until tonight
same shit that happens to me. no issues if trying on another machine, but gets stuck in the same command every time on the usual machine
Add a log inside the interactionCreate file, at the top, then inside the catch, also inside the execute function and after you defer
Something is taking too long somewhere
The api won’t die on you that easily 😉
Now it shows all 4 logs, even the one after editReply but it doesn't edit. But I'll add some in the interactionCreate
It just doesn’t edit?
It defers, it also logs the time after the edit but doesn't edit. I just did a test now, it takes about 4 seconds between the first and last log though
maybe also await the editReply due to it being a promise and may not resolve
maybe
4 seconds is weirdly… Hugh
High*
Just as the other guy, that’s just showing an embed and some buttons which is weird
For a help command too. No issues before tonight too with no code changes. The host usually has high ping (about 200ms) due to it being UK-based but that's never caused any issues before
it is happening again now 😭 man should i giveup?
Show the code
You reply after you have replied
Do you have any error handling which responds with a reply
Ok just did another test, with await editReply. 1 second delay between first and last, final log after editReply doesn't come through as the await editReply must've not happened
Now 5 seconds with another test, same code. It seems varied. Although final log still not gone through
Why do you deferReply() then .reply() here
I changed it, the code didn't save properly
Ah
no, it still doesn't edit. Last log doesn't come through. Still a delay I think between first and second last log though for some reason
@humble stone
It complains about the lines in these two files 1st file - line no. 16 2nd file line no. -
https://gist.github.com/whizzbbig/91ce7b39d8736b5d25df1fece03bca9b
https://gist.github.com/whizzbbig/b0e742e5e6d1ec97b656d66eb1c4cde8
@digital root hey man, what’s your thoughts about this? Nothing seems to be wrong code wise
Just another thing to note, might be unrelated but it does this for a couple of tries, then restarts like a third time then doesn't crash but does the no edit reply thing
Like it does that, restarts, does it, restarts then works with no crash but no editReply
Something isn’t saved
As that’s an unknown interaction coming from a reply…
What’s help.js line 48
now I'm confused with what the problem is
is it that it's deferring and not editing
The await editReply
Nah that’s an error coming from a reply
help.js line 48
Something either isn’t saving on your end or it’s not the code we are seeing
I don't even know the problem 
If I change it to reply, not editReply and no defer it works. But when I do defer and edit, it doesn't work. Like the other guy said, only tonight
so it's deferring, but not editing the reply?
yeah
I find it pretty weird considering it’s only sending an embed and some buttons
Please add the following code to your code base outside of any other event listeners and provide the full log output relevant to your issue.
client
.on("debug", console.log)
.on("warn", console.log)
• Note: if you initialize your Client as bot or other identifiers you need to use these instead of client
• If the output is too long to post consider using a bin instead: gist | paste.gg | sourceb.in | hastebin
have you done this
no
do it, send output
yes
where, in help command or interactionCreate?
outside of any other event listeners
Wherever you have access to your client, probs index.js
ok
do it right after creating the client
done
Output?
yes

is it meant to say something about shards?
Send the output
wdym
send the output
1066ms 
is that after the command is run
no, I've just started the bot with no commands. Every interval now it's saying about 200ms, what I usually see on the host as its in the UK so far from Discord
on command it shows error
after running the command it shows 300ms which i assume normal
What error
It's finally replying. I'll do some more testing. Although pretty big delay (like 12 seconds for a help command...)
thisss
are you logging the interactions in anyway before executing their commands?
• DiscordAPIError: Interaction has already been acknowledged
• [InteractionAlreadyReplied]: The reply to this interaction has already been sent or deferred.
You have already replied to the interaction.
• Use <Interaction>.followUp() to send a new message
• If you deferred reply it's better to use <Interaction>.editReply()
• Responding to slash commands / buttons / select menus
i was and removing that made everything work like normal after
i lose logging but now i don't need to change all my code
This is for @strong juniper
I'm currently doing Date.now() to check for delays if that's what you mean
no, that's not what i mean. do you do literally anything with the interactions before executing the commands?
You can use console.time() and console.timeEnd()
despite the fact i awaited the command execution, my logging took so long that i blocked the actual important reply
I'm doing defer, create the embed and buttons, editReply to send them. No logs other than time logging for troubleshooting
i had to comment out my logging and now it works like it used to
i don't timeout to handle interactions anymore, despite this not being awaited and also being placed BELOW the await execute command
so your interactionCreate doesn't do anything else other than loading the relevant command, yes?
yes
I am doing the right way @humble stone
i understand. sorry for not being able to help you any further then
You definitely aren’t
module.exports = {
data: new SlashCommandBuilder()
.setName('askme') // set the name of the command to /askme
.setDescription('Replies with a response generated using the OpenAI API')
.addStringOption(option =>
option.setRequired(true)
.setName('input')
.setDescription('The input to use to generate the response')),
async execute(interaction) {
// send the initial "thinking" message using deferReply
await interaction.deferReply();
// get the value of the input option
const input = interaction.options.getString('input');
prompt += `You: ${input}\n`;
// use the OpenAI API to generate a response based on the input using Chat GPT - 3
const response = await openai.createCompletion({
model: "text-davinci-003",
prompt: prompt,
max_tokens: 360,
temperature: 0.5,
top_p: 1.0,
});
await interaction.reply('pong')
// reply to the user with the generated response
// await interaction.reply(`**input: ${input}**\n\n${response.data.choices[0].text.substring(5)}`);
prompt += `${response.data.choices[0].text}\n`;
console.log(prompt);
},
};
this is the code that is doin the thing
now what i am doing wrong there?
you have to edit replies too with defer, you did await interaction.reply("pong"), not editReply("pong")
So you reply like 3 times
It's annoying because it just worked then but then I tried again and it didn't edit
thanks for the help guys we fix the error by creating another error and fixing it
weird that i am getting error in the console but things are working fine
good that it's kind of fixed for you. Still no clue what's wrong for me though
I did a bit of testing without .editReply or .deferReply and just with .reply as it works with that and found that with .deferReply and .editReply between the first and last log it had a delay of 600ms to a couple of seconds and with reply it had a delay of 3-4ms. So with defer and edit it had a way bigger delay, no other code changes
Surely that's more of an increase of delay by just putting defer in than normal, or does defer and edit do that (make a big delay)?
I asked in the main Discord Devs server whether it was an issue with them or they knew how to fix it and the only thing they said was that I could try editing with https://discord.com/api/webhooks/${interaction.application_id}/${interaction.token}/messages/@original using the patch method. How would I do this in djs? I'll also continue to monitor to see whether it fixes tomorrow
Iirc that’s just interaction.webhook.editMessage()
Would also be nice to know your exact djs version
That delay is due to you awaiting the response for the deferReply before continuing with the code to then await your editReply later on. To have a real comparison you‘d need to measure the time you need to reach the point before your editReply call and compare that to reaching the point after your reply call in the other case
Thanks Qjuh
14.7.1
That makes sense. Any clue why it's not editing the deferred response though
Do both of the bottom console.logs happen?
Can you show how you execute commands inside your interactionCreate file
Or event rather
Do you have an error handler catching errors? And if so does it catch one in those cases? And how active is your bot (how many interactions per second/minute/hour?
No, I should definitely make one at some point soon. My bot is barely active, only when I'm testing it really so far
So your bot crashes when interaction fails?
No, it just gets stuck on defer (not is thinking...)
Then you catch the rejection somewhere…
Sorry for the bad screenshot, I'm on mobile rn
That is a catch and an error handler right there
How long are you waiting for an error before turning the bot off again?
I waited nearly an hour over dinner while it was running and no error
But the deferReply was still there? No editReply happened either?
Yeah it stayed on defer reply for that hour with no edit, and no error in console
We'll tbh I'm pretty sure it times out after 15mins with defer so it timed out
That’s an essential difference… did you get an error because the interaction wasn’t valid anymore or did you get nothing?
I got no error in console if that's what you mean. It stayed on defer
That… shouldn’t happen ever… you should either get a rejection from the editReply call or it should resolve (and have successfully edited the reply by then). Did you await the editReply always?
Yeah I awaited the editReply
As I Said, then this should be impossible…
Please add the following code to your code base outside of any other event listeners and provide the full log output relevant to your issue.
client
.on("debug", console.log)
.on("warn", console.log)
• Note: if you initialize your Client as bot or other identifiers you need to use these instead of client
• If the output is too long to post consider using a bin instead: gist | paste.gg | sourceb.in | hastebin
I've done that, it's pinging back around 200-300ms each time
That’s not what I‘m interested in… the heartbeats are irrelevant… are there any other debug logs besides the heartbeats happening?
Oh, might have to add it on client.rest to get the interesting ones
client.rest.on('response', console.log)
Those will spam your console, so be prepared😂
That was directly after logging in… not waiting 15 minutes after a deferReply though
Where should I put this then? In index or in the help command?
Oh yh we gotta love those
Index
Anywhere outside of other event handlers
What should I send? All of it?
Probably lmao. There’ll be a lot
Probs only me who saw it and tbh I don’t care lol
Ok, still I'll reset and send
You should reset either way
And only the requests with interaction in its URL should be relevant
set-cookie lol
Here's what happens if I run the command. Stuck on defer again
Did the editReply succeed?
Oh it did now. I'll try it again a couple of times
Is there supposed to be some kinda error being thrown here?
There is supposed to be a response from the API at least, if the call doesn’t reject… and if the interaction still shows as deferred then the response from the API should tell us why, yes
Ahhh ok thank you
Imagine it just works now and I just bought Qjuh here for no reason 😭
I‘m not for sale😳
Oh, it broke again...
Did the logs show anything juicy 😋
Well one cookie expired on the Unix epoch, I wouldn't eat that now
Expire=0 means just never
Probably better to show them here haha
That’s just how the logger parses that. Undici should know better how to interpret 0 I hope
I’m just confused as this has to be something to do with their code, right? No offence lads. Because this error would have 100% happened before
I do get this every couple of restarts but then it just goes and works (apart from the defer thing) until it does it again
But I restart a couple of times and it goes
You could also filter the response for response.route.includes('webhooks') to reduce the amount you need to look through
Ngl these are errors I typically get whenever I double host my bot…
The second error is from you trying to followUp with your error message although you couldn’t reply in the first place…
Nah, then you get already replied
Yeah thought so
Oh yea not been sent
Those you have there are classic replies too late errors. Those are common and need to be expected and handled. The one where it defers but never edits, that one is weird
I'm gonna have to come back to this in the morning as I don't have access to my pc rn and its late
No worries dude
How would I handle those errors? Being as my current error handler doesn't seem to catch them. I'll also do some testing today and change some stuff
What errors?
The replies too late ones
As it seems to catch the ones where you reply too late
It crashes the bot when that happens for some reason
It does, you just try to followUp to them which produces another error… don’t followUp if interaction.replied is false
Rule of thumb: don’t try to use the mechanism that causes your error to do something else with it…
Ok I'll see if I can add that in. I've just moved some local files onto the host to see if that works
So same error, even when uploading my local files which work to the host but it did log this
And did it successfully edit the reply? And what does the status on that response say (scroll down)?
This? And no it didn't edit
Even below that. I‘m looking for statusCode and the response itself
Status code: 429
What's the cooldown until I'm not? And is this an issue with the host or just my server on the host (I'm assuming just my server)
Change the response listener to rateLimited listener. And this looks like it already passed (was about 3 seconds only)
Ok I changed that and I'm pretty sure it now works, it's editing them but it's just taking ages (like 5 seconds). The replies too late errors are also being handled now
Not sure if it's working with all commands though, I'm still testing that
It worked for a tiny bit and then I added both the rateLimited and response listeners and it said 429 again and won't edit. It like logs, says status code 204 then logs again without me putting in another command saying 429
When I use interaction.reply() and no defer it logs status code 204, no 429
So:
interaction.deferReply() and interaction.editReply() = status code 429
interaction.reply() = status code 204
Umm, that is a one-time editReply on one interaction? Or are you spamming your bot with interactions? Are there other bots running from your network?
And the 204 before the 429, is that from the deferReply call or do you get a 204 for the edit and then a 429 for the same request data?
Well it's an online host so yeah there are other bots on the same node but not my server. I'll check to see if there's any interaction spamming in my code but I don't think there is
If they are running on a different IP and server that shouldn’t affect it. Is it a real seperate VPS or is it some bs like replit has?
It's not a VPS, no, it's a host that uses shared nodes with Pterodactyl
Just looked into it, doesn’t look like something I‘d trust
So you get ratelimited because of all the other bots running on the same machine
Nothing to do with djs
I've been using it for a while and it works fine. It only started happening last night. Also I checked and its the defer (method POST) gives 204, edit (method PATCH) gives 429
Then probably someone started a new bot on that node that spams the API too much
I'll check in the host's support server and see if they can have a look
That’s the problem with shared hosts like that…
Yeah, any other free host I've tried doesn't work too well but obviously paid would be way better
Well, nothing’s free in this world… so if it tells you it’s free there’s always a catch
yeah. I could look into some other hosts but this one's been this best one I've tried so far. Well thanks for your help and I'll ask in their server to check for any abusers/api spammers
Okay? How is that relevant to them getting ratelimited?
oh, you didn't follow that we were having similar problems, right
it's not your job to know everything
they posted having similar problem to mine at #1059163759547011092
i thought whatever solution they got would be applicable to me as well, but no luck so far
all i get are 404s for interactions not existing, but messages get posted just fine
Messages as in the interaction‘s replies? Or regular Channel#send() ones?
yeah interaction.channels.(cache i think? then .get() i think?).send()
if i can't find the fix for this problem, I'll be forced to answer every interaction with 'interaction.channel.send()' instead of 'interaction.reply()'
man these errors are getting on my nerves
it was working very smoothly again smh but till this night
can't we have a proper permanent solution?
reply sooner
i'm rewriting my bot to not try replying to the interactions, it will just send messages in chat instead
maybe that will be the best option i see
but i've a quesiton here how i can edit the messages like this
That is API spam
huh
It spams api requests
but how could i achieve with discord.js
i am too noob to get what you're saying tho
It spams API with requests, which we will not support
oh
ohk but can't we get the permanent solution of this error we're getting and it is related to discord.js
how i can make it reply sooner when it is generating the response by itself
You can't always just 'reply sooner'. Some stuff like using an API to get stuff or image modifiers or something like that might just take longer than the 3 seconds non-deferred replies get, especially if the bot is a bit slow at the time. Although generally this shouldn't be an issue if you have relatively basic commands
if you reply or defer at the very top of your command, you won't have issues. problem just arises when not even that is enough, like my case
That's what I am having it works sometime but not most of the time
my issue went away entirely 4 days ago so i've just reverted back to interactions