node.js - 将用户 ID 保存在 JSON 文件中
问题描述
今天我正在尝试制作一个 json 数据以将不和谐帐户链接到另一个帐户(英雄联盟、Dota 等......)
为了制作我的数据库,我正在使用以下代码:
message.reply(`Your account is link to **${args[1]}**`).then(msg => {
msg.delete({
timeout: 5000
});
});
userID = message.author;
let link = require('../link.json')
link.userID = {
name: `${message.author.username}`,
lol: `${args[1]}`,
}
var string = JSON.stringify(link, null, '\t');
fs.writeFile('./link.json', string, function(err) {
if (err) return console.error(err);
})
如果 bob 写/link lol boby02
而我(StarKleey帅哥)写/link lol StarKleey
json 将是:
{
"userID": { //here I would like "@<565465478767545>": {
"name": "bob",
"lol": "boby02"
},
"userID": { //and here "@<456465574385735>": {
"name": "StarKleey 帅哥",
"lol": "StarKleey"
}
}
我怎样才能做到这一点?
这是我目前正在使用的:
link.message.author = {
name: `${message.author.username}`,
lol: `${args[1]}`,
}
重新加载:
{
"@<565465478767545>": {
"name": "bob",
"lol": "boby02"
},
"@<456465574385735>": {
"name": "StarKleey 帅哥",
"lol": "StarKleey"
}
}
解决方案
您当前正在存储用户名,而您似乎想要存储用户 ID:您应该尝试使用User.id
:
link.message.author = {
name: `${message.author.id}`,
lol: `${args[1]}`,
}
推荐阅读
- load-testing - 在 K6 中使用 yield 时出现语法错误
- javascript - VUEJS: Override function from node_modules component
- sql - foreach 游标显式和 foreach 游标隐式有什么区别
- javascript - 每 10 秒使用 reactjs 挂钩从外部 Api 获取数据
- image-processing - 使用 CUDA 仅将 1/3 的 RGB 图像转换为灰度
- gradle - Junit 5 测试用例未在 gradle 4.4 中执行
- swift - 如何计算 SwiftUI 中的 @ViewBuilder 视图?
- python - 如何根据df1中的日期> = df2中的日期加入两个熊猫数据框
- ajax - Delete form data after data is displayed or submission of the form
- javascript - 调用 EvenListener 时如何关闭浏览器的弹出窗口