disamples-modmail
Version:
264 lines (157 loc) • 8.73 kB
JavaScript
const Discord = require('discord.js')
async function modmail(client, options = []) {
let { MessageButton, MessageActionRow } = require('discord.js')
let guild = client.guilds.cache.get(options.guildID);
if (!guild) throw new Error("No Guild!");
client.on("messageCreate", async(message) => {
if (message.author.bot) return;
if (message.channel.type === "DM") {
let mailName = `${message.author.id}`
let usersChannel = await guild.channels.cache.find(ch => ch.name === mailName.toLowerCase());
if (!usersChannel) {
const createdEmbed = new Discord.MessageEmbed()
.setAuthor(`${message.author.tag}`, message.author.displayAvatarURL({ dynamic: true }))
.setTitle("No Mail Opened")
.setDescription(message.content)
.setColor(options.embedColor)
let categ = guild.channels.cache.get(options.categoryID)
if (!categ) throw new Error("No Category!")
if (!options.staffRole) throw new Error("No Role!")
let permissions = {
id: options.staffRole,
allow: ['VIEW_CHANNEL', 'SEND_MESSAGES', 'READ_MESSAGE_HISTORY']
}
guild.channels.create(`${message.author.id}`, {
type: "text",
parent: categ,
permissionOverwrites: [
{
id: guild.roles.everyone,
deny: ['VIEW_CHANNEL', 'SEND_MESSAGES', 'READ_MESSAGE_HISTORY'] //Deny permissions
},
permissions
],
}).then(async (ch) => {
let role = ch.guild.roles.cache.find((r) => r.id == options.staffRole)
if (!role) throw new Error("No role!")
let delButton2 = new MessageButton()
.setStyle("DANGER")
.setLabel('Cancel')
.setCustomId('close_mail')
.setEmoji(`${options.wrongEmoji}` || '❌')
const openedUserEmbed = new Discord.MessageEmbed()
.setColor('#054df3')
.setTitle("This is the modmail system for Disample's World to get you the support you need faster than ever. To help us out respond with one of the options below.\nEx: `report user`")
.addField('**Post Art**', 'This is for sending your art to the art or photography channel. Your art will then be reviewed by our art posters and staff.\n**Warning**: If we detect the art is stolen you will be punished.')
.addField('**Report User**', 'This is for reporting users who have broken rules, it could be DM advertising or some NSFW images they sent to you.')
.addField('**Report Staff**', `This is for reporting staff who have done something wrong, it could be something very rude they said to you or maybe even something abusive you observed. This is not used for appealing punishments.`)
.addField('**Suggestion**', "This is for making suggestion about the server, it could be a rule you'd like changed or explained or a cool feature you'd like to see, just make sure it is something that is reasonable and serious.\n**(We don't have alot of time for jokes)**\n**This is NOT for YouTube or video suggestions.**")
.addField('**Request Role**', 'This is for requesting an obtainable role, please make sure you have checked the role information to see if you qualify or if the role is even obtainable.')
.addField('Appeal', 'This is for appealing any punishment you were given. You can appeal punishments if you did not really break the rule, feel it was unfair or bias.\n*You cannot appeal Automod punishments as they are always accurate.')
.addField('Other', 'This is for sending through any other request you may have such as questions or help needed.')
.addField(`<:info:934574706907041844> Info`, `Once you picked your option that fits your issue please wait untill a staff members responds back.`)
message.author.send({ embeds: [openedUserEmbed] })
let usersCreatedChannel = await guild.channels.cache.find(ch => ch.name === mailName.toLowerCase());
let delButton = new MessageButton()
.setStyle("DANGER")
.setLabel('Delete')
.setCustomId('close_mail')
.setEmoji(`${options.wrongEmoji}` || '❌')
let deleteRow = new MessageActionRow()
.addComponents([delButton])
const openedStaffEmbed = new Discord.MessageEmbed()
.setAuthor(`${message.author.tag}`, message.author.displayAvatarURL({ dynamic: true }))
.setTitle(`New Modmail Entry!`)
.setDescription(`**User: ${message.author.tag} (${message.author.id})**\n\n${message.author.tag} has created a new modmail entry.They are currently selecting a option that fits/supports their issue.`)
.addField(`Option Descriptions`, `**Post Art**: They want their own art posted in the (art channel).\n**Report User**: They want to report a user, they have to give an id username and proof/attachment.\n**Report Staff**: Same as report user but its a staff member not a regular member.\nSuggestion: they give an suggestion and you copy and paste that suggestion into the staff channel so everyone can review it.\n**Request Role**: They ask for a role that they are sure they have the requirements to get it.\n**Appeal**:Appeal for an punishment they must give when it happened and the punishment reason.\n**Other**: General Support.`)
.setTimestamp()
.setColor(options.embedColor)
usersCreatedChannel.send({ embeds: [openedStaffEmbed], components: [deleteRow] })
})
} else {
let usersHadChannel = await guild.channels.cache.find(ch => ch.name === mailName.toLowerCase());
const userHadEmbed = new Discord.MessageEmbed()
.setAuthor(`${message.author.tag}`, message.author.displayAvatarURL({ dynamic: true }))
.setTitle(`New Modmail Message`)
.setDescription(`${message.author.tag} has sent a new message regarding to this modmail entry.`)
.addField(`Message`,`${message.content || "*Image Only Message*"}`)
.setTimestamp()
.setColor(options.embedColor)
if (message.attachments.size>0){userHadEmbed.setImage(message.attachments.first().url)}
usersHadChannel.send({ embeds: [userHadEmbed] })
}
// Sent In DM's //
} else {
if (message.channel.type === "GUILD_TEXT") {
let categor = guild.channels.cache.get(options.categoryID)
if (message.channel.parentId !== categor.id) return;
const usertosend = message.guild.members.cache.find((user) => user.id == message.channel.name)
if (!usertosend) return;
if (options.anonymousReply === true) {
const staffSendEmbedA = new Discord.MessageEmbed()
.setAuthor(`Staff Team`)
.setTitle(`${message.content}`)
.setTimestamp()
.setColor(options.embedColor)
usertosend.send({ embeds: [staffSendEmbedA] })
} else {
const staffSendEmbed = new Discord.MessageEmbed()
.setAuthor(`${message.author.tag}`, message.author.displayAvatarURL())
.setTitle(`Modmail Reply`)
.setDescription(`You've received a reply for your modmail request.`)
.addField(`Reply`, `${message.content || "*Image Only Message*"}`)
.setColor(options.embedColor)
if (message.attachments.size>0){staffSendEmbed.setImage(message.attachments.first().url)}
usertosend.send({ embeds: [staffSendEmbed] })
}
}
}
})
// Channel Deleted //
client.on("channelDelete", (channel) => {
let category = guild.channels.cache.get(options.categoryID)
if (channel.parentId !== category.id) return;
const user = channel.guild.members.cache.find((user) => user.id == channel.name)
if (!user) return;
const deletedEmbed = new Discord.MessageEmbed()
.setTitle(`Modmail Entry Closed`)
.setDescription(`Your modmail entry was closed by a staff member remember if you require/need further assistance, don't hesitate in messaging again!`)
.setColor(options.embedColor)
user.send({ embeds: [deletedEmbed] })
});
// Delete Buttons //
let confirmButton = new MessageButton()
.setStyle("SUCCESS")
.setLabel('Confirm')
.setCustomId('confirm_mail')
.setEmoji(`${options.rightEmoji}` || '✔️')
let cancleButton = new MessageButton()
.setStyle("SECONDARY")
.setLabel('Cancle')
.setCustomId('cancle_mail')
.setEmoji(`${options.wrongEmoji}` || '❌')
let optionsRow = new MessageActionRow()
.addComponents([confirmButton])
.addComponents([cancleButton])
client.on('interactionCreate', interaction => {
if (interaction.customId === "close_mail") {
interaction.update({ components: [optionsRow]})
} else {
if (interaction.customId === "cancle_mail") {
let delButton2 = new MessageButton()
.setStyle("DANGER")
.setLabel('Delete')
.setCustomId('close_mail')
.setEmoji('❌')
let deleteRow2 = new MessageActionRow()
.addComponents([delButton2])
interaction.update({ components: [deleteRow2]})
} else {
if (interaction.customId === "confirm_mail") {
interaction.message.channel.delete();
}
}
}
});
}
module.exports = modmail;