用户回复问题后,如何使我的机器人发送消息

发布于 2025-02-08 13:26:06 字数 1024 浏览 1 评论 0原文

我正在尝试制作一个系统,该系统由机器人提出问题,然后用户回复它清除了这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] });

I'm trying to make a system where a user is given a question by the bot and after the user replies it clears these 2 messages and asks another question and repeats until all the questions are complete.

I can't make it to wait for the user to input their answer before asking another question, any help?

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] });

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

捎一片雪花 2025-02-15 13:26:06

您应该使用收集器,我认为等待 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()

...

这 消息)包含(s)您问题的有效答案。之后,您可以进行治疗!

You should use Collectors and I think awaitMessages : https://discordjs.guide/popular-topics/collectors.html#await-messages

Its a totally different way to do it but simpler

Something like that :

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()

...

That is returning the first message (or messages) that contain(s) the valid answer to your question. After that you can run your treatement!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文