interactionalreadyanswered错误,而发送一个模式,discord.js v14



我正在使用discord.jsv14开发一个机器人,所以我正在制作一个模态命令,但我发现了一个我无法解决的错误。这是我正在使用的代码。

modal.js:

const BOT = require("../../../handlers/Client");
const {
ApplicationCommandType,
Client,
CommandInteraction,
ModalBuilder,
ActionRowBuilder,
TextInputBuilder,
TextInputStyle
} = require("discord.js")
module.exports = {
name: "modal",
description: `ModalTest`,
userPermissions: [],
botPermissions: [],
category: "Information",
cooldown: 10,
type: ApplicationCommandType.ChatInput,
/**
*
* @param {BOT} client
* @param {CommandInteraction} interaction
* @param {String[]} args
*/
run: async (client, interaction, args) => {

const myModal = new ModalBuilder()
.setCustomId("modal_1")
.setTitle(`Modal Teste`);
const username = new TextInputBuilder()
.setCustomId("username")
.setLabel("Username:")
.setStyle(2)
.setPlaceholder("Coloque seu nome")
.setRequired(true)
.setMinLength(4)
.setMaxLength(10);
const password = new TextInputBuilder()
.setCustomId("password")
.setLabel("Password:")
.setStyle(2)
.setPlaceholder("Coloque sua senha")
.setRequired(true)
.setMinLength(4)
.setMaxLength(10);
const username_row = new ActionRowBuilder().addComponents(username);
const password_row = new ActionRowBuilder().addComponents(password);
myModal.addComponents(username_row, password_row);
await interaction.showModal(myModal);

}
}

事件/modal.js:

const { InteractionType } = require("discord.js");
const client = require("../index");
client.on("interactionCreate", async (interaction) => {
if (interaction.type === InteractionType.ModalSubmit) {
// code
if (interaction.customId === "modal_1") {
const username = interaction.fields.getTextInputValue("username");
const password = interacrion.fields.getTextInputValue("username");
if(username && password){
await interaction.reply({
content: `Sua submissão foi enviada. nn UserName: ${username} n Password: ${password}`,
ephemeral: true,
})
}
}
}
})

错误代码:

[Error_Handling] :: Unhandled Rejection/Catch
Error [InteractionAlreadyReplied]: The reply to this interaction has already been sent or deferred.
at ChatInputCommandInteraction.showModal (C:UsersRaphaDownloadsdiscord js procjetPROJETINHO DIVINO QUE EU VOU TERMINAR EM NOME DE JESUS AMÉMnode_modulesdiscord.jssrcstructuresinterfacesInteractionResponses.js:252:46)
at Object.run (C:UsersRaphaDownloadsdiscord js procjetPROJETINHO DIVINO QUE EU VOU TERMINAR EM NOME DE JESUS AMÉMCommandsSlashInformationmodal.js:56:23)
at BOT.<anonymous> (C:UsersRaphaDownloadsdiscord js procjetPROJETINHO DIVINO QUE EU VOU TERMINAR EM NOME DE JESUS AMÉMeventsinteractionCreate.js:51:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
code: 'InteractionAlreadyReplied'
} Promise {
<rejected> Error [InteractionAlreadyReplied]: The reply to this interaction has already been sent or deferred.
at ChatInputCommandInteraction.showModal (C:UsersRaphaDownloadsdiscord js procjetPROJETINHO DIVINO QUE EU VOU TERMINAR EM NOME DE JESUS AMÉMnode_modulesdiscord.jssrcstructuresinterfacesInteractionResponses.js:252:46)
at Object.run (C:UsersRaphaDownloadsdiscord js procjetPROJETINHO DIVINO QUE EU VOU TERMINAR EM NOME DE JESUS AMÉMCommandsSlashInformationmodal.js:56:23)
at BOT.<anonymous> (C:UsersRaphaDownloadsdiscord js procjetPROJETINHO DIVINO QUE EU VOU TERMINAR EM NOME DE JESUS AMÉMeventsinteractionCreate.js:51:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
code: 'InteractionAlreadyReplied'
}
}

interactionCreate.js:

const { ApplicationCommandOptionType } = require("discord.js");
const client = require("..");
const { cooldown } = require("../handlers/functions");
const { emoji } = require("../settings/config");
client.on("interactionCreate", async (interaction) => {
// Slash Command Handling
if (interaction.isChatInputCommand()) {
await interaction.deferReply({ ephemeral: true }).catch((e) => {});
const cmd = client.commands.get(interaction.commandName);
if (!cmd)
return client.embed(
interaction,
`${emoji.ERROR} `${interaction.commandName}` Command Not Found `
);
const args = [];
for (let option of interaction.options.data) {
if (option.type === ApplicationCommandOptionType.Subcommand) {
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);
}
interaction.member = interaction.guild.members.cache.get(
interaction.user.id
);
if (cmd) {
// checking user perms
if (!interaction.member.permissions.has(cmd.userPermissions || [])) {
return client.embed(
interaction,
`You Don't Have `${cmd.userPermissions}` Permission to Use `${cmd.name}` Command!!`
);
} else if (
!interaction.guild.members.me.permissions.has(cmd.botPermissions || [])
) {
return client.embed(
interaction,
`I Don't Have `${cmd.botPermissions}` Permission to Use `${cmd.name}` Command!!`
);
} else if (cooldown(interaction, cmd)) {
return client.embed(
interaction,
` You are On Cooldown , wait `${cooldown(
interaction,
cmd
).toFixed()}` Seconds`
);
} else {
cmd.run(client, interaction, args);
}
}
}
// Context Menu Handling
if (interaction.isContextMenuCommand()) {
await interaction.deferReply({ ephemeral: true }).catch((e) => {});
const command = client.commands.get(interaction.commandName);
if (command) command.run(client, interaction);
}
});

我试着跟进互动,但没有解决它,我不知道现在该怎么办

既然你想显示一个模态,事实是,你不能使用deferReply(),如果你需要使用showModal()以及(据我所知)。由于您在interactionCreate.js文件中使用了deferReply(),因此会弹出此错误。所以要修复它,你所需要做的就是删除deferReply(),你的代码应该可以正常工作

最新更新