Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const { CommandoClient } = require('discord.js-commando');
- const mysql = require("mysql");
- const token = require("./token.json");
- let coins = require("./coins.json");
- const client = new CommandoClient({
- commandPrefix: '~',
- owner: '142764278582214656',
- });
- var con = mysql.createConnection({
- host: "localhost",
- user: "root",
- password: "-",
- database: "-"
- });
- con.connect(err => {
- if(err) throw err;
- console.log("I'm connected to the database! ~")
- con.query("SHOW TABLES");
- });
- client.registry.registerGroup('random');
- client.registry.registerGroup('advertising');
- client.registry.registerGroup('other');
- client.registry.registerGroup('xp');
- client.registry.registerDefaults();
- client.registry.registerCommandsIn(__dirname + "/commands")
- client.on('ready', () => {
- console.log('Im online! ~')
- client.user.setActivity('Reciting the vitamin hymns.');
- });
- function generateXp() {
- let min = 1;
- let max = 1;
- return Math.floor(Math.random() * (max - min + 1)) + min;
- }
- client.on("message", async message => {
- if(message.author.bot) return;
- if(message.channel.type === "dm") return;
- if(!coins[message.author.id]){
- coins[message.author.id] = {
- coins: 0
- };
- }
- let coinAmt = Math.floor(Math.random() * 1) + 1;
- let baseAmt = Math.floor(Math.random() * 1) + 1;
- console.log(`${coinAmt} ; ${baseAmt}`);
- if(coinAmt === baseAmt){
- coins[message.author.id] = {
- coins: coins[message.author.id].coins + coinAmt
- };
- fs.writeFile("./coins.json", JSON.stringify(coins), (err) => {
- if (err) console.log(err)
- });
- }
- con.query(`SELECT * FROM xp WHERE id = '${message.author.id}'`, (err,rows) => {
- if(err) throw err;
- let sql;
- if(rows.length < 1) {
- sql = `INSERT INTO xp (id, xp) VALUES ('${message.author.id}', ${generateXp()})`;
- } else {
- let xp = rows[0].xp;
- sql = `UPDATE xp SET xp = ${xp + generateXp()} WHERE id = '${message.author.id}'`;
- }
- con.query(sql)
- })
- });
- client.login(token.token);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement