【问题标题】:How to get text from individual users如何从个人用户那里获取文本
【发布时间】:2021-05-24 10:56:07
【问题描述】:

我正在尝试为特定用户创建备注命令,但我的 Discord 机器人会将备注作为公众用户所说的任何备注。我该如何解决?我已经知道我的代码存在问题,但我不知道如何解决它。

if (command == "Note") {
   const notes = db.fetch('userInfo');
   while (!args[0]) return message.channel.send("Here are your notes: " + notes);
   db.set('userInfo', args.join(' '));
   message.channel.send((args.join(' ')) + (" successfully noted!"));
}

【问题讨论】:

    标签: javascript discord.js quick.db


    【解决方案1】:

    您有一个名为userInfo 的行,只要有人执行该命令,该行就会更新。如果您希望它与用户链接,则最好使用用户的 id,因为每个人都有不同的 ID。我建议使用类似的东西:

       const notes = db.fetch(`userInfo.${message.author.id}`)
       while (!args[0]) return message.channel.send("Here are your notes: " + notes )
       db.set('userInfo.${message.author.id}', args.join(' '))
       message.channel.send(args.join(' ') + " successfully noted!")
    

    【讨论】:

    • 谢谢,它成功了。最后,我最终使用了以下代码: const notes = db.fetch(userInfo${message.author.id}); while (!args[0]) return message.channel.send("这是你的笔记:" + notes); db.set(userInfo${message.author.id}, args.join('')); message.channel.send((args.join(' ')) + ("成功记下!"));
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-23
    • 2018-10-07
    • 1970-01-01
    • 1970-01-01
    • 2015-07-17
    • 1970-01-01
    相关资源
    最近更新 更多