Problem with Interactions
I am experiencing a bug with interactions when using a custom handler. I'll send the handler code below.
/post/postDiscordAPIError: Interaction has already been acknowledged[InteractionAlreadyReplied]: The reply to this interaction has already been sent or deferred.<Interaction>.followUp() to send a new message<Interaction>.editReply()/post/postDiscordAPIError: Interaction has already been acknowledged[InteractionAlreadyReplied]: The reply to this interaction has already been sent or deferred.<Interaction>.followUp()<Interaction>.editReply()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;
}
};
}
}
}
}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);
}
})
}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 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));
}
}