DudeThatsErin

index.js

Mar 5th, 2021
748
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const fs = require('fs');
  2. const Discord = require('discord.js');
  3. const client = new Discord.Client();
  4. client.commands = new Discord.Collection();
  5. const config = require('./config.json');
  6.  
  7. let connection;
  8.  
  9. const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
  10.  
  11. for (const file of commandFiles) {
  12.     console.log(file.slice(0,-3));
  13.     const command = require(`./commands/${file.slice(0,-3)}`)
  14.     client.commands.set(command.name, command);
  15. }
  16.  
  17. client.on('ready', (guild) => {
  18.   console.log(`${client.user.tag} is logged in and ready!`);
  19.  
  20.   client.user.setPresence({
  21.     status: "ONLINE",
  22.     activity: {
  23.         name: `sm!help`,  
  24.         type: "LISTENING"
  25.     }
  26.   });
  27. });
  28. client.on('guildDelete', guild => {
  29.     // this event triggers when the bot is removed from a guild.
  30.     console.log(`I have been removed from: ${guild.name} (id: ${guild.id})`);
  31.  
  32. });
  33.  
  34. client.on('guildCreate', guild => {
  35.  
  36.   console.log(`New guild joined: ${guild.name} (id: ${guild.id}). This guild has ${guild.memberCount} members!`);
  37.  
  38.     try {
  39.     guild.members.cache.map( member => {
  40.       connection.query(
  41.            `INSERT INTO Points (guildId, user) VALUES ('${guild.id}', '${member.id}')`
  42.          );
  43.     });
  44.    }
  45.    catch{console.log(error);}
  46.    let challenge_role = guild.roles.cache.find(r => r.name === 'Participants');
  47.    let participants = guild.members.cache.filter(member => member.roles.cache.find(role => role == challenge_role)).map(mems => mems.user.id);
  48.    let challenge_channel = guild.channels.cache.find(c => c.name === 'Challenges');
  49.    if(!challenge_channel) {
  50.     guild.channels.create('Challenges', {
  51.         type: 'text',
  52.         reason: 'Sakura Moon needed a Challenges channel for the Challenges handler.',
  53.     }).then(console.log('The Challenges channel did not exist so I created one!')).catch(console.error);
  54. }
  55.    let submissions_channel = guild.channels.cache.find(ch => ch.name === 'Submissions');
  56.    if(!submissions_channel) {
  57.     guild.channels.create('Submissions', {
  58.         type: 'text',
  59.         reason: 'Sakura Moon needed a Submissions channel for the Challenges handler.'
  60.     }).then(console.log('The Submissions channel did not exist so I created one!')).catch(console.error);
  61. }
  62.  
  63.   connection.query(
  64.     `INSERT INTO Challenges (guildId, player, challengeAnnouncementsChannel, submissionsDumpChannel) VALUES ('${guild.id}', '${participants.id}', '${challenge_channel.id}', '${submissions_channel.id}')`
  65.   );
  66. });
  67.  
  68. client.on('error', function (err) {
  69.   console.log('Global error handler called:\n');
  70.   if(err) {console.log(err);}
  71. });
  72.  
  73. client.on('message', async message => { // Looking for a message
  74.  
  75.   /* ----------------------------------------------------------
  76.   NECESSARY PARTS OF THE FILE
  77.   -------------------------------------------------------------- */
  78.   if (!message.content.startsWith(config.client.prefix) || message.author.bot) return;
  79.  
  80.   const args = message.content.slice(config.client.prefix.length).trim().split(/ +/);
  81.   const commandName = args.shift().toLowerCase();
  82.   const command = client.commands.get(commandName)
  83.     || client.commands.find(cmd => cmd.aliases && cmd.aliases.includes(commandName));
  84.   if (!command) return;
  85.  
  86.   try {
  87.     command.execute(message, args);
  88.   } catch (error) {
  89.     console.error(error);
  90.     message.reply('there was an error trying to execute that command!');
  91.   }
  92.  
  93.   }); // end of looking
  94.  
  95.   (async () => {
  96.     connection = await require('./database.js');
  97.     await client.login(config.client.token);
  98.   })();
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×