Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var con = mysql.createConnection({ //creating a connection
- host: "localhost", //localhost means your ip
- user: "root", // root is default username for mysql
- password: "", // Your own password that you select in the mysql installer
- database: "xrokz" // database that i created in the bigging: CREATE DATABASE {any name};
- });
- ///////////////
- //MySQL download in the description
- //commands in mysql command line:
- //CREATE DATABASE xrokz;
- //USE xrokz;
- //CREATE TABLE userDI (userID varchar(30) NOT NULL, userXP INT NOT NULL);
- ///////////////
- con.connect(e => {
- if(e) return;
- console.log("CONNECTED");
- });
- function xp() {
- return Math.floor(Math.random() * (30 - 20 + 1) + 20);
- }
- client.on('message', message => {
- con.query('SELECT * FROM userDI', (e, rows) => {
- if(e) return;
- let sql;
- if(!rows || !rows[0] || rows.length < 1) { // if user dont have any previous xp do this
- sql = `INSERT INTO userDI (userID, userXP) VALUES ('${message.author.id}', ${xp()})`
- console.log("VALUES ADDED");
- } else { // if he has do this
- let pxp = rows[0].userXP
- sql = `UPDATE userDI SET userXP = ${pxp + xp()} WHERE userID = '${message.author.id}'` //did you see any thing ? lol
- console.log("VALUES ADDED");
- }
- con.query(sql); //lol
- });
- //now im gonna create a xp command to see my xp
- });// lagging ._.
- client.on('message', message => {
- let id = message.content.split(" ").slice(1).join(" ");
- let men = message.mentions.users.first() || message.author;
- if(message.content.startsWith('-xp')) {
- con.query(`SELECT * FROM userDI WHERE userID = '${men.id}'`, (err, rows) => { // dont switch between them err first !
- if(err) return;
- if(!rows[0]) return message.channel.send("There is no details on record");
- let xt = rows[0].userXP
- message.channel.send(`${men.username} xp is ${xt}`);
- });
- }
- })//im gonna kill my self
- // to be honest i got rid from these errors so i use google i fixed it
- //Credits for xRokz & codes server
- //you gonna find the code in description below.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement