Advertisement
williambriggs

Untitled

Oct 23rd, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. const config = require("./config.json");
  2. const Discord = require("discord.js");
  3. const math = require("mathjs");
  4. const fs = require("fs");
  5. const express = require(`express`);
  6. const mysql = require(`mysql`);
  7. const bot = new Discord.Client({disableEveryone: true});
  8. bot.commands = new Discord.Collection();
  9.  
  10. // mySQL setup
  11. const db = mysql.createConnection({
  12. host : '',
  13. user : '',
  14. password : '',
  15. database : '',
  16. port : ''
  17. });
  18.  
  19. db.connect((err) => {
  20. if(err){
  21. throw err;
  22. }
  23. console.log('MySql Connected...');
  24. });
  25.  
  26. const app = express();
  27.  
  28. app.get('/createpoststable', (req, res) => {
  29. let sql = 'CREATE TABLE posts(id int AUTO_INCREMENT, title VARCHAR(255), body VARCHAR(255), PRIMARY KEY(id))';
  30. db.query(sql, (err, result) => {
  31. if(err) throw err;
  32. console.log(result);
  33. res.send('Posts table created...');
  34. });
  35. });
  36.  
  37.  
  38.  
  39.  
  40.  
  41. fs.readdir("./commands/", (err, files) => {
  42.  
  43. if(err) console.log(err);
  44.  
  45. let jsfile = files.filter(f => f.split(".").pop() === "js")
  46. if(jsfile.length <= 0){
  47. console.log("Couldn't find commands.");
  48. return;
  49. }
  50.  
  51. jsfile.forEach((f, i) =>{
  52. let props = require(`./commands/${f}`);
  53. console.log(`${f} loaded!`);
  54. bot.commands.set(props.help.name, props);
  55. });
  56.  
  57. });
  58.  
  59. bot.on("ready", async () => {
  60. console.log(`${bot.user.username} is online on ${bot.guilds.size} servers!`);
  61. bot.user.setActivity("You learn!", {type: "WATCHING"});
  62. });
  63.  
  64. bot.on("guildMemberAdd", function(member) {
  65. if(!profile[member.id]) profile[member.id] = {
  66. name: "not set",
  67. class: "not set",
  68. id: "not set"
  69. };
  70. fs.writeFile("./profiles.json", JSON.stringify(profile), (err) => {
  71. if (err) console.log(err)
  72. });
  73. })
  74.  
  75. bot.on("message", async message => {
  76. if(message.author.bot) return;
  77. if(message.channel.type === "dm") return;
  78.  
  79. let prefix = config.prefix;
  80. let messageArray = message.content.split(" ");
  81. let cmd = messageArray[0];
  82. let args = messageArray.slice(1);
  83.  
  84. if (message.content.startsWith(config.prefix)) {
  85. let commandfile = bot.commands.get(cmd.slice(prefix.length));
  86. if(commandfile) commandfile.run(bot,message,args);
  87.  
  88. }
  89. });
  90.  
  91. bot.login(config.token);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement