如何让我的机器人在用户回复问题后发送消息?



我试图使一个系统,其中用户是由机器人给出一个问题,用户回复后,它清除这2条消息,并问另一个问题,并重复,直到所有的问题都完成。

我不能让它等待用户输入他们的答案之前问另一个问题,有帮助吗?

const { MessageEmbed } = require("discord.js");
const clearMessages = require("./clearMessages");
const askEventQuestions = async (client, channelId) => {
const edonoChannel = client.channels.cache.get(channelId);
let q1Answer = ""
//event questions embeds
const q1 = new MessageEmbed()
.setColor("AQUA")
.setDescription("What Type of Event would you like to donate for?");
const q2 = new MessageEmbed()
.setColor("AQUA")
.setDescription("What are the amounts of DMC/Items that you are donating?");

//send and set answer for questions
await edonoChannel.send({ embeds: [q1] });
client.on("messageCreate", async (message) => {
q1Answer = message.content;
if (q1Answer !== "") {
await clearMessages(2, message);
console.log(q1Answer);
}
});
await edonoChannel.send({ embeds: [q2] });

您应该使用收集器我认为awaitMessages: https://discordjs.guide/popular-topics/collectors.html await-messages

这是一种完全不同的方法,但更简单

像这样:

const isValid = response => response.content == ''
const question = await edonoChannel.send({ embeds: [q1] })
const stepper = await question.channel.awaitMessages({isValid, your options ?})
const answer = stepper.first().content 
// this is your answer content, the data is necessarily the unique valid response, thanks to isValid function
await question.delete()
await stepper.delete()
...

返回第一条(或多条)包含您的问题的有效答案的消息。之后你就可以开始你的治疗了!

相关内容

  • 没有找到相关文章

最新更新