Problem with Interactions

I am experiencing a bug with interactions when using a custom handler. I'll send the handler code below.
14 Replies
Unknown User
Unknown Userβ€’3y ago
Message Not Public
Sign In & Join Server To View
π•―π–”π–‰π–”π•Ύπ–Šπ–†π–‘
function checkFileType(client, typeName) {
var clientCmds = Array.from(client.commands);
var commands = [];

for (var command of clientCmds) {
if (command[0].type == typeName) {
commands.push(command[0]);
};
};

return commands;
};

module.exports = {
name: "interactionCreate",
types: {
button: {
execute(client, Discord, interaction) {
var handlers = checkFileType(client, "button");

for (var handler of handlers) {
if (interaction.customId == handler.name) {
handler.execute(interaction, client, Discord);
break;
}
};
}
},
command: {
execute(client, Discord, interaction) {
var handlers = checkFileType(client, "slash");

for (var handler of handlers) {
if (interaction.commandName == handler.name) {
handler.execute(interaction, client, Discord);
break;
}
};
}
}
}
}
function checkFileType(client, typeName) {
var clientCmds = Array.from(client.commands);
var commands = [];

for (var command of clientCmds) {
if (command[0].type == typeName) {
commands.push(command[0]);
};
};

return commands;
};

module.exports = {
name: "interactionCreate",
types: {
button: {
execute(client, Discord, interaction) {
var handlers = checkFileType(client, "button");

for (var handler of handlers) {
if (interaction.customId == handler.name) {
handler.execute(interaction, client, Discord);
break;
}
};
}
},
command: {
execute(client, Discord, interaction) {
var handlers = checkFileType(client, "slash");

for (var handler of handlers) {
if (interaction.commandName == handler.name) {
handler.execute(interaction, client, Discord);
break;
}
};
}
}
}
}
HANDLER CODE (Separate file)
if (event.name == "interactionCreate") {
client.on("interactionCreate", (interaction) =>{
if (interaction.isButton()) {
event.types.button.execute(client, Discord, interaction);
} else if (interaction.isCommand()) {
event.types.command.execute(client, Discord, interaction);
}
})
}
if (event.name == "interactionCreate") {
client.on("interactionCreate", (interaction) =>{
if (interaction.isButton()) {
event.types.button.execute(client, Discord, interaction);
} else if (interaction.isCommand()) {
event.types.command.execute(client, Discord, interaction);
}
})
}
HANDLER CODE (Index.js part)
duck
duckβ€’3y ago
and what problem do you encounter?
π•―π–”π–‰π–”π•Ύπ–Šπ–†π–‘
Interaction already acknowledged
duck
duckβ€’3y ago
you haven't shown any code that responds to interactions is this error reproduceable? does it only occur on specific commands/buttons? or if it's for any and all interactions, could you show the rest of this file?
monbrey
monbreyβ€’3y ago
This.... seems to duplicate the bindings?
π•―π–”π–‰π–”π•Ύπ–Šπ–†π–‘
Wdym
const { ActionRowBuilder, ButtonBuilder, ButtonStyle } = require('discord.js')

module.exports = {
name: "post",
type: "slash",
execute(interaction, client, Discord){
const row = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setCustomId("editPost")
.setStyle(ButtonStyle.Secondary)
.setDisabled(true) // Check DataBase for previous Posts
.setLabel("Edit/Remove Post"),
new ButtonBuilder()
.setCustomId("createPost")
.setStyle(ButtonStyle.Success)
.setLabel("Create New Post")
)

if (!interaction.isButton()) {
interaction.reply({
ephemeral: true,
components: [row]
})
}
}
}
const { ActionRowBuilder, ButtonBuilder, ButtonStyle } = require('discord.js')

module.exports = {
name: "post",
type: "slash",
execute(interaction, client, Discord){
const row = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setCustomId("editPost")
.setStyle(ButtonStyle.Secondary)
.setDisabled(true) // Check DataBase for previous Posts
.setLabel("Edit/Remove Post"),
new ButtonBuilder()
.setCustomId("createPost")
.setStyle(ButtonStyle.Success)
.setLabel("Create New Post")
)

if (!interaction.isButton()) {
interaction.reply({
ephemeral: true,
components: [row]
})
}
}
}
Handler for /post
const mongoose = require(`mongoose`);
const Post = require(`../DataModels/post.js`);
const { mongoURI } = require(`../JSON/config.json`);

module.exports = {
name: "createPost",
type: "button",
execute(interaction, client, Discord){
console.log("Activated?")

mongoose.connect(mongoURI)
.then(interaction.reply({ content: "Connected to Database", ephemeral: true }))
.catch(err => console.log(err));

const newPost = new Post({
title: "DodoSeal - Programmer",
description: "I am programmer",
payment: "Payment here",
contact: "Twitter: https://twitter.com/WestJordan08"
});

newPost.save()
.then(interaction.reply({ content: "Added Data", ephemeral: true }))
.catch(err => console.log(err));
}
}
const mongoose = require(`mongoose`);
const Post = require(`../DataModels/post.js`);
const { mongoURI } = require(`../JSON/config.json`);

module.exports = {
name: "createPost",
type: "button",
execute(interaction, client, Discord){
console.log("Activated?")

mongoose.connect(mongoURI)
.then(interaction.reply({ content: "Connected to Database", ephemeral: true }))
.catch(err => console.log(err));

const newPost = new Post({
title: "DodoSeal - Programmer",
description: "I am programmer",
payment: "Payment here",
contact: "Twitter: https://twitter.com/WestJordan08"
});

newPost.save()
.then(interaction.reply({ content: "Added Data", ephemeral: true }))
.catch(err => console.log(err));
}
}
Handler for buttons sent by /post
duck
duckβ€’3y ago
Just within this file you reply twice You never answered my questions so idk if this is the only issue you have
d.js docs
d.js docsβ€’3y ago
β€’ DiscordAPIError: Interaction has already been acknowledged β€’ [InteractionAlreadyReplied]: The reply to this interaction has already been sent or deferred. You have already replied to the interaction. β€’ Use <Interaction>.followUp() to send a new message β€’ If you deferred reply it's better to use <Interaction>.editReply() β€’ Responding to slash commands / buttons / select menus
π•―π–”π–‰π–”π•Ύπ–Šπ–†π–‘
u wanted code that responds to the interactions
duck
duckβ€’3y ago
I also asked a few more questions
π•―π–”π–‰π–”π•Ύπ–Šπ–†π–‘
Btw where does discord.js think I'm double replying
duck
duckβ€’3y ago
In this file you reply after connecting then reply after saving
π•―π–”π–‰π–”π•Ύπ–Šπ–†π–‘
Changing the second reply to an edit reply errors I think i can fix it though
Want results from more Discord servers?
Add your server