Catching an error and sending custom error

I don't know if I have phrased the title well, but is it possible to filter an error and make it custom? So what I mean is if I get an error DiscordAPIError: Interaction has already been acknowledged., can i make is so the bot will send a custom error instead of
Error handling interaction: DiscordAPIError: Interaction has already been acknowledged.
at RequestHandler.execute (/home/customaddress/bottest/node_modules/discord.js/src/rest/RequestHandler.js:350:13)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async RequestHandler.push (/home/customaddress/bottest/node_modules/discord.js/src/rest/RequestHandler.js:51:14)
at async ButtonInteraction.update (/home/customaddress/bottest/node_modules/discord.js/src/structures/interfaces/InteractionResponses.js:214:5)
at async Client.<anonymous> (/home/customaddress/bottest/modmail.js:1412:13) {
method: 'post',
path: '/interactions/1271880935536853082/aW50ZXJhY3Rpb246MTI3MTg4MDkzNTUzNjg1MzA4Mjp5eFdnU2hxSnUxWkN0c25Eclg3a05lc21GamxOaEVaejJTeFlhYTZicnVEUWFwTnYyalFLRXE0WmJQWXF0UTgyNnN0djhYZlV4RkRkSGhMd3RCcVljcjZzR3RNWUFzaEpINW1QSnZBOVQ3bkdCcUJoYmdLZTV4R1BNSzFSRHdRdA/callback',
code: 40060,
httpStatus: 400,
requestData: { json: { type: 7, data: [Object] }, files: [] }
}
Error handling interaction: DiscordAPIError: Interaction has already been acknowledged.
at RequestHandler.execute (/home/customaddress/bottest/node_modules/discord.js/src/rest/RequestHandler.js:350:13)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async RequestHandler.push (/home/customaddress/bottest/node_modules/discord.js/src/rest/RequestHandler.js:51:14)
at async ButtonInteraction.update (/home/customaddress/bottest/node_modules/discord.js/src/structures/interfaces/InteractionResponses.js:214:5)
at async Client.<anonymous> (/home/customaddress/bottest/modmail.js:1412:13) {
method: 'post',
path: '/interactions/1271880935536853082/aW50ZXJhY3Rpb246MTI3MTg4MDkzNTUzNjg1MzA4Mjp5eFdnU2hxSnUxWkN0c25Eclg3a05lc21GamxOaEVaejJTeFlhYTZicnVEUWFwTnYyalFLRXE0WmJQWXF0UTgyNnN0djhYZlV4RkRkSGhMd3RCcVljcjZzR3RNWUFzaEpINW1QSnZBOVQ3bkdCcUJoYmdLZTV4R1BNSzFSRHdRdA/callback',
code: 40060,
httpStatus: 400,
requestData: { json: { type: 7, data: [Object] }, files: [] }
}
6 Replies
d.js toolkit
d.js toolkit4mo ago
- 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!
Mark
Mark4mo ago
check what the error.message contains (it's a string) and use if or switch statements to handle it accordingly
treble/luna
treble/luna4mo ago
also if you're using v13, upgrade, its deprecated
fauteen
fauteenOP4mo ago
if (error.message.includes('Interaction has already been acknowledged')) {
if (error.message.includes('Interaction has already been acknowledged')) {
will this work?
Mark
Mark4mo ago
Did you try it
d.js docs
d.js docs4mo ago
:dtypes: v10: RESTJSONErrorCodes read more
Want results from more Discord servers?
Add your server