Skip to content
This repository has been archived by the owner on Oct 29, 2022. It is now read-only.

Commit

Permalink
warning systems
Browse files Browse the repository at this point in the history
  • Loading branch information
GeantW0rld authored Oct 25, 2022
1 parent b306726 commit d894b38
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/commands/Moderation/removewarn.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const { SlashCommandBuilder, PermissionFlagsBits } = require('discord.js')
const warnModel = require("../../models/WarningDB")

module.exports = {
data: new SlashCommandBuilder()
.setName("remove-warn")
.setDescription("remove warn a member")
.addStringOption(options => options.setName("warnid").setDescription("warnid that you want to delete").setRequired(true))
.setDefaultMemberPermissions(PermissionFlagsBits.ModerateMembers),
async execute(interaction, client) {
const warnid = interaction.options.getString("warnid")

const data = await warnModel.findById(warnid)

if (!data) return interaction.reply({content: `${warnid} is not a valid id`, ephemeral: true})

data.delete()

const user = interaction.guild.members.cache.get(data.UserID)
return interaction.reply({content: `Removed 1 of ${user}'s warnings`, ephemeral: true})
},
};
26 changes: 26 additions & 0 deletions src/commands/Moderation/warn.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const { SlashCommandBuilder, PermissionFlagsBits } = require('discord.js')
const warnModel = require("../../models/WarningDB")

module.exports = {
data: new SlashCommandBuilder()
.setName("warn")
.setDescription("warn a member")
.addUserOption(options => options.setName("target").setDescription("the member to warn").setRequired(true))
.addStringOption(options => options.setName("reason").setDescription("the reason").setRequired(false))
.setDefaultMemberPermissions(PermissionFlagsBits.ModerateMembers),
async execute(interaction, client) {
const user = interaction.options.getUser("target")
const reason = interaction.options.getString("reason") ||"No Reason"

new warnModel({
UserID: user.id,
GuildID: interaction.guildId,
ModeratorID: interaction.user.id,
Reason: reason,
}).save()

user.send(`You have been warned in ${interaction.guild.name}`).catch(console.log)

interaction.reply({content: `${user} has been warned for ${reason}`, ephemeral: true})
},
};
38 changes: 38 additions & 0 deletions src/commands/Moderation/warnings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const { SlashCommandBuilder, PermissionFlagsBits, EmbedBuilder } = require('discord.js')
const warnModel = require("../../models/WarningDB")
const moment = require("moment")

module.exports = {
data: new SlashCommandBuilder()
.setName("warnings")
.setDescription("view all warns")
.addUserOption(options => options.setName("target").setDescription("the member to warn").setRequired(true))
.setDefaultMemberPermissions(PermissionFlagsBits.ModerateMembers),
async execute(interaction, client) {
const user = interaction.options.getUser("target")

const userWarnings = await warnModel.find({
UserID: user.id,
GuildID: interaction.guildId,
})

if (!userWarnings?.length) return interaction.reply({content: `${user} has no warnings in the server`, ephemeral: true})

const embedDescription = userWarnings.map((warn) => {
const mods = interaction.guild.members.cache.get(warn.ModeratorID)

return [
`WarnId: ${warn._id}`,
`Moderator: ${mods || "Has left"}`,
`Reason: ${warn.Reason}`
].join("\n")
}).join("\n\n")

const embed = new EmbedBuilder()
.setTitle(`${user.tag}'s warnings`)
.setDescription(embedDescription)
.setColor("Random")

interaction.reply({embeds: [embed]})
},
};

0 comments on commit d894b38

Please sign in to comment.