英文:
Discord.js cancellation of modal cause crashes
问题
我使用以下方法来等待执行斜杠命令后的模态回复。
await interaction.showModal(submissionValidateModal);
const modalReply = await interaction.awaitModalSubmit({
time: 60000,
filter: i => i.user.id === interaction.user.id,
}).catch(error => {
console.log(error)
return null;
})
// 处理事务
modalReply.reply({ embeds: [requestedSentEmbed], ephemeral: true });
然而,如果用户执行命令,机器人将等待模态提交事件。即使用户在这种情况下点击取消,await也不会被取消。当用户快速再次执行命令并提交模态时,最终会导致错误:Interaction has already been acknowledged
。我认为这是因为有多个收集器等待模态提交,当模态被提交时,将导致机器人尝试多次回复。有人对这个问题有线索吗?
英文:
I use the following method to wait for the modal reply after executing the slash command.
await interaction.showModal(submissionValidateModal);
const modalReply = await interaction.awaitModalSubmit({
time: 60000,
filter: i => i.user.id === interaction.user.id,
}).catch(error => {
console.log(error)
return null;
})
// Handling Stuff
modalReply.reply({ embeds: [requestedSentEmbed], ephemeral: true });
However, if the user execute the command, and the bot will be waiting for the modal submit event. The await would not be cancelled even if the user click cancel in this situation. When the user quickly execute the command again, and submit with the modal, it will eventually causing the error: Interaction has already been acknowledged
. I believe this happens because there is more than 1 collector waiting for the modal submit, when the modal is submitted, it will cause the bot attempting to reply a more than once.
Anyone have clues on this issue?
答案1
得分: 1
基于DJS文档
您需要使用.then
方法。由于awaitModalSubmit
已经确认了命令。
// 收集模态提交交互
const filter = (interaction) => interaction.customId === 'modal';
interaction.awaitModalSubmit({ filter, time: 15_000 })
.then(interaction => console.log(`${interaction.customId}已提交!`))
.catch(console.error);
英文:
Based off of DJS Documentation
You need the .then
method. Since awaitModalSubmit already acknowledges the command
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-js -->
// Collect a modal submit interaction
const filter = (interaction) => interaction.customId === 'modal';
interaction.awaitModalSubmit({ filter, time: 15_000 })
.then(interaction => console.log(`${interaction.customId} was submitted!`))
.catch(console.error);
<!-- end snippet -->
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论