我一直在编码discord机器人,该机器人可以让您执行!v,从而创建一个快速页面,该页面使用随机生成的密钥将您的Steam帐户链接到您的discord帐户。到目前为止,除了将Steamid插入sqlite表之外,其他一切都进行得很好。
我需要让代码获得发送!v命令的用户,并将Steamid插入该用户下的表中。这是我现在拥有的代码:
app.get('/api/auth/:userid', steam.authenticate(), function(req, res) {
sql.all(`SELECT * FROM info WHERE userid ="${message.author.id}"`).then(rows => {
rows.forEach(function (row) {
req.params({ "userid": row.key })
res.redirect('/');
res.send(req.params);
})
})
});
app.get('/api/verify/', steam.verify(), function(req, res) {
sql.get(`SELECT * FROM info WHERE userid ="${message.author.id}"`).then(row => {
if (!row) {
sql.run("INSERT INTO info (key, userid, name, steamid) VALUES (?, ?, ?, ?)", [rngkey.toString(), message.author.id, message.author.username, req.user.steamid]);
res.send(req.user).end();
}
}).catch(() => {
console.error;
sql.run("CREATE TABLE IF NOT EXISTS info (key TEXT, userid TEXT, name TEXT, steamid TEXT)").then(() => {
sql.run("INSERT INTO info (key, userid, name, steamid) VALUES (?, ?, ?, ?)", [rngkey.toString(), message.author.id, message.author.username, req.user.steamid]);
});
});
});
This is what the table looks like
是否可以从auth页面获取/:userid(rngkey),然后将Steamid插入该键行?
答案 0 :(得分:1)
通过将代码放在client.on内解决了我的问题,并且效果很好。