首页 文章

等待私人消息discord.js的回复

提问于
浏览
0

因此,这按预期工作ALMOST . 我将机器人私人消息传递给在服务器的正确通道中使用正确命令的用户 . 我没有使用配置文件创建消息来堵塞服务器,而是让私有的bot进行配置文件创建 . 我知道/认为问题出在message.channel.awaitMessages上,因为它只能看到命令所在的服务器上原始通道中的回复 .

我不确定应该替换message.channel.awaitMessages,以便它在私人消息对话中获取回复,而不是服务器上的原始配置文件创建通道 .

我还没有测试过sql消息 . 我没有测试过我的东西,但我很确定它不起作用 . 我希望私人消息中的用户给出的回复(可能会更新?)到我已经设置并正常工作的mysql数据库中 . 用户ID和用户名已放入此表中,此时其他与配置文件相关的问题为空 . 当他们回答这些问题时,可以填写/更新这些字段 . 欢迎任何想法/建议!

module.exports.run = async (bot, message, args) => {
if(message.channel.id === '460633878244229120') return message.author.send(`Greetings, ${message.author.username}! FIRST QUESTION, **What is the name of your Brawler or Character?**`)
  .then(function(){
    message.channel.awaitMessages(response => message.content, {
      max: 1,
      time: 5000,
      errors: ['time'],
    })
    .then((collected) => {
        message.author.send(`Your Name is: ${collected.first().content}`);
        var sql = (`UPDATE profile SET name = '${message.content}' WHERE id = ${message.author.id}`);
      })
      .catch(function(){
        message.author.send('Please submit a name for your character. To restart Profile creation, please type "!profilecreate" command in Profile Creation channel on the server.');
      });
    });
  }

在此先感谢您的时间!

1 回答

  • 0

    我不这么使用SQL,因为问题不在于此,请不要问我 .

    当您使用 message.channel.awaitMessages 时, message 仍然是您在 module.exports.run 函数中传递的第一个,而不是来自 send() 的函数 . 当 send 被解析时,它传递一条新消息,你必须包含在你放在 then 中的函数的参数中:所以,你需要像 .then(function(new_message_sent_in_private) {}) 这样的东西而不是 .then(function() {})

    这应该可以解决问题:

    module.exports.run = async (bot, message, args) => {
    if(message.channel.id === '460633878244229120') return message.author.send(`Greetings, ${message.author.username}! FIRST QUESTION, **What is the name of your Brawler or Character?**`)
      .then((newmsg) => { //Now newmsg is the message you sent
        newmsg.channel.awaitMessages(response => response.content, {
          max: 1,
          time: 5000,
          errors: ['time'],
        }).then((collected) => {
          newmsg.channel.send(`Your Name is: ${collected.first().content}`);
          var sql = (`UPDATE profile SET name = '${message.content}' WHERE id = ${message.author.id}`);
        }).catch(() => {
          newmsg.channel.send('Please submit a name for your character. To restart Profile creation, please type "!profilecreate" command in Profile Creation channel on the server.');
        });
      });
    }
    

    现在让我,如果有效:)

相关问题