Advertisement
HelloDearSir

Untitled

Jan 6th, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.04 KB | None | 0 0
  1. botconfig.json
  2. {
  3.  
  4. "token": "NTI0NjY5Mzg4OTc3MDc4Mjg1.DxOcFA.VrZw92J70yjz8RJnvkatfHDlRlU",
  5. "prefix": "d!"
  6.  
  7. }
  8.  
  9. main.js
  10.  
  11. //commando is the framework for discord.js
  12. //const Commando = require("discord.js-commando");
  13. //const bot = new Commando.Client();
  14. //this is the discord.js libary
  15. const Discord = require ("discord.js");
  16. //config file for JSON, this will get the prefix and the token from the discord.api
  17.  
  18. const botconfig = require('./config.json');
  19.  
  20. // from the discord.js libary.
  21. const client = new Discord.Client;
  22. client.commands = new Discord.Collection();
  23.  
  24. //bot.registry.registerGroup('admin', 'Admin');
  25. //bot.registry.registerCommandsIn( __dirname+ "/bot_commands");
  26.  
  27. //fs is for the file system to read them.
  28. const fs = require("fs");
  29.  
  30. //reading all the files in the folder
  31. //if theres any errors this will console.error if any appear.
  32. fs.readdir("./botcommandz/",(err, files) =>{
  33. if(err) console.error(err);
  34. //filter will look through all the files and be true. pop will take the last part of the array.
  35. let jsfile = files.filter(f => f.split(".").pop() === "js")
  36. if(jsfile.length <= 0)
  37. {
  38. console.log("nothing to load");
  39.  
  40. }
  41. console.log(`loading ${jsfile} commands`);
  42. //Foreach loop was more better than using the basic for loop.
  43. jsfile.forEach((f,i) => {
  44. let props = require(`./botcommandz/${f}`);
  45. //this will load all the files in botcommandz and print this into the console.log.
  46. console.log(`${i+1}: ${f} Loaded`);
  47. //help.name will allow me to call the command
  48. client.commands.set(props.help.name, props);
  49. });
  50.  
  51.  
  52. });
  53.  
  54.  
  55. //When bot online it will, print to the console log that its online.
  56. //the setActivity is what is doing e.g. coding
  57. client.on("ready", async () =>
  58. {
  59. //When the bot is online, Can set the game its playing.
  60. console.log(`${client.user.username} is online!` );
  61. client.user.setActivity( `How many users online: ${client.guilds.size}`);
  62. console.log(client.commands);
  63.  
  64. });
  65.  
  66.  
  67.  
  68.  
  69. //let xp = require('./usersxp.json');
  70. let xp = require('./xp.json');
  71. //let coins = require('./coins.json');
  72.  
  73.  
  74.  
  75. client.on("message",async message =>
  76. {
  77. if(message.author.bot) return;
  78.  
  79.  
  80. //this is using the set prefix that I made in the congif.json.
  81. let prefix = botconfig.prefix;
  82.  
  83. //messageArray will use the message.content.split.
  84. let messageArray = message.content.split(" ");
  85.  
  86.  
  87. //args is an arugment .
  88. let args = messageArray.slice(1);
  89.  
  90.  
  91. //setting xpAdd to = math.floor(Math.random() * ) + ;
  92.  
  93. let xpAdd = Math.floor(Math.random() * 100) + 8;
  94. //console.log (xpadd) to see if it works.
  95. console.log(xpAdd);
  96. //if the users not created in the file yet, set them to xp:0, level 0
  97. if(!xp[message.author.id]){
  98. xp[message.author.id] = {
  99. xp: 0,
  100. level: 0
  101. };
  102. }
  103.  
  104. //let the current xp with the author.id e.g. 180783462578520064
  105. let currentxp = xp[message.author.id].xp;
  106. //let the current level with the author id. levle
  107. let currentlvl = xp[message.author.id].level;
  108. //each level up will take * 900. e.g. level 2 will be 1800 xp
  109. let nextlvl = xp[message.author.id].level * 900;
  110. // currentxp + xpAdd
  111. xp[message.author.id].xp = currentxp + xpAdd;
  112. //when xp gets to the nextlevel it will pop up the new level
  113. if(nextlvl <= xp[message.author.id].xp)
  114. {
  115. xp[message.author.id].level = currentlvl +1;
  116.  
  117. // using the RichEmbed from discord.js libary
  118. let levelup = new Discord.RichEmbed()
  119. .setTitle("Level uppp")
  120. //new field, will display the new level from currentlvl + 1.
  121. .addField("New Level",currentlvl + 1);
  122. message.channel.send(levelup);
  123. }
  124.  
  125. //write to the xp.json. if theres a error it will console.log it .
  126. fs.writeFile("./xp.json", JSON.stringify(xp), (error) => {
  127. if(error) console.log(error)
  128. });
  129.  
  130.  
  131.  
  132. });
  133.  
  134. client.on('guildMemberAdd', member => {
  135. member.guild.channels.get('channelID').send("Welcome d!help for any help");
  136. });
  137.  
  138. //While bot on, if pharase are said, the bot will react it different ways.
  139.  
  140. //this is the discord token from the botconfig.json
  141. client.login(botconfig.token);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement