Advertisement
n3k4a

Untitled

Mar 26th, 2019
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.64 KB | None | 0 0
  1.  
  2. // Calling Packages
  3. const Discord = require('discord.js');
  4. const bot = new Discord.Client();
  5. const fs = require('fs');
  6. const db = require('quick.db');
  7.  
  8. // We can call the file with all the functions here.
  9. const func = require('./functions.js'); // If this returns an error for you (or you might be on ubuntu/linux), try '../functions.js'
  10. // You can also change the name of func to something else like tools.
  11.  
  12. // We can call the JSON file here
  13. const commands = JSON.parse(fs.readFileSync('Storage/commands.json', 'utf8'));
  14. // We need to call the serverPrefixes JSON file
  15. const serverPrefixes = JSON.parse(fs.readFileSync('Storage/serverPrefixes.json', 'utf8'))
  16.  
  17. // Global Settings
  18. const prefix = '~'; // This is the prefix, you can change it to whatever you want.
  19.  
  20. // Listener Event: Runs whenever a message is received.
  21. bot.on('message', message => {
  22.  
  23. // Variables - Variables make it easy to call things, since it requires less typing.
  24. let msg = message.content.toUpperCase(); // This variable takes the message, and turns it all into uppercase so it isn't case sensitive.
  25. let sender = message.author; // This variable takes the message, and finds who the author is.
  26. let args = message.content.slice(prefix.length).trim().split(" "); // This variable slices off the prefix, then puts the rest in an array based off the spaces
  27. let cmd = args.shift().toLowerCase(); // This takes away the first object in the cont array, then puts it in this.
  28.  
  29. // Message Leveling System - Make sure you require quick.db
  30. db.updateValue(message.author.id + message.guild.id, 1).then(i => { // You pass it the key, which is authorID + guildID, then pass it an increase which is 1 in this instance.
  31. // It also returns the new updated object, which is what we will use.
  32.  
  33. let messages; // Create an empty variable - These IF statements will run if the new amount of messages sent is the same as the number.
  34. if (i.value == 25) messages = 25; // Level 1
  35. else if (i.value == 50) messages = 50; // Level 2
  36. else if (i.value == 100) messages = 100; // Level 3 - You can set these to any number, and any amount of them.
  37.  
  38. if (!isNaN(messages)) { // If messages IS STILL empty, run this.
  39. db.updateValue(`userLevel_${message.author.id + message.guild.id}`, 1).then(o => { // This returns the updated object of userLevel_ID.
  40. message.channel.send(`You sent ${messages} messages, so you leveled up! You are now level ${o.value}`) // Send their updated level to the channel.
  41. })
  42. }
  43.  
  44. })
  45.  
  46. // We also need to make sure it doesn't respond to bots
  47. if (sender.bot) return;
  48. if (!message.content.startsWith(prefix)) return; // We also want to make it so that if the message does not start with the prefix, return.
  49.  
  50. // Command Handler - .trim() removes the blank spaces on both sides of the string
  51. try {
  52. let commandFile = require(`./commands/${cmd}.js`); // This will assign that filename to commandFile
  53. commandFile.run(bot, message, args, func); // This will add the functions, from the functions.js file into each commandFile.
  54. } catch (e) { // If an error occurs, this will run.
  55. console.log(e.message); // This logs the error message
  56. } finally { // This will run after the first two clear up
  57. console.log(`${message.author.username} ran the command: ${cmd}`);
  58. }
  59.  
  60. });
  61.  
  62. // Listener Event: Runs whenever the bot sends a ready event (when it first starts for example)
  63. bot.on('ready', () => {
  64.  
  65. // We can post into the console that the bot launched.
  66. console.log('Bot started.');
  67.  
  68. });
  69.  
  70. bot.login('<token>');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement