gaber-elsayed

xp mysql

Jul 2nd, 2021
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. var con = mysql.createConnection({ //creating a connection
  2. host: "localhost", //localhost means your ip
  3. user: "root", // root is default username for mysql
  4. password: "", // Your own password that you select in the mysql installer
  5. database: "xrokz" // database that i created in the bigging: CREATE DATABASE {any name};
  6. });
  7. ///////////////
  8. //MySQL download in the description
  9. //commands in mysql command line:
  10. //CREATE DATABASE xrokz;
  11. //USE xrokz;
  12. //CREATE TABLE userDI (userID varchar(30) NOT NULL, userXP INT NOT NULL);
  13. ///////////////
  14. con.connect(e => {
  15. if(e) return;
  16. console.log("CONNECTED");
  17. });
  18.  
  19. function xp() {
  20. return Math.floor(Math.random() * (30 - 20 + 1) + 20);
  21. }
  22.  
  23. client.on('message', message => {
  24. con.query('SELECT * FROM userDI', (e, rows) => {
  25. if(e) return;
  26. let sql;
  27. if(!rows || !rows[0] || rows.length < 1) { // if user dont have any previous xp do this
  28. sql = `INSERT INTO userDI (userID, userXP) VALUES ('${message.author.id}', ${xp()})`
  29. console.log("VALUES ADDED");
  30. } else { // if he has do this
  31. let pxp = rows[0].userXP
  32. sql = `UPDATE userDI SET userXP = ${pxp + xp()} WHERE userID = '${message.author.id}'` //did you see any thing ? lol
  33. console.log("VALUES ADDED");
  34. }
  35. con.query(sql); //lol
  36. });
  37. //now im gonna create a xp command to see my xp
  38.  
  39.  
  40. });// lagging ._.
  41.  
  42. client.on('message', message => {
  43. let id = message.content.split(" ").slice(1).join(" ");
  44. let men = message.mentions.users.first() || message.author;
  45. if(message.content.startsWith('-xp')) {
  46. con.query(`SELECT * FROM userDI WHERE userID = '${men.id}'`, (err, rows) => { // dont switch between them err first !
  47. if(err) return;
  48. if(!rows[0]) return message.channel.send("There is no details on record");
  49. let xt = rows[0].userXP
  50. message.channel.send(`${men.username} xp is ${xt}`);
  51. });
  52. }
  53. })//im gonna kill my self
  54. // to be honest i got rid from these errors so i use google i fixed it
  55. //Credits for xRokz & codes server
  56. //you gonna find the code in description below.
Advertisement
Add Comment
Please, Sign In to add comment