├── config.json └── index.js /config.json: -------------------------------------------------------------------------------- 1 | { 2 | "prefix": "PREFIX", 3 | "ServerID": "SERVER ID" 4 | } 5 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | const discord = require("discord.js"); 2 | const client = new discord.Client() 3 | const { prefix, ServerID } = require("./config.json") 4 | const config = require('./config.json'); 5 | 6 | client.on("ready", () => { 7 | 8 | console.log("Bot online") 9 | client.user.setActivity("Watching My Dm's") 10 | }) 11 | 12 | 13 | 14 | client.on("channelDelete", (channel) => { 15 | if (channel.parentID == channel.guild.channels.cache.find((x) => x.name == "MODMAIL").id) { 16 | const person = channel.guild.members.cache.find((x) => x.id == channel.name) 17 | 18 | if (!person) return; 19 | 20 | let yembed = new discord.MessageEmbed() 21 | .setAuthor("MAIL DELETED", client.user.displayAvatarURL()) 22 | .setColor('RED') 23 | .setDescription("Your mail was deleted by a staff member!") 24 | return person.send(yembed) 25 | 26 | } 27 | 28 | 29 | }) 30 | 31 | 32 | 33 | 34 | 35 | client.on("message", async message => { 36 | if (message.author.bot) return; 37 | 38 | const args = message.content.slice(prefix.length).trim().split(/ +/g); 39 | let command = args.shift().toLowerCase(); 40 | 41 | 42 | if (message.guild) { 43 | 44 | if (command == "mod-mail") { 45 | if (!message.content.startsWith(prefix)) return; 46 | if (!message.member.hasPermission("ADMINISTRATOR")) { 47 | return message.channel.send("You need Admin Permissions to setup the modmail system!") 48 | } 49 | 50 | if (!message.guild.me.hasPermission("ADMINISTRATOR")) { 51 | return message.channel.send("Bot need Admin Permissions to setup the modmail system!") 52 | } 53 | 54 | 55 | let role = message.guild.roles.cache.find((x) => x.name == "Staff") 56 | let everyone = message.guild.roles.cache.find((x) => x.name == "@everyone") 57 | 58 | if (!role) { 59 | role = await message.guild.roles.create({ 60 | data: { 61 | name: "Staff", 62 | color: "YELLOW" 63 | }, 64 | reason: "Role needed for ModMail System" 65 | }) 66 | } 67 | 68 | await message.guild.channels.create("MODMAIL", { 69 | type: "category", 70 | topic: "All the mail will be here", 71 | permissionOverwrites: [ 72 | { 73 | id: role.id, 74 | allow: ["VIEW_CHANNEL", "SEND_MESSAGES", "READ_MESSAGE_HISTORY"] 75 | }, 76 | { 77 | id: everyone.id, 78 | deny: ["VIEW_CHANNEL", "SEND_MESSAGES", "READ_MESSAGE_HISTORY"] 79 | } 80 | ] 81 | }) 82 | 83 | 84 | return message.channel.send("Setup is Completed ✅") 85 | 86 | } else if (command == "close") { 87 | if (!message.content.startsWith(prefix)) return; 88 | if (!message.member.roles.cache.find((x) => x.name == "Staff")) { 89 | return message.channel.send("You need Staff role to use this command") 90 | } 91 | if (message.channel.parentID == message.guild.channels.cache.find((x) => x.name == "MODMAIL").id) { 92 | 93 | const person = message.guild.members.cache.get(message.channel.name) 94 | 95 | if (!person) { 96 | return message.channel.send("I am Unable to close the channel and this error is coming because probaly channel name is changed.") 97 | } 98 | 99 | await message.channel.delete() 100 | 101 | let yembed = new discord.MessageEmbed() 102 | .setAuthor("MAIL CLOSED", client.user.displayAvatarURL()) 103 | .setColor("RED") 104 | .setThumbnail(client.user.displayAvatarURL()) 105 | .setFooter("Mail is closed by " + message.author.username) 106 | if (args[0]) yembed.setDescription(`Reason: ${args.join(" ")}`) 107 | 108 | return person.send(yembed) 109 | 110 | } 111 | } else if (command == "open") { 112 | if (!message.content.startsWith(prefix)) return; 113 | const category = message.guild.channels.cache.find((x) => x.name == "MODMAIL") 114 | 115 | if (!category) { 116 | return message.channel.send("Moderation system is not setuped in this server, use " + prefix + "setup") 117 | } 118 | 119 | if (!message.member.roles.cache.find((x) => x.name == "Staff")) { 120 | return message.channel.send("You need `Staff` role to use this command") 121 | } 122 | 123 | if (isNaN(args[0]) || !args.length) { 124 | return message.channel.send("Please Give the ID of the person") 125 | } 126 | 127 | const target = message.guild.members.cache.find((x) => x.id === args[0]) 128 | 129 | if (!target) { 130 | return message.channel.send("Unable to find this person.") 131 | } 132 | 133 | 134 | const channel = await message.guild.channels.create(target.id, { 135 | type: "text", 136 | parent: category.id, 137 | topic: "Mail is Direct Opened by **" + message.author.username + "** to make contact with " + message.author.tag 138 | }) 139 | 140 | let nembed = new discord.MessageEmbed() 141 | .setAuthor("DETAILS", target.user.displayAvatarURL({ dynamic: true })) 142 | .setColor("BLUE") 143 | .setThumbnail(target.user.displayAvatarURL({ dynamic: true })) 144 | .setDescription(message.content) 145 | .addField("Name", target.user.username) 146 | .addField("Account Creation Date", target.user.createdAt) 147 | .addField("Direct Contact", "Yes(it means this mail is opened by a Staff)"); 148 | 149 | channel.send(nembed) 150 | 151 | let uembed = new discord.MessageEmbed() 152 | .setAuthor("DIRECT MAIL OPENED") 153 | .setColor("GREEN") 154 | .setThumbnail(client.user.displayAvatarURL()) 155 | .setDescription("You have been contacted by Staff of **" + message.guild.name + "**, Please wait until he send another message to you!"); 156 | 157 | 158 | target.send(uembed); 159 | 160 | let newEmbed = new discord.MessageEmbed() 161 | .setDescription("Opened The Mail: <#" + channel + ">") 162 | .setColor("GREEN"); 163 | 164 | return message.channel.send(newEmbed); 165 | } else if (command == "help") { 166 | if (!message.content.startsWith(prefix)) return; 167 | let embed = new discord.MessageEmbed() 168 | .setAuthor('MODMAIL BOT') 169 | .addField("$setup", "Setup the modmail system(This is not for multiple server.)", true) 170 | 171 | .addField("$open", 'Let you open the mail to contact anyone with his ID', true) 172 | .setThumbnail(client.user.displayAvatarURL()) 173 | .addField("$close", "Close the mail in which you use this command.", true); 174 | 175 | return message.channel.send(embed) 176 | 177 | } 178 | } 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | if (message.channel.parentID) { 187 | 188 | const category = message.guild.channels.cache.find((x) => x.name == "MODMAIL") 189 | 190 | if (message.channel.parentID == category.id) { 191 | let member = message.guild.members.cache.get(message.channel.name) 192 | 193 | if (!member) return message.channel.send('Unable To Send Message') 194 | 195 | let lembed = new discord.MessageEmbed() 196 | .setColor("GREEN") 197 | .setAuthor(message.author.username, message.author.displayAvatarURL({ dynamic: true })) 198 | .setDescription(message.content) 199 | 200 | return member.send(lembed) 201 | } 202 | 203 | 204 | } 205 | 206 | if (!message.guild) { 207 | const guild = await client.guilds.cache.get(ServerID) || await client.guilds.fetch(ServerID).catch(m => { }) 208 | if (!guild) return; 209 | const category = guild.channels.cache.find((x) => x.name == "MODMAIL") 210 | if (!category) return; 211 | const main = guild.channels.cache.find((x) => x.name == message.author.id) 212 | 213 | 214 | if (!main) { 215 | let mx = await guild.channels.create(message.author.id, { 216 | type: "text", 217 | parent: category.id, 218 | topic: "This mail is created for helping **" + message.author.tag + " **" 219 | }) 220 | 221 | let sembed = new discord.MessageEmbed() 222 | .setAuthor("MAIL OPENED") 223 | .setColor("GREEN") 224 | .setThumbnail(client.user.displayAvatarURL()) 225 | .setDescription("Conversation is now started, you will be contacted by staff soon") 226 | 227 | message.author.send(sembed) 228 | 229 | 230 | let eembed = new discord.MessageEmbed() 231 | .setAuthor("DETAILS", message.author.displayAvatarURL({ dynamic: true })) 232 | .setColor("BLUE") 233 | .setThumbnail(message.author.displayAvatarURL({ dynamic: true })) 234 | .setDescription(message.content) 235 | .addField("Name", message.author.username) 236 | .addField("Account Creation Date", message.author.createdAt) 237 | .addField("Direct Contact", "No(it means this mail is opened by person not a staff)") 238 | 239 | 240 | return mx.send(eembed) 241 | } 242 | 243 | let xembed = new discord.MessageEmbed() 244 | .setColor("RED") 245 | .setAuthor(message.author.tag, message.author.displayAvatarURL({ dynamic: true })) 246 | .setDescription(message.content) 247 | 248 | 249 | main.send(xembed) 250 | 251 | } 252 | 253 | 254 | 255 | 256 | }) 257 | 258 | 259 | client.login(process.env.TOKEN) --------------------------------------------------------------------------------