首页 > 解决方案 > 用私人消息 discord.js 中用户的回复替换 mysql 数据库中的值

问题描述

因此,我有一个机器人在不和谐服务器上的公共频道中发起对话后,在私人聊天中询问用户一些问题。我希望在私人聊天中得到用户的回复,以更新我的 mysql 数据库中的某个字段。

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: 10000,
      errors: ['time'],
    }).then((collected) => {
      newmsg.channel.send(`Your Name is: ${collected.first().content}`)
        var sql = (`UPDATE profile SET name = ${collected.first().content} WHERE id = ${newmsg.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.');
    });
  });
}

除了将行提交到数据库之外,其他一切都有效。它看起来甚至根本没有尝试运行该行,因为当我知道应该有语法错误时,我没有收到语法错误。我一般是编码新手,更不用说JS了。

标签: javascriptmysqlnode.jsdiscord.js

解决方案


推荐阅读