javascript - 如何从个人用户那里获取文本
问题描述
我正在尝试为特定用户创建注释命令,但我的 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!"));
}
解决方案
您有一个名为 的行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!")
推荐阅读
- java - 为什么我在编码后在 Netbeans 10 中找不到 Javafx 桌面应用程序
- c - 函数 kbhit 在 C 中移动对象
- android - values-v28.xml:5:5-8:13: AAPT: 找不到与给定名称匹配的资源(在 'dialogCornerRadius' 处,值为 '?android:attr/dialogCornerRadius')
- python - 如何在python中编写一个字母二元组(aa,ab,bc,cd ... zz)频率分析计数器?
- javascript - ES6 导入失败
- laravel-5 - 为什么刀片显示模型原始值而不是属性?
- php - 如何内部连接 2 个 SQL 表,但只从第二个表中获取第一个结果?
- substring - 在 Wikidata Query Service 上使用 SPARQL 查找字符串中最长的三个子字符串,并在字符串中对它们进行排序
- node.js - 在节点和角度之间共享常量的好方法是什么
- rust - 如何从作为十六进制编码字符串给出的模数和指数构造公钥?