Javascript 能力。提示:不要在查询中使用模板字符串,避免插入的诱惑。您可能遇到了错误情况和/或在回调链的某个位置丢了球。这真的很难说,因为这段代码相当复杂。 const db = require('mysql2-promise')(); const crypto =
Javascript 能力。提示:不要在查询中使用模板字符串,避免插入的诱惑。您可能遇到了错误情况和/或在回调链的某个位置丢了球。这真的很难说,因为这段代码相当复杂。 const db = require('mysql2-promise')(); const crypto = ,javascript,mysql,node.js,promise,discord.js,Javascript,Mysql,Node.js,Promise,Discord.js,能力。提示:不要在查询中使用模板字符串,避免插入的诱惑。您可能遇到了错误情况和/或在回调链的某个位置丢了球。这真的很难说,因为这段代码相当复杂。 const db = require('mysql2-promise')(); const crypto = require('crypto'); db.configure({ host: "localhost", user: "root", password: ""
能力。提示:不要在查询中使用模板字符串,避免插入的诱惑。您可能遇到了错误情况和/或在回调链的某个位置丢了球。这真的很难说,因为这段代码相当复杂。
const db = require('mysql2-promise')();
const crypto = require('crypto');
db.configure({
host: "localhost",
user: "root",
password: "",
database: ""
});
module.exports = {
name: 'acc',
description: "Used to manage accounts!",
async execute(message, args, cmd, client, Discord){
const guild = await client.guilds.cache.get('something');
if(!guild) return message.author.send("Guild error!");
let member = await guild.members.fetch(message.author.id);
if(!member) return message.author.send("Member error!");
let role = await member.roles.cache.has('something');
if(!role) return message.author.send("You don't have access to this command :eyes:");
if(!args[0]) return message.author.send("Needs extra arguments!");
if(args[0] === 'create') {
if(!args[1]) return message.author.send("Needs both username and password!");
if(!args[2]) return message.author.send("Needs a password!");
db.query(`SELECT * FROM account WHERE discordid = '${message.author.id}'`, (err, rows) => {
if(err) throw err;
let sql;
if (rows.length < 1) {
var hash = crypto.createHash('md5').update(args[2]).digest('hex');
sql = `INSERT INTO account (username, password, discordid) VALUES (?, ?, ?)`;
db.execute(sql, [args[1], hash, message.author.id]);
message.author.send("Created your account!");
} else {
message.author.send("Can't create your account!");
}
});
}
if(args[0] === 'changeuser') {
if(!args[1]) return message.author.send("Needs to know the new username!");
db.query(`SELECT * FROM account WHERE discordid = '${message.author.id}'`, (err, rows) => {
if(err) throw err;
let sql;
if (rows.length < 1) {
message.author.send("Can't find your account!");
} else {
sql = `UPDATE account SET username = ? WHERE discordid = ?`;
db.execute(sql, [args[1], message.author.id]);
message.author.send("Changed your username!");
}
});
}
if(args[0] === 'changepass') {
if(!args[1]) return message.author.send("Needs to know the new password!");
db.query(`SELECT * FROM account WHERE discordid = '${message.author.id}'`, (err, rows) => {
if(err) throw err;
let sql;
if (rows.length < 1) {
message.author.send("Can't find your account!");
} else {
var hash = crypto.createHash('md5').update(args[1]).digest('hex');
sql = `UPDATE account SET password = ? WHERE discordid = ?`;
db.execute(sql, [hash, message.author.id]);
message.author.send("Changed your password!");
}
});
}
if(args[0] === 'link') {
if(!args[1]) return message.author.send("Needs both username and password!");
if(!args[2]) return message.author.send("Needs a password!");
db.query(`SELECT * FROM account WHERE discordid = '${message.author.id}'`, (err, rows) => {
if(err) throw err;
let sql;
if (rows.length < 1) {
sql = `SELECT * FROM account WHERE username = ? AND password = ?`;
var hash = crypto.createHash('md5').update(args[2]).digest('hex').toLowerCase();
db.execute(`SELECT * FROM account WHERE username = '${args[1]}' AND password = '${hash}'`, (err, rows) => {
if(err) throw err;
let sql2;
if(rows.length < 1) {
message.author.send("Can't find that account to link...");
} else {
sql2 = `UPDATE account SET discordid = ? WHERE username = ?`;
db.execute(sql2, [message.author.id, args[1]], (err) => {
if(err) throw err;
});
message.author.send("Linked your account!");
}
});
} else {
message.author.send("You already have an account :eyes:");
}
});
}
}
}