Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const config = require("./config.json");
- const Discord = require("discord.js");
- const math = require("mathjs");
- const fs = require("fs");
- const express = require(`express`);
- const mysql = require(`mysql`);
- const bot = new Discord.Client({disableEveryone: true});
- bot.commands = new Discord.Collection();
- // mySQL setup
- const db = mysql.createConnection({
- host : '',
- user : '',
- password : '',
- database : '',
- port : ''
- });
- db.connect((err) => {
- if(err){
- throw err;
- }
- console.log('MySql Connected...');
- });
- const app = express();
- app.get('/createpoststable', (req, res) => {
- let sql = 'CREATE TABLE posts(id int AUTO_INCREMENT, title VARCHAR(255), body VARCHAR(255), PRIMARY KEY(id))';
- db.query(sql, (err, result) => {
- if(err) throw err;
- console.log(result);
- res.send('Posts table created...');
- });
- });
- fs.readdir("./commands/", (err, files) => {
- if(err) console.log(err);
- let jsfile = files.filter(f => f.split(".").pop() === "js")
- if(jsfile.length <= 0){
- console.log("Couldn't find commands.");
- return;
- }
- jsfile.forEach((f, i) =>{
- let props = require(`./commands/${f}`);
- console.log(`${f} loaded!`);
- bot.commands.set(props.help.name, props);
- });
- });
- bot.on("ready", async () => {
- console.log(`${bot.user.username} is online on ${bot.guilds.size} servers!`);
- bot.user.setActivity("You learn!", {type: "WATCHING"});
- });
- bot.on("guildMemberAdd", function(member) {
- if(!profile[member.id]) profile[member.id] = {
- name: "not set",
- class: "not set",
- id: "not set"
- };
- fs.writeFile("./profiles.json", JSON.stringify(profile), (err) => {
- if (err) console.log(err)
- });
- })
- bot.on("message", async message => {
- if(message.author.bot) return;
- if(message.channel.type === "dm") return;
- let prefix = config.prefix;
- let messageArray = message.content.split(" ");
- let cmd = messageArray[0];
- let args = messageArray.slice(1);
- if (message.content.startsWith(config.prefix)) {
- let commandfile = bot.commands.get(cmd.slice(prefix.length));
- if(commandfile) commandfile.run(bot,message,args);
- }
- });
- bot.login(config.token);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement