Advertisement
n3k4a

Untitled

Mar 26th, 2019
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.95 KB | None | 0 0
  1.  
  2. Save New Duplicate & Edit Just Text Twitter
  3. 1
  4. 2
  5. 3
  6. 4
  7. 5
  8. 6
  9. 7
  10. 8
  11. 9
  12. 10
  13. 11
  14. 12
  15. 13
  16. 14
  17. 15
  18. 16
  19. 17
  20. 18
  21. 19
  22. 20
  23. 21
  24. 22
  25. 23
  26. 24
  27. 25
  28. 26
  29. 27
  30. 28
  31. 29
  32. 30
  33. 31
  34. 32
  35. 33
  36. 34
  37. 35
  38. 36
  39. 37
  40. 38
  41. 39
  42. 40
  43. 41
  44. 42
  45. 43
  46. 44
  47. 45
  48. 46
  49. 47
  50. 48
  51. 49
  52. 50
  53. 51
  54. 52
  55. 53
  56. 54
  57. 55
  58. 56
  59. 57
  60. 58
  61. 59
  62. 60
  63. 61
  64. 62
  65. 63
  66. 64
  67. 65
  68. 66
  69. 67
  70. 68
  71. 69
  72. // Calling Packages
  73. const Discord = require('discord.js');
  74. const bot = new Discord.Client();
  75. const fs = require('fs');
  76. const db = require('quick.db');
  77.  
  78. // We can call the file with all the functions here.
  79. const func = require('./functions.js'); // If this returns an error for you (or you might be on ubuntu/linux), try '../functions.js'
  80. // You can also change the name of func to something else like tools.
  81.  
  82. // We can call the JSON file here
  83. const commands = JSON.parse(fs.readFileSync('Storage/commands.json', 'utf8'));
  84. // We need to call the serverPrefixes JSON file
  85. const serverPrefixes = JSON.parse(fs.readFileSync('Storage/serverPrefixes.json', 'utf8'))
  86.  
  87. // Global Settings
  88. const prefix = '~'; // This is the prefix, you can change it to whatever you want.
  89.  
  90. // Listener Event: Runs whenever a message is received.
  91. bot.on('message', message => {
  92.  
  93. // Variables - Variables make it easy to call things, since it requires less typing.
  94. let msg = message.content.toUpperCase(); // This variable takes the message, and turns it all into uppercase so it isn't case sensitive.
  95. let sender = message.author; // This variable takes the message, and finds who the author is.
  96. 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
  97. let cmd = args.shift().toLowerCase(); // This takes away the first object in the cont array, then puts it in this.
  98.  
  99. // Message Leveling System - Make sure you require quick.db
  100. 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.
  101. // It also returns the new updated object, which is what we will use.
  102.  
  103. let messages; // Create an empty variable - These IF statements will run if the new amount of messages sent is the same as the number.
  104. if (i.value == 25) messages = 25; // Level 1
  105. else if (i.value == 50) messages = 50; // Level 2
  106. else if (i.value == 100) messages = 100; // Level 3 - You can set these to any number, and any amount of them.
  107.  
  108. if (!isNaN(messages)) { // If messages IS STILL empty, run this.
  109. db.updateValue(`userLevel_${message.author.id + message.guild.id}`, 1).then(o => { // This returns the updated object of userLevel_ID.
  110. message.channel.send(`You sent ${messages} messages, so you leveled up! You are now level ${o.value}`) // Send their updated level to the channel.
  111. })
  112. }
  113.  
  114. })
  115.  
  116. // We also need to make sure it doesn't respond to bots
  117. if (sender.bot) return;
  118. if (!message.content.startsWith(prefix)) return; // We also want to make it so that if the message does not start with the prefix, return.
  119.  
  120. // Command Handler - .trim() removes the blank spaces on both sides of the string
  121. try {
  122. let commandFile = require(`./commands/${cmd}.js`); // This will assign that filename to commandFile
  123. commandFile.run(bot, message, args, func); // This will add the functions, from the functions.js file into each commandFile.
  124. } catch (e) { // If an error occurs, this will run.
  125. console.log(e.message); // This logs the error message
  126. } finally { // This will run after the first two clear up
  127. console.log(`${message.author.username} ran the command: ${cmd}`);
  128. }
  129.  
  130. });
  131.  
  132. // Listener Event: Runs whenever the bot sends a ready event (when it first starts for example)
  133. bot.on('ready', () => {
  134.  
  135. // We can post into the console that the bot launched.
  136. console.log('Bot started.');
  137.  
  138. });
  139.  
  140. bot.login('<token>');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement