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 });
}
},
};
the embed sends to the desired channel id, but i get an interaction already replied error even though the embed sends, and it wont send the user a confirmation message saying Flight log entry recorded successfully.
10 Replies
d.js toolkit
d.js toolkit7mo 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!
treble/luna
treble/luna7mo ago
you likely defer or reply somewhere else in your code
fauteen
fauteenOP7mo ago
i am only using this command, and this command gets the error only
treble/luna
treble/luna7mo ago
you appear to be replying somewhere else though check your interactionCreate
fauteen
fauteenOP7mo ago
const { MessageEmbed, Collection } = require('discord.js')
module.exports = async (client, interaction) => {

if (interaction.isCommand()) {
await interaction.deferReply({ ephemeral: false })
let embed = new MessageEmbed()

const cmd = client.commands.get(interaction.commandName);

if (!cmd) return interaction.followUp({ content: "An error has occured " });

const args = [];

for (let option of interaction.options.data) {
if (option.type === "SUB_COMMAND") {
if (option.name) args.push(option.name);
option.options ?.forEach((x) => {
if (x.value) args.push(x.value);
});
} else if (option.value) args.push(option.value);
}

if (cmd.cooldown) {
if (!client.cooldown.has(cmd.name)) { client.cooldown.set(cmd.name, new Collection()) }

if (client.cooldown.get(cmd.name).has(interaction.user.id)) {

if (Date.now() < client.cooldown.get(cmd.name).get(interaction.user.id) + (cmd.cooldown) * 1000) {

const time_left = (client.cooldown.get(cmd.name).get(interaction.user.id) + (cmd.cooldown) * 1000 - Date.now()) / 1000;

return interaction.followUp({
content: `cooldown for \`${time_left.toFixed(1)}\` seconds`,
ephemeral: true
})

}
}

client.cooldown.get(cmd.name).set(interaction.user.id, Date.now());

setTimeout(() => client.cooldown.get(cmd.name).delete(interaction.user.id), (cmd.cooldown) * 1000);

}

if (cmd.permissions) {
if (!client.vaildPermissions.includes(cmd.permissions)) return;

if (!interaction.member.permissions.has(cmd.permissions)) return interaction.followUp({
content: `You don\'t have \`${cmd.permissions}\` permission`,
ephemeral: true
})
}

cmd.run(client, interaction, args);
}
}
const { MessageEmbed, Collection } = require('discord.js')
module.exports = async (client, interaction) => {

if (interaction.isCommand()) {
await interaction.deferReply({ ephemeral: false })
let embed = new MessageEmbed()

const cmd = client.commands.get(interaction.commandName);

if (!cmd) return interaction.followUp({ content: "An error has occured " });

const args = [];

for (let option of interaction.options.data) {
if (option.type === "SUB_COMMAND") {
if (option.name) args.push(option.name);
option.options ?.forEach((x) => {
if (x.value) args.push(x.value);
});
} else if (option.value) args.push(option.value);
}

if (cmd.cooldown) {
if (!client.cooldown.has(cmd.name)) { client.cooldown.set(cmd.name, new Collection()) }

if (client.cooldown.get(cmd.name).has(interaction.user.id)) {

if (Date.now() < client.cooldown.get(cmd.name).get(interaction.user.id) + (cmd.cooldown) * 1000) {

const time_left = (client.cooldown.get(cmd.name).get(interaction.user.id) + (cmd.cooldown) * 1000 - Date.now()) / 1000;

return interaction.followUp({
content: `cooldown for \`${time_left.toFixed(1)}\` seconds`,
ephemeral: true
})

}
}

client.cooldown.get(cmd.name).set(interaction.user.id, Date.now());

setTimeout(() => client.cooldown.get(cmd.name).delete(interaction.user.id), (cmd.cooldown) * 1000);

}

if (cmd.permissions) {
if (!client.vaildPermissions.includes(cmd.permissions)) return;

if (!interaction.member.permissions.has(cmd.permissions)) return interaction.followUp({
content: `You don\'t have \`${cmd.permissions}\` permission`,
ephemeral: true
})
}

cmd.run(client, interaction, args);
}
}
this is my interactioncreate ^^
treble/luna
treble/luna7mo ago
either use editReply or dont defer
fauteen
fauteenOP7mo ago
let me fix that and see when i changed that line to editreply, it worked. but i got this error when trying to run other commands.
rror [INTERACTION_NOT_REPLIED]: The reply to this interaction has not been sent or deferred.
at CommandInteraction.editReply (/home/runner/System-Bot/node_modules/discord.js/src/structures/interfaces/InteractionResponses.js:149:48)
at module.exports (/home/runner/System-Bot/src/events/interactionCreate.js:5:23)
at Client.emit (node:events:394:28)
at InteractionCreateAction.handle (/home/runner/System-Bot/node_modules/discord.js/src/client/actions/InteractionCreate.js:83:12)
at Object.module.exports [as INTERACTION_CREATE] (/home/runner/System-Bot/node_modules/discord.js/src/client/websocket/handlers/INTERACTION_CREATE.js:4:36)
at WebSocketManager.handlePacket (/home/runner/System-Bot/node_modules/discord.js/src/client/websocket/WebSocketManager.js:346:31)
at WebSocketShard.onPacket (/home/runner/System-Bot/node_modules/discord.js/src/client/websocket/WebSocketShard.js:493:22)
at WebSocketShard.onMessage (/home/runner/System-Bot/node_modules/discord.js/src/client/websocket/WebSocketShard.js:327:10)
at callListener (/home/runner/System-Bot/node_modules/ws/lib/event-target.js:290:14)
at WebSocket.onMessage (/home/runner/System-Bot/node_modules/ws/lib/event-target.js:209:9) {
[Symbol(code)]: 'INTERACTION_NOT_REPLIED'
}

rror [INTERACTION_NOT_REPLIED]: The reply to this interaction has not been sent or deferred.
at CommandInteraction.editReply (/home/runner/System-Bot/node_modules/discord.js/src/structures/interfaces/InteractionResponses.js:149:48)
at module.exports (/home/runner/System-Bot/src/events/interactionCreate.js:5:23)
at Client.emit (node:events:394:28)
at InteractionCreateAction.handle (/home/runner/System-Bot/node_modules/discord.js/src/client/actions/InteractionCreate.js:83:12)
at Object.module.exports [as INTERACTION_CREATE] (/home/runner/System-Bot/node_modules/discord.js/src/client/websocket/handlers/INTERACTION_CREATE.js:4:36)
at WebSocketManager.handlePacket (/home/runner/System-Bot/node_modules/discord.js/src/client/websocket/WebSocketManager.js:346:31)
at WebSocketShard.onPacket (/home/runner/System-Bot/node_modules/discord.js/src/client/websocket/WebSocketShard.js:493:22)
at WebSocketShard.onMessage (/home/runner/System-Bot/node_modules/discord.js/src/client/websocket/WebSocketShard.js:327:10)
at callListener (/home/runner/System-Bot/node_modules/ws/lib/event-target.js:290:14)
at WebSocket.onMessage (/home/runner/System-Bot/node_modules/ws/lib/event-target.js:209:9) {
[Symbol(code)]: 'INTERACTION_NOT_REPLIED'
}

treble/luna
treble/luna7mo ago
then you arent deferring some of your other commands
fauteen
fauteenOP7mo ago
Yep, I've found out the issue. Thanks!
Want results from more Discord servers?
Add your server