【发布时间】:2022-01-21 02:18:09
【问题描述】:
当我们使用awaitMessages 时,我可能不太了解 Discord API 的工作原理。我正在尝试做的是在私人频道中单击按钮后等待用户的消息:
client.on('interactionCreate', async interaction => {
if (interaction.isButton()) {
if (interaction.customId.startsWith('dialogue-')) {
const embed = new MessageEmbed()
.setColor('#1a8175')
.setTitle('???? Dialogue')
.setDescription('Please type your dialgoue')
await interaction.channel.send({embeds: [embed]})
// My problem lies here
const filter = m => m.author.id === interaction.author.id;
await interaction.channel.awaitMessages(filter, {
max: 1,
time: 60000,
errors: ['time']
}).then(
async(collected) => {
await interaction.channel.send('Received: ' + collected.first().content.toLowerCase())
})
}
}
如您所见,用户单击按钮,会发送一条消息,要求进行对话。之后,机器人应该会收到下一条消息。
调试后,我看到我在消息发送给用户后键入的所有内容都会触发messageCreate 事件,这就是我的代码无法正常工作的原因。据我了解,当我们使用 awaitMessages 时,机器人应该等待 Promise 完成。我无法弄清楚我在这里缺少什么。有任何想法吗?提前致谢
【问题讨论】:
标签: javascript discord discord.js bots