Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const Discord = require("discord.js");
- const Config = require("./config.json");
- const Token = require("./token.json");
- const fs = require("fs");
- const superagent = require("superagent");
- let config = require("./config.json")
- const bot = new Discord.Client();
- bot.commands = new Discord.Collection();
- fs.readdir("./commands/", (err, files) =>{
- if(err) console.log(err);
- let jsfile = files.filter(f => f.split(".").pop() === "js");
- if(jsfile.length <= 0 ){
- console.log("Could not find the command");
- return;
- }
- jsfile.forEach((f, i) =>{
- let props = require(`./commands/${f}`);
- console.log(`${f} has loaded and is now working!`);
- bot.commands.set(props.help.name, props);
- });
- });
- //${bot.guilds.size} servers!
- bot.on("ready", async () =>{
- console.log (`${bot.user.username} is online! It's running on ${bot.guilds.size} servers!`);
- bot.user.setActivity(`S2help`, {type:"PLAYING"});
- })
- //start of joins
- bot.on("guildMemberAdd", async member => {
- // send a dm
- 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!!");
- });
- //end of joins
- bot.on("message", async message => {
- if(message.author.bot) return;
- if(message.channel.type === "dm") return;
- let prefixes = JSON.parse(fs.readFileSync("./prefixes.json", "utf8"));
- if(!prefixes[message.guild.id]){
- prefixes[message.guild.id] = {
- prefixes: config.prefix
- };
- }
- let prefix = prefixes[message.guild.id].prefixes;
- if(!message.content.startsWith(prefix)) return;
- let messageArray = message.content.split(" ");
- let cmd = messageArray[0];
- let args = messageArray.slice(1);
- let commandfile = bot.commands.get(cmd.slice(prefix.length));
- if(commandfile) commandfile.run(bot, message, args);
- //////////////////////////////////////////////////////////////////////////////////////////////
- const db = require("enmap");
- if (message.author.bot) return;
- if (message.channel.type !== `text`) {
- let active = await bot.db.get(`support_${message.author.id}`);
- let guild = client.guilds.get(`guildID`);
- let channel, found = true;
- try{
- if (active) client.channels.get(active.channelID).guild;
- } catch (e) {
- found = false;
- }
- if (!active || !found) {
- active = {};
- channel = await guild.channels.create(`${message.author.username}-${message.author.discriminator}`, {
- parent: `522562841123880977`,
- topic: `When this support ticket is complete do *complete* to close the ticket | Support ticket for ${message.author.tag} | ID: ${message.author.id}`
- });
- let author = message.author;
- //embed
- const newChannel = new Discord.MessageEmbed()
- .setColor(0x36393e)
- .setAuthor(author.tag, author.displayAvatarURL())
- .setFooter("Support Ticket Created")
- .addField(`User`, author)
- .addField("User's ID", author.id)
- await channel.send(newChannel);
- //sends user the confirmation
- const newTicket = new Discord.MessageEmbed()
- .setColor(0x36393e)
- .setAuthor(`Hello, ${author.tag}`, author.displayAvatarURL())
- .setFooter("Support Ticket Created")
- //sends pm embed
- await author.send(newTicket);
- //updates data
- active.channelID = channel.id;
- active.targetID = author.id
- }
- //sends the message author said into support channels
- channel = client.channels.get(active.channelID);
- //create dm embed
- const dm = new Discord.MessageEmbed()
- .setColor(0x36393e)
- .setAuthor(`Thank you, ${message.author.tag}`, message.author.displayAvatarURL())
- .setFooter(`Your message has been sent! A staff member will be in contact with you soon!`)
- //sends embed
- await message.author.send(dm);
- const embed = new Discord.MessageEmbed()
- .setColor(0x36393e)
- .setAuthor(message.author.tag, message.author.displayAvatarURL())
- .setDescription(message.content)
- .setFooter(`Message Recieved -- ${message.author.tag}`)
- //sends embed
- await channel.send(embed);
- //updates database
- db.set(`support_${message.author.id}`, active);
- db.set(`supportChannel_${channel.id}`, message.author.id);
- return;
- }
- let support = await bot.db.get(`supportChannel_${message.channel.id}`);
- if (support) {
- support = await bot.db.get(`support_${support}`);
- let supportUser = client.users.get(support.targetID);
- if (!supportUser) return message.channel.delete();
- if (message.content.toLowerCase() === `*complete`) {
- const complete = new Discord.MessageEmbed()
- .setColor(0x36393e)
- .setAuthor(`Hey, ${supportUser.tag}`, supportUser.displayAvatarURL())
- .setFooter(`Ticket Closed -- Staffy's Support Server`)
- .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) *`)
- //sends the message
- supportUser.send(complete);
- //deletes the support channel
- message.channel.delete();
- db.delete(`support_${support.targetID}`);
- }
- //embed
- const embed = new Discord.MessageEmbed()
- .setColor(0x36393e)
- .setAuthor(message.author.tag, message.author.displayAvatarURL())
- .setFooter(`Message Recieved -- Staffy's Support Server`)
- .setDescription(message.content)
- // sends the embed in dm
- client.users.get(support.targetID).send(embed)
- message.delete({timeout: 1000});
- //modifys the embed
- embed.setFooter(`Message Sent -- ${supportUser.tag}`).setDescription(message.content);
- //sends and returns
- return message.channel.send(embed)
- }
- //////////////////////////////////////////////////////////////////////////////////////////////
- })
- bot.login(Token.token);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement