Advertisement
dfhfjjfgjfsfeedgf

Untitled

Dec 15th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.80 KB | None | 0 0
  1. const Discord = require("discord.js");
  2. const Config = require("./config.json");
  3. const Token = require("./token.json");
  4. const fs = require("fs");
  5. const superagent = require("superagent");
  6. let config = require("./config.json")
  7.  
  8.  
  9. const bot = new Discord.Client();
  10. bot.commands = new Discord.Collection();
  11.  
  12. fs.readdir("./commands/", (err, files) =>{
  13. if(err) console.log(err);
  14. let jsfile = files.filter(f => f.split(".").pop() === "js");
  15. if(jsfile.length <= 0 ){
  16. console.log("Could not find the command");
  17. return;
  18. }
  19.  
  20. jsfile.forEach((f, i) =>{
  21. let props = require(`./commands/${f}`);
  22. console.log(`${f} has loaded and is now working!`);
  23. bot.commands.set(props.help.name, props);
  24. });
  25. });
  26. //${bot.guilds.size} servers!
  27. bot.on("ready", async () =>{
  28. console.log (`${bot.user.username} is online! It's running on ${bot.guilds.size} servers!`);
  29. bot.user.setActivity(`S2help`, {type:"PLAYING"});
  30. })
  31.  
  32. //start of joins
  33. bot.on("guildMemberAdd", async member => {
  34. // send a dm
  35. member.send("Hey there! My name is ***Staffy 2.0*** i am a Discord bot specified for ***Staffy's Suppport Server*** If you need help just do `S2help` and i will PM/DM you a list of commands :) Make sure to read our rules!!");
  36. });
  37. //end of joins
  38.  
  39.  
  40. bot.on("message", async message => {
  41.  
  42. if(message.author.bot) return;
  43. if(message.channel.type === "dm") return;
  44.  
  45. let prefixes = JSON.parse(fs.readFileSync("./prefixes.json", "utf8"));
  46. if(!prefixes[message.guild.id]){
  47. prefixes[message.guild.id] = {
  48. prefixes: config.prefix
  49. };
  50. }
  51. let prefix = prefixes[message.guild.id].prefixes;
  52. if(!message.content.startsWith(prefix)) return;
  53. let messageArray = message.content.split(" ");
  54. let cmd = messageArray[0];
  55. let args = messageArray.slice(1);
  56.  
  57. let commandfile = bot.commands.get(cmd.slice(prefix.length));
  58. if(commandfile) commandfile.run(bot, message, args);
  59. //////////////////////////////////////////////////////////////////////////////////////////////
  60. const db = require("enmap");
  61. if (message.author.bot) return;
  62. if (message.channel.type !== `text`) {
  63. let active = await bot.db.get(`support_${message.author.id}`);
  64. let guild = client.guilds.get(`guildID`);
  65. let channel, found = true;
  66. try{
  67. if (active) client.channels.get(active.channelID).guild;
  68. } catch (e) {
  69. found = false;
  70. }
  71. if (!active || !found) {
  72.  
  73. active = {};
  74.  
  75. channel = await guild.channels.create(`${message.author.username}-${message.author.discriminator}`, {
  76. parent: `522562841123880977`,
  77. topic: `When this support ticket is complete do *complete* to close the ticket | Support ticket for ${message.author.tag} | ID: ${message.author.id}`
  78. });
  79.  
  80. let author = message.author;
  81.  
  82. //embed
  83. const newChannel = new Discord.MessageEmbed()
  84. .setColor(0x36393e)
  85. .setAuthor(author.tag, author.displayAvatarURL())
  86. .setFooter("Support Ticket Created")
  87. .addField(`User`, author)
  88. .addField("User's ID", author.id)
  89.  
  90. await channel.send(newChannel);
  91.  
  92. //sends user the confirmation
  93. const newTicket = new Discord.MessageEmbed()
  94. .setColor(0x36393e)
  95. .setAuthor(`Hello, ${author.tag}`, author.displayAvatarURL())
  96. .setFooter("Support Ticket Created")
  97.  
  98. //sends pm embed
  99. await author.send(newTicket);
  100.  
  101. //updates data
  102. active.channelID = channel.id;
  103. active.targetID = author.id
  104.  
  105. }
  106.  
  107. //sends the message author said into support channels
  108. channel = client.channels.get(active.channelID);
  109.  
  110. //create dm embed
  111. const dm = new Discord.MessageEmbed()
  112. .setColor(0x36393e)
  113. .setAuthor(`Thank you, ${message.author.tag}`, message.author.displayAvatarURL())
  114. .setFooter(`Your message has been sent! A staff member will be in contact with you soon!`)
  115.  
  116. //sends embed
  117. await message.author.send(dm);
  118.  
  119. const embed = new Discord.MessageEmbed()
  120. .setColor(0x36393e)
  121. .setAuthor(message.author.tag, message.author.displayAvatarURL())
  122. .setDescription(message.content)
  123. .setFooter(`Message Recieved -- ${message.author.tag}`)
  124.  
  125. //sends embed
  126. await channel.send(embed);
  127.  
  128. //updates database
  129. db.set(`support_${message.author.id}`, active);
  130. db.set(`supportChannel_${channel.id}`, message.author.id);
  131. return;
  132. }
  133.  
  134. let support = await bot.db.get(`supportChannel_${message.channel.id}`);
  135.  
  136. if (support) {
  137.  
  138. support = await bot.db.get(`support_${support}`);
  139.  
  140. let supportUser = client.users.get(support.targetID);
  141. if (!supportUser) return message.channel.delete();
  142.  
  143. if (message.content.toLowerCase() === `*complete`) {
  144.  
  145. const complete = new Discord.MessageEmbed()
  146. .setColor(0x36393e)
  147. .setAuthor(`Hey, ${supportUser.tag}`, supportUser.displayAvatarURL())
  148. .setFooter(`Ticket Closed -- Staffy's Support Server`)
  149. .setDescription(`*Your ticket has been marked as **complete**. If you whish to re-open this or create a new one, please PM/DM the discord bot (Staffy 2.0) *`)
  150.  
  151. //sends the message
  152. supportUser.send(complete);
  153.  
  154. //deletes the support channel
  155. message.channel.delete();
  156.  
  157. db.delete(`support_${support.targetID}`);
  158.  
  159. }
  160.  
  161. //embed
  162. const embed = new Discord.MessageEmbed()
  163. .setColor(0x36393e)
  164. .setAuthor(message.author.tag, message.author.displayAvatarURL())
  165. .setFooter(`Message Recieved -- Staffy's Support Server`)
  166. .setDescription(message.content)
  167.  
  168. // sends the embed in dm
  169. client.users.get(support.targetID).send(embed)
  170.  
  171. message.delete({timeout: 1000});
  172.  
  173. //modifys the embed
  174. embed.setFooter(`Message Sent -- ${supportUser.tag}`).setDescription(message.content);
  175.  
  176. //sends and returns
  177. return message.channel.send(embed)
  178.  
  179. }
  180.  
  181.  
  182. //////////////////////////////////////////////////////////////////////////////////////////////
  183.  
  184. })
  185.  
  186.  
  187.  
  188. bot.login(Token.token);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement