technyk
technyk
DIdiscord.js - Imagine ❄
Created by technyk on 11/11/2024 in #djs-questions
Interaction has already been acknowledged
Hi, I am making a Discord bot which utilizes interactions and message ids. Basically, whenever a message id is supplied into a command, it should currently reply back with the name of the channel which the command was run in. However, if the id is invalid, it should reply back with an error message. Unfortunately so, the bot does reply with the channel name everytime the command is ran (regardless of the validity of the message id), and if the message id was invalid it just throws an error into the console, which goes as follows:
throw new DiscordAPIError(data, "code" in data ? data.code : data.error, status, method, url, requestData);
^

DiscordAPIError[40060]: Interaction has already been acknowledged.
throw new DiscordAPIError(data, "code" in data ? data.code : data.error, status, method, url, requestData);
^

DiscordAPIError[40060]: Interaction has already been acknowledged.
Command code below:
client.on("interactionCreate", (interaction) => {
if (!interaction.isCommand()) return;

const { commandName, options } = interaction;
if (commandName === "rolereactors") {
const arg = options.getString("messageid");

interaction.channel.messages.fetch(arg).catch(error => {
interaction.reply("Message not found..\n Make sure you are in the same channel as the message")
return;
});

interaction.reply(interaction.channel.toString()); // TODO: Get all reactors on the message
}
});
client.on("interactionCreate", (interaction) => {
if (!interaction.isCommand()) return;

const { commandName, options } = interaction;
if (commandName === "rolereactors") {
const arg = options.getString("messageid");

interaction.channel.messages.fetch(arg).catch(error => {
interaction.reply("Message not found..\n Make sure you are in the same channel as the message")
return;
});

interaction.reply(interaction.channel.toString()); // TODO: Get all reactors on the message
}
});
Thank you in advance for any tips and/or suggestions for improvements to the code :cronchycat:
18 replies