fauteen
DIAdiscord.js - Imagine an app
•Created by fauteen on 8/16/2024 in #djs-questions
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: [] }
}
7 replies
DIAdiscord.js - Imagine an app
•Created by fauteen on 6/22/2024 in #djs-questions
Interaction already replied issue
const { MessageEmbed } = require('discord.js');
module.exports = {
name: 'flightlog',
description: 'Log a flight with a flight number',
options: [
{
name: 'flight_number',
type: 'STRING',
description: 'The flight number to log',
required: true,
},
],
run: async (client, interaction) => {
const userId = interaction.user.id;
const userName = interaction.user.username;
const flightNumber = interaction.options.getString('flight_number');
const embed = new MessageEmbed()
.setTitle('Flight Log Entry')
.setDescription(`**User:** ${userName}\n**Flight Number:** ${flightNumber}`)
.setColor('BLUE')
.setFooter('Flight Log Bot')
.setTimestamp();
const logChannelId = '1244624724223332463';
const logChannel = client.channels.cache.get(logChannelId);
if (logChannel) {
logChannel.send({ embeds: [embed] })
.then(() => {
interaction.reply({ content: 'Flight log entry recorded successfully.', ephemeral: true });
})
.catch((error) => {
console.error('Failed to send message to the log channel:', error);
interaction.reply({ content: 'There was an error recording your flight log entry. Please try again later.', ephemeral: true });
});
} else {
console.error('Log channel not found');
interaction.reply({ content: 'Log channel not found. Please contact the server administrator.', ephemeral: true });
}
},
};
const { MessageEmbed } = require('discord.js');
module.exports = {
name: 'flightlog',
description: 'Log a flight with a flight number',
options: [
{
name: 'flight_number',
type: 'STRING',
description: 'The flight number to log',
required: true,
},
],
run: async (client, interaction) => {
const userId = interaction.user.id;
const userName = interaction.user.username;
const flightNumber = interaction.options.getString('flight_number');
const embed = new MessageEmbed()
.setTitle('Flight Log Entry')
.setDescription(`**User:** ${userName}\n**Flight Number:** ${flightNumber}`)
.setColor('BLUE')
.setFooter('Flight Log Bot')
.setTimestamp();
const logChannelId = '1244624724223332463';
const logChannel = client.channels.cache.get(logChannelId);
if (logChannel) {
logChannel.send({ embeds: [embed] })
.then(() => {
interaction.reply({ content: 'Flight log entry recorded successfully.', ephemeral: true });
})
.catch((error) => {
console.error('Failed to send message to the log channel:', error);
interaction.reply({ content: 'There was an error recording your flight log entry. Please try again later.', ephemeral: true });
});
} else {
console.error('Log channel not found');
interaction.reply({ content: 'Log channel not found. Please contact the server administrator.', ephemeral: true });
}
},
};
15 replies
DIAdiscord.js - Imagine an app
•Created by fauteen on 6/21/2024 in #djs-questions
Unknown Interaction
for some reason I keep getting this error when trying to run a command, this only happens sometimes.
DiscordAPIError: Unknown interaction
at RequestHandler.execute (/home/container/node_modules/discord.js/src/rest/RequestHandler.js:350:13)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async RequestHandler.push (/home/container/node_modules/discord.js/src/rest/RequestHandler.js:51:14)
at async CommandInteraction.deferReply (/home/container/node_modules/discord.js/src/structures/interfaces/InteractionResponses.js:61:5)
at async module.exports (/home/container/src/events/interactionCreate.js:5:5) {
method: 'post',
path: '/interactions/1253563066042421249/aW50ZXJhY3Rpb246MTI1MzU2MzA2NjA0MjQyMTI0OTpKTlZsOVdWcUJLbFZ4T25wdG1iUzVTUUlDSUFRcjcxUk1wRXpJbmVXUTFseGdXTXhNRHBOOHJpTmo1eUNKMGs4Mkl4eWxBUURKUmZQc0pvcEN4OHVKaVk4WVFYRDlNaHhvV1o2QlNXUUZhQUFVU1hLTDNoUFlReTNzU0s0a0xoTg/callback',
code: 10062,
httpStatus: 404,
requestData: { json: { type: 5, data: [Object] }, files: [] }
}
DiscordAPIError: Unknown interaction
at RequestHandler.execute (/home/container/node_modules/discord.js/src/rest/RequestHandler.js:350:13)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async RequestHandler.push (/home/container/node_modules/discord.js/src/rest/RequestHandler.js:51:14)
at async CommandInteraction.deferReply (/home/container/node_modules/discord.js/src/structures/interfaces/InteractionResponses.js:61:5)
at async module.exports (/home/container/src/events/interactionCreate.js:5:5) {
method: 'post',
path: '/interactions/1253563066042421249/aW50ZXJhY3Rpb246MTI1MzU2MzA2NjA0MjQyMTI0OTpKTlZsOVdWcUJLbFZ4T25wdG1iUzVTUUlDSUFRcjcxUk1wRXpJbmVXUTFseGdXTXhNRHBOOHJpTmo1eUNKMGs4Mkl4eWxBUURKUmZQc0pvcEN4OHVKaVk4WVFYRDlNaHhvV1o2QlNXUUZhQUFVU1hLTDNoUFlReTNzU0s0a0xoTg/callback',
code: 10062,
httpStatus: 404,
requestData: { json: { type: 5, data: [Object] }, files: [] }
}
34 replies