这是我的代码:
async function createTicketModal(interaction, ticketType) {
if (interaction.deferred || interaction.replied) {
// Interaction has already been replied to or deferred
return;
}
const modal = new ModalBuilder()
.setCustomId('ticketModal')
.setTitle(`${ticketType} - Ticket`);
const questionModal = new TextInputBuilder()
.setCustomId('questionModal')
.setLabel('Please describe your problem.')
.setStyle(TextInputStyle.Paragraph);
const firstActionRow = new ActionRowBuilder().addComponents(questionModal);
modal.addComponents(firstActionRow);
const modalMessage = await interaction.showModal(modal);
try {
const modalResponse = await interaction.awaitModalSubmit({
filter: (i) =>
i.customId === "ticketModal" &&
i.user.id === interaction.user.id,
time: 60000,
});
if (modalResponse.isMessageComponent()) {
const description = modalResponse.values[0];
const channel = await interaction.guild.channels.create(`${interaction.user.username}-ticket`, {
type: 'text',
permissionOverwrites: [
{
id: interaction.guild.id,
deny: 'VIEW_CHANNEL',
},
{
id: interaction.user.id,
allow: ['VIEW_CHANNEL', 'SEND_MESSAGES', 'ATTACH_FILES'],
},
],
});
if (!channel.isText()) {
await modalMessage.editReply({
content: `Failed to create a text channel for your ${ticketType} ticket.`,
embeds: [],
components: [],
});
return;
}
const embed = new EmbedBuilder()
.setTitle(`${ticketType} Ticket`)
.setDescription(`Problem Description: ${description}`)
.setColor('#0099ff')
.build();
await channel.send(`${interaction.user}`, { embeds: [embed] });
// Close the modal by updating the interaction with an empty array of components
await modalMessage.editReply({ components: [] });
}
} catch (error) {
console.error(error);
await modalMessage.editReply({
content: `An error occurred while creating your ${ticketType} ticket. Please try again later.`,
embeds: [],
components: [],
});
}
}
当您将命令(/ticket
)发送到通道时,所有操作都将开始.就在机器人发送带有4个按钮的嵌入消息之后.当我在第一次嵌入时点击一个按钮,它只会发送一个模式,询问‘请描述您的问题’.但问题是,当我提交它时,模式说:
注意事项
This question似乎不是复制品,因为它不适合我的案子.