不和谐的私人消息命令

时间:2018-07-06 11:35:11

标签: javascript command discord.js private-messaging

我正在使用JavaScript为Discord机器人进行RP配置文件创建设置。我的对话从某个渠道开始,然后转移到与该漫游器进行私人消息传递。询问第一个问题,并将来自用户的答复存储在数据库中。很好。

当我尝试通过漫游器在私人消息中使用另一个命令来进入RP配置文件创建的下一步时,似乎出现了问题。似乎没有注册正在使用的命令。甚至可以在通过Bot进行私人消息传递中使用命令吗?

我使用了与第一个有效的问题相同的代码,更改了所需的内容,但没有任何东西会破坏代码。看起来甚至看不到第二个命令,该命令存储在单独的命令文件中。我该怎么做?

module.exports.run = async (bot, message, args) => {
message.author.send(` SECOND QUESTION, **What is the age of your Brawler or Character?**`)
  .then((newmsg) => { //Now newmsg is the message you send to the bot
    newmsg.channel.awaitMessages(response => response.content, {
      max: 1,
      time: 300000,
      errors: ['time'],
    }).then((collected) => {
      newmsg.channel.send(`Your brawler's age is: **${collected.first().content}**

      If you are okay with this age, type !profilegender to continue the profile creation process!

      If you would like to edit your age, please type !profileage`)
        con.query(`UPDATE profile SET age = '${collected.first().content}' WHERE id = ${message.author.id}`);
        console.log("1 record updated!")
    }).catch(() => {
      newmsg.channel.send('Please submit an age for your character. To restart Profile creation, please type "!profilecreate" command in Profile Creation channel on the server.');
    });
  });
}

提前感谢您的宝贵时间!

编辑:这是机器人/客户端正在侦听消息的代码的一部分。

bot.on(`message`, async message => {
  if(message.author.bot) return;
  if(message.channel.type === "dm") return;

  con.query(`SELECT * FROM profile WHERE id = '${message.author.id}'`, (err, rows) => {
    if(err) throw err;

    var sql;

    if(rows.length < 1) {
      var sql = (`INSERT INTO profile (id, username) VALUES (${message.author.id}, '${message.author.tag}')`);
    } else {
      var sql = (`UPDATE profile SET username = '${message.author.tag}' WHERE id = ${message.author.id}`);
    };

    //con.query(sql, console.log);
    //if (err) throw err;
    //console.log("1 record inserted!");
  });

1 个答案:

答案 0 :(得分:1)

评论答复

lib内,如果通道为DMChannel,则有一个if检查退出该函数

client.on("message")

为避免这种情况,只需删除此行:这样,机器人将执行命令,而与通道类型无关。如果只想在某些通道中允许某些命令,则可以在if(message.channel.type === "dm") return; 或命令本身的功能中进行。

相关问题