InteractionNotReplied, sometimes occurs

hello, i made a bot for hangman, but i am facing an issue where i keep getting this code D:\Projects\node\discordbot\node_modules\discord.js\src\structures\interfaces\InteractionResponses.js:184 if (!this.deferred && !this.replied) return Promise.reject(new DiscordjsError(ErrorCodes.InteractionNotReplied)); ^ Error [InteractionNotReplied]: The reply to this interaction has not been sent or deferred. at ChatInputCommandInteraction.followUp (D:\Projects\node\discordbot\node_modules\discord.js\src\structures\interfaces\InteractionResponses.js:184:64) at Object.execute (D:\Projects\node\discordbot\commands\hangman.js:47:17) at Client.<anonymous> (D:\Projects\node\discordbot\main.js:39:23) at Client.emit (node:events:518:28) at InteractionCreateAction.handle (D:\Projects\node\discordbot\node_modules\discord.js\src\client\actions\InteractionCreate.js:97:12) at module.exports [as INTERACTION_CREATE] (D:\Projects\node\discordbot\node_modules\discord.js\src\client\websocket\handlers\INTERACTION_CREATE.js:4:36) at WebSocketManager.handlePacket (D:\Projects\node\discordbot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:355:31) at WebSocketManager.<anonymous> (D:\Projects\node\discordbot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:239:12) at WebSocketManager.emit (D:\Projects\node\discordbot\node_modules@vladfrangu\async_event_emitter\dist\index.cjs:282:31)
at WebSocketShard.<anonymous> (D:\Projects\node\discordbot\node_modules@discordjs\ws\dist\index.js:1173:51) { code: 'InteractionNotReplied' } Node.js v20.11.0
4 Replies
d.js toolkit
d.js toolkit9mo 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! - Marked as resolved by OP
ahmed349
ahmed349OP9mo ago
without including most of the gamelogic, this is how my code works, manipulating an array of active game sessions to see who is playing what game, and if statements to give appropriate replies when they fail/win the game depending on the input
async function execute(interaction){
let userId = interaction.user.id;
let session = activeGameSessions[Object.keys(activeGameSessions).find(str => str == userId)];
if (session == undefined) {
session = await createNewSession(userId);
interaction.reply('YO, Guess this word\n' + session.revealedWord);
return;
}

let input = interaction.options.getString('string');
console.log(input);
if (!input) return;

if (input.length > 1){
if (session.attemptWord(input)){
interaction.reply('GG, ig\n' + session.revealedWord);
delete(activeGameSessions[userId]);

return;
}
else {
interaction.reply('Nope, stupid nerd\n' + session.revealedWord);
}
}
else {
if (session.attemptLetter(input)){
interaction.reply('Les gooooo!!1\n' + session.revealedWord)
}
else {
interaction.reply('Nope, bad letter my boy\n' + session.revealedWord);
}
}

interaction.followUp(`Holy moly your lives are at ${session.lives} pepperoni`);
}
async function execute(interaction){
let userId = interaction.user.id;
let session = activeGameSessions[Object.keys(activeGameSessions).find(str => str == userId)];
if (session == undefined) {
session = await createNewSession(userId);
interaction.reply('YO, Guess this word\n' + session.revealedWord);
return;
}

let input = interaction.options.getString('string');
console.log(input);
if (!input) return;

if (input.length > 1){
if (session.attemptWord(input)){
interaction.reply('GG, ig\n' + session.revealedWord);
delete(activeGameSessions[userId]);

return;
}
else {
interaction.reply('Nope, stupid nerd\n' + session.revealedWord);
}
}
else {
if (session.attemptLetter(input)){
interaction.reply('Les gooooo!!1\n' + session.revealedWord)
}
else {
interaction.reply('Nope, bad letter my boy\n' + session.revealedWord);
}
}

interaction.followUp(`Holy moly your lives are at ${session.lives} pepperoni`);
}
i am testing getting wrong letters in the game of hangman, but sometimes it works and gives me the proper response, and sometimes it just breaks and gives the aforementioned error
TÆMBØ
TÆMBØ9mo ago
Because you're not taking advantage of async/await with your interaction responses like you are with createNewSession(). You aren't waiting for the Promise of reply() to resolve before then trying to follow-up, so now you're getting a race condition where you're sending the reply & follow-up at effectively the same time, You're getting inconsistent results because it's not certain which request will go through first
ahmed349
ahmed349OP9mo ago
ahhh must have missed that while reading the documentation, and i am also to blame for not figured it out intuitively, thank you very much
Want results from more Discord servers?
Add your server