Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //AUDIT LOG
- const Audit_Log = require("./Schemas.js/auditlog");
- //Add ban
- client.on(Events.GuildBanAdd, async (ban) => {
- const guild = ban.guild;
- const target = ban.user;
- const reason = ban.reason || 'No reason given';
- const data = await Audit_Log.findOne({
- Guild: guild.id
- })
- let logID;
- if (data) {
- logID = data.Channel
- } else {
- return;
- }
- const auditEmbed = new EmbedBuilder().setColor("White").setTimestamp().setFooter({ text: "Nexus Audit Log System"})
- const auditChannel = client.channels.cache.get(logID);
- auditEmbed
- .setTitle('Ban added')
- .addFields(
- {name: "Banned Member:", value: `Name: ${target.tag}\nID: ${target.id}`, inline: false},
- {name: "Reason:", value: `${reason}`, inline: false},
- )
- await auditChannel.send({ embeds: [auditEmbed] }).catch((err) => {console.log(err)});
- });
- //Remove ban
- client.on('guildBanRemove', async (ban) => {
- const target = ban.user;
- const data = await Audit_Log.findOne({
- Guild: ban.guild.id
- })
- let logID;
- if (data) {
- logID = data.Channel
- } else {
- return;
- }
- const auditEmbed = new EmbedBuilder().setColor("White").setTimestamp().setFooter({ text: "Nexus Audit Log System"})
- const auditChannel = client.channels.cache.get(logID);
- auditEmbed
- .setTitle('Ban removed')
- .addFields(
- {name: "Banned Member:", value: `${target}\nID: ${target.id}`, inline: false},
- {name: "Ban Reason:", value: `${ban.reason || "No reason given!"}`, inline: false},
- )
- await auditChannel.send({ embeds: [auditEmbed] }).catch((err) => {return;});
- });
- //Channel Create
- client.on(Events.ChannelCreate, async (channel) => {
- const data = await Audit_Log.findOne({
- Guild: channel.guild.id
- })
- let logID;
- if (data) {
- logID = data.Channel
- } else {
- return;
- }
- const auditEmbed = new EmbedBuilder().setColor("White").setTimestamp().setFooter({ text: "Nexus Audit Log System"})
- const auditChannel = client.channels.cache.get(logID);
- auditEmbed.setTitle("Channel Created").addFields(
- {name: "Channel Name:", value: channel.name, inline: false},
- {name: "Channel ID:", value: channel.id, inline: false}
- )
- await auditChannel.send({ embeds: [auditEmbed]}).catch((err) => {return;});
- })
- //Channel Delete
- client.on(Events.ChannelDelete, async (channel) => {
- const auditEmbed = new EmbedBuilder().setColor("White").setTimestamp().setFooter({ text: "Nexus Audit Log System"})
- const data = await Audit_Log.findOne({
- Guild: channel.guild.id,
- })
- let logID;
- if (data) {
- logID = data.Channel
- } else {
- return;
- }
- const auditChannel = client.channels.cache.get(logID);
- auditEmbed.setTitle("Channel Deleted").addFields(
- {name: "Channel Name:", value: channel.name, inline: false},
- {name: "Channel ID:", value: channel.id, inline: false}
- )
- await auditChannel.send({ embeds: [auditEmbed]}).catch((err) => {return;});
- })
- //Channel Update
- client.on(Events.ChannelUpdate, async (oldChannel, newChannel) => {
- const auditEmbed = new EmbedBuilder().setColor("White").setTimestamp().setFooter({ text: "Nexus Audit Log System"})
- const data = await Audit_Log.findOne({
- Guild: oldChannel.guild.id,
- })
- let logID;
- if (data) {
- logID = data.Channel
- } else {
- return;
- }
- const auditChannel = client.channels.cache.get(logID);
- const changes = [];
- if (oldChannel.name !== newChannel.name) {
- changes.push(`Name: \`${oldChannel.name}\` → \`${newChannel.name}\``);
- }
- if (oldChannel.topic !== newChannel.topic) {
- changes.push(`Topic: \`${oldChannel.topic || 'None'}\` → \`${newChannel.topic || 'None'}\``);
- }
- if (changes.length === 0) return;
- const changesText = changes.join('\n');
- auditEmbed.setTitle("Channel Updated").addFields({ name: "Changes:", value: changesText})
- await auditChannel.send({ embeds: [auditEmbed]}).catch((err) => {return;});
- })
- //Role Create
- client.on(Events.GuildRoleCreate, async (role) => {
- const data = await Audit_Log.findOne({
- Guild: role.guild.id
- })
- let logID;
- if (data) {
- logID = data.Channel
- } else {
- return;
- }
- const auditEmbed = new EmbedBuilder().setColor("White").setTimestamp().setFooter({ text: "Nexus Audit Log System"})
- const auditChannel = client.channels.cache.get(logID);
- auditEmbed.setTitle("Role Created").addFields(
- {name: "Role Name:", value: role.name, inline: false},
- {name: "Role ID:", value: role.id, inline: false}
- )
- await auditChannel.send({ embeds: [auditEmbed]}).catch((err) => {return;});
- })
- //Role Delete
- client.on(Events.GuildRoleDelete, async (role) => {
- const auditEmbed = new EmbedBuilder().setColor("White").setTimestamp().setFooter({ text: "Nexus Audit Log System"})
- const data = await Audit_Log.findOne({
- Guild: role.guild.id,
- })
- let logID;
- if (data) {
- logID = data.Channel
- } else {
- return;
- }
- const auditChannel = client.channels.cache.get(logID);
- auditEmbed.setTitle("Role Removed").addFields(
- {name: "Role Name:", value: role.name, inline: false},
- {name: "Role ID:", value: role.id, inline: false}
- )
- await auditChannel.send({ embeds: [auditEmbed]}).catch((err) => {return;});
- })
- //Message Delete
- client.on(Events.MessageDelete, async (message) => {
- const data = await Audit_Log.findOne({
- Guild: message.guild.id,
- }).catch((err) => {return;});
- let logID;
- if (data) {
- logID = data.Channel
- } else {
- return;
- }
- try {
- const auditEmbed = new EmbedBuilder().setColor("White").setTimestamp().setFooter({ text: "Nexus Audit Log System"})
- const auditChannel = client.channels.cache.get(logID);
- auditEmbed.setTitle("Message Deleted").addFields(
- {name: "Author:", value: `<@${message.user.id}>`, inline: false},
- {name: "Message:", value: `${message.content}`, inline: false},
- {name: "Message ID:", value: `${message.id}`}
- )
- await auditChannel.send({ embeds: [auditEmbed]}).catch((err) => {return;});
- } catch (err) {
- return;
- }
- })
- //Thread create
- client.on(Events.ThreadCreate, async (thread) => {
- const data = await Audit_Log.findOne({
- Guild: thread.guild.id,
- })
- let logID;
- if (data) {
- logID = data.Channel
- } else {
- return;
- }
- const auditEmbed = new EmbedBuilder().setColor("White").setTimestamp().setFooter({ text: "Nexus Audit Log System"})
- const auditChannel = client.channels.cache.get(logID);
- auditEmbed.setTitle("Thread Created").addFields(
- {name: "Name:", value: thread.name, inline: false},
- {name: "Tag:", value: `<#${thread.id}>`, inline: false},
- {name: "ID:", value: thread.id, inline: false},
- )
- await auditChannel.send({ embeds: [auditEmbed]}).catch((err) => {return;});
- })
- //Thread Delete
- client.on(Events.ThreadDelete, async (thread) => {
- const data = await Audit_Log.findOne({
- Guild: thread.guild.id,
- })
- let logID;
- if (data) {
- logID = data.Channel
- } else {
- return;
- }
- const auditEmbed = new EmbedBuilder().setColor("White").setTimestamp().setFooter({ text: "Nexus Audit Log System"})
- const auditChannel = client.channels.cache.get(logID);
- auditEmbed.setTitle("Thread Deleted").addFields(
- {name: "Name:", value: thread.name, inline: false},
- {name: "Tag:", value: `<#${thread.id}>`, inline: false},
- {name: "ID:", value: thread.id, inline: false},
- )
- await auditChannel.send({ embeds: [auditEmbed]}).catch((err) => {return;});
- })
- //Invite Create
- client.on(Events.InviteCreate, async (invite) => {
- const data = await Audit_Log.findOne({
- Guild: invite.guild.id,
- })
- let logID;
- if (data) {
- logID = data.Channel
- } else {
- return;
- }
- const auditEmbed = new EmbedBuilder().setColor("White").setTimestamp().setFooter({ text: "Nexus Audit Log System"})
- const auditChannel = client.channels.cache.get(logID);
- auditEmbed.setTitle("Invite Created").addFields(
- {name: "User:", value: `<@${invite.inviterId}>`, inline: false},
- {name: "Invite Code:", value: `${invite.code}`, inline: false},
- {name: "Expires at:", value: `${invite.expiresAt}`, inline: false},
- {name: "Created at:", value: `${invite.createdAt}`, inline: false},
- {name: "Channel:", value: `<#${invite.channelId}>`, inline: false},
- {name: "Max Uses:", value: `${invite.maxUses}`, inline: false},
- {name: "URL", value: `${invite.url}`}
- )
- await auditChannel.send({ embeds: [auditEmbed]}).catch(err => {
- return;
- });
- })
- //Invite Delete
- client.on(Events.InviteDelete, async (invite) => {
- const data = await Audit_Log.findOne({
- Guild: invite.guild.id
- })
- let logID;
- if (data) {
- logID = data.Channel
- } else {
- return;
- }
- const auditEmbed = new EmbedBuilder().setColor("White").setTimestamp().setFooter({ text: "Nexus Audit Log System"})
- const auditChannel = client.channels.cache.get(logID);
- auditEmbed.setTitle("Invite Deleted").addFields(
- {name: "User:", value: `<@${invite.user.id}>`, inline: false},
- {name: "Invite Code:", value: `${invite.code}`, inline: false},
- {name: "Expires at:", value: `${invite.expiresAt}`, inline: false},
- {name: "Created at:", value: `${invite.createdAt}`, inline: false},
- {name: "Channel:", value: `<#${invite.channelId}>`, inline: false},
- {name: "Max Uses:", value: `${invite.maxUses}`, inline: false},
- {name: "URL", value: `${invite.url}`}
- )
- await auditChannel.send({ embeds: [auditEmbed]}).catch((err) => {return;});
- })
- //Bulk Delete
- client.on(Events.MessageBulkDelete, async (messages) => {
- const firstMessage = messages.first();
- const channel = firstMessage.channel;
- const guildId = channel.guild.id;
- const data = await Audit_Log.findOne({
- Guild: guildId
- })
- let logID;
- if (data) {
- logID = data.Channel
- } else {
- return;
- }
- const auditEmbed = new EmbedBuilder().setColor("White").setTimestamp().setFooter({ text: "Nexus Audit Log System"})
- const auditChannel = client.channels.cache.get(logID);
- const htmlContent = generateHtmlTranscript(messages, channel, guildId);
- const transcriptFilePath = path.join(__dirname, 'transcripts', `transcript_${Date.now()}.html`);
- fs.writeFileSync(transcriptFilePath, htmlContent);
- function generateHtmlTranscript(messages, channel, guildId) {
- let html = `
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8">
- <title>Bulk Delete</title>
- </head>
- <body>
- <h1>Transscript - Deleted Messages</h1>
- <p>Channel: ${channel.name} (ID: ${channel.id})</p>
- <p>Server ID: ${guildId}</p>
- <p>Amount of deleted messages: ${messages.size}</p>
- <ul>
- `;
- messages.forEach(message => {
- const content = message.content || '[Picture/File]';
- html += `<li><strong>${message.author.tag}</strong>: ${content}</li>`;
- });
- html += `
- </ul>
- </body>
- </html>
- `;
- return html;
- }
- auditEmbed.setTitle("Message Bulk Delete").addFields(
- {name: "Messages Deleted:", value: `${messages.size}`, inline: false},
- {name: "Channel:", value: `${messages.channel}`, inline: false},
- )
- await auditChannel.send({
- embeds: [auditEmbed],
- files: [transcriptFilePath],}).catch((err) => {return;});
- })
- /*const { id, channel_id, guild_id, author, timestamp, type } = data;*/
- client.on(Events.MessageUpdate, async (oldMessage, newMessage) => {
- if (oldMessage.content === newMessage.content) return;
- const data = await Audit_Log.findOne({
- Guild: oldMessage.guild.id
- })
- let logID;
- if (data) {
- logID = data.Channel
- } else {
- return;
- }
- const auditEmbed = new EmbedBuilder().setColor("White").setTimestamp().setFooter({ text: "Nexus Audit Log System"})
- const auditChannel = client.channels.cache.get(logID);
- const id = oldMessage.id;
- const guildID = oldMessage.guild.id;
- const channelID = oldMessage.channel.id;
- const buttons = new ButtonBuilder()
- .setLabel("Jump to")
- .setStyle(ButtonStyle.Link)
- .setURL(`https://canary.discord.com/channels/${guildID}/${channelID}/${id}`);
- const row = new ActionRowBuilder().addComponents(buttons);
- const newText = newMessage.content;
- const oldText = oldMessage.content;
- const length1 = newMessage.length;
- const length2 = oldMessage.length;
- if (length1 >= 1024 && length2 >= 1024) {
- const LongAuditEmbed = new EmbedBuilder()
- .setTitle("Message Edited")
- .addFields({ name: 'Author:', value: `${newMessage.author.tag}`, inline: false})
- .addFields({ name: 'Channel:', value: `${newMessage.channel}`, inline: false})
- .setColor("White")
- .setTimestamp()
- .setFooter({ text: "Nexus Audit Log System"})
- const embedOld = new EmbedBuilder()
- .setTitle("Old Message")
- .setDescription(`${oldText}`)
- .setColor("White")
- .setTimestamp()
- .setFooter({ text: "Nexus Audit Log System"})
- const embedNew = new EmbedBuilder()
- .setTitle("New Message")
- .setDescription(`${newText}`)
- .setColor("White")
- .setTimestamp()
- .setFooter({ text: "Nexus Audit Log System"})
- await auditChannel.send({ embeds: [LongAuditEmbed, embedOld, embedNew], components: [row]});
- }
- auditEmbed.setTitle("Message Edited")
- .addFields({ name: 'Author:', value: `${newMessage.author.tag}`, inline: false})
- .addFields({ name: 'Channel:', value: `${newMessage.channel}`, inline: false})
- .addFields({ name: 'Old Message:', value: `${oldMessage.content}`, inline: false})
- .addFields({ name: 'New Message:', value: `${newMessage.content}`, inline: false})
- await auditChannel.send({ embeds: [auditEmbed], components: [row]}).catch((err) => {return;});
- })
- //Guild Update
- client.on(Events.GuildUpdate, async (oldGuild, newGuild) => {
- //Old Stuff
- const oldName = oldGuild.name;
- const oldDesc = oldGuild.description;
- const oldBanner = oldGuild.bannerURL();
- const oldIcon = oldGuild.iconURL();
- //New Stuff
- const newName = newGuild.name;
- const newDesc = newGuild.description;
- const newBanner = newGuild.bannerURL();
- const newIcon = newGuild.iconURL();
- const data = await Audit_Log.findOne({
- Guild: newGuild.id
- })
- let logID;
- if (data) {
- logID = data.Channel
- } else {
- return;
- }
- var icon;
- var name;
- var banner;
- var desc;
- if (oldIcon !== newIcon) {
- icon = {
- name: "Icon:",
- value: `Old Icon: ${oldIcon} \nNew Icon: ${newIcon}`,
- inline: false,
- }
- } else {
- icon = {
- name: "Icon:",
- value: "No icon changes have been made"
- }
- }
- if (oldName !== newName) {
- name = {
- name: "Name:",
- value: `Old name: ${oldName}\nNew Name: ${newName}`,
- inline: false
- }
- } else {
- name = {
- name: "Name:",
- value:"No name changes have been made"
- }
- }
- const auditEmbed = new EmbedBuilder().setColor("White").setTimestamp().setFooter({ text: "Nexus Audit Log System"})
- const auditChannel = client.channels.cache.get(logID);
- if (newBanner !== oldBanner) {
- auditEmbed.setImage(newBanner)
- banner = {
- name: "Banner:",
- value: `[Old Banner}(${oldBanner}) \n[New Banner](${newBanner})`,
- inline: false
- }
- } else {
- banner = {
- name: "Banner:",
- value: `No banner changes have been made`,
- inline: false
- }
- }
- if (oldDesc !== newDesc) {
- desc = {
- name: "Description:",
- value: `Old: ${oldDesc} \nNew: ${newDesc}`,
- inline: false
- }
- } else {
- desc = {
- name: "Description:",
- value: `No description changes have been made`,
- inline: false
- }
- }
- auditEmbed.addFields(
- icon,
- name,
- banner,
- desc
- )
- await auditChannel.send({
- embeds: [auditEmbed]
- })
- })
- //Remove all reactions from a message
- client.on(Events.MessageReactionRemoveEmoji, async (reaction) => {
- const {message} = reaction;
- const {author, id, guild, channel } = message
- const data = await Audit_Log.findOne({
- Guild: guild.id
- })
- let logID;
- if (data) {
- logID = data.Channel
- } else {
- return;
- }
- const discords = [
- "discord.com",
- "ptb.discord.com",
- "canary.discord.com"
- ];
- const num = Math.floor(Math.random(discords.length))
- const output = `https://${discords[num]}/channels/${guild.id}/${channel.id}/${id}`
- const button = new ButtonBuilder()
- .setLabel("Jump to")
- .setDisabled(false)
- .setStyle(ButtonStyle.Link)
- .setURL(output)
- const row = new ActionRowBuilder()
- .addComponents(button)
- const auditEmbed = new EmbedBuilder().setColor("White").setTimestamp().setFooter({ text: "Nexus Audit Log System"})
- const auditChannel = client.channels.cache.get(logID);
- auditEmbed.addFields(
- {name: "Author:", value: `${author}`, inline: false},
- {name: "Message ID:", value: `${id}`, inline: false},
- {name: "Channel:", value: `${channel}`, inline: false},
- {name: "Channel ID:", value: `${channel.id}`, inline: false},
- {name: "Channel Name:", value: `${channel.name}`, inline: false},
- {name: "Link:", value: output, inline: false}
- ).setTitle("Message Reaction Remove Emoji")
- await auditChannel.send({
- embeds: [auditEmbed],
- components: [row]
- })
- })
Advertisement
Add Comment
Please, Sign In to add comment