Skip to content

Commit d07f3c9

Browse files
Merge pull request #16 from Mini51/7-should-update-to-v14-of-discordjs
added the warn system and forgot to add mute command before
2 parents fb2469c + 2eadc9e commit d07f3c9

File tree

2 files changed

+252
-0
lines changed

2 files changed

+252
-0
lines changed

src/commands/mute.js

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
const { SlashCommandBuilder } = require('@discordjs/builders');
2+
const { EmbedBuilder, PermissionsBitField } = require('discord.js');
3+
4+
5+
module.exports = {
6+
helpinfo : "This comand is used to mute/unmute a user",
7+
data: new SlashCommandBuilder()
8+
.setName('mute')
9+
.setDescription('mute/unmute a user')
10+
.addSubcommand(subcommand => subcommand
11+
.setName('mute')
12+
.setDescription('mute a user')
13+
.addUserOption(option =>
14+
option.setName('user')
15+
.setDescription('user to mute')
16+
.setRequired(true)
17+
)
18+
)
19+
.addSubcommand(subcommand => subcommand
20+
.setName('unmute')
21+
.setDescription('unmute a user')
22+
.addUserOption(option =>
23+
option.setName('user')
24+
.setDescription('user to unmute')
25+
.setRequired(true)
26+
)
27+
),
28+
async execute(interaction) {
29+
const subcommand = interaction.options.getSubcommand();
30+
const member = interaction.guild.members.cache.get(interaction.options.getUser('user').id);
31+
const moderator = interaction.guild.members.cache.get(interaction.user.id);
32+
33+
// Checks before mute or unmute
34+
if(!member) {
35+
return interaction.reply({ content: 'User is not in the guild', ephemeral: true });
36+
}
37+
38+
// makes sure the user has the kick permission
39+
if (!moderator.permissions.has(PermissionsBitField.Flags.MuteMembers)) {
40+
return interaction.reply({ content: 'You do not have permission to mute/unmute members!', ephemeral: true });
41+
}
42+
43+
// makes sure the user is not the bot
44+
if(member.bot) {
45+
return interaction.reply({ content: 'You cannot mute/unmute a bot!', ephemeral: true });
46+
}
47+
48+
// makes sure the user is not admin
49+
if(member === moderator) {
50+
return interaction.reply({ content: 'You cannot mute/unmute yourself!', ephemeral: true });
51+
}
52+
53+
if(!member.manageable) {
54+
return interaction.reply({ content: `I cannot mute/unmute this user`, ephemeral: true });
55+
}
56+
57+
//check if the server has a mute role
58+
const muteRole = interaction.guild.roles.cache.find(role => role.name === 'Muted');
59+
if(!muteRole) {
60+
interaction.reply({ content: `This server does not have a "Muted" role, plesae create one and rerun this command.`, ephemeral: true });
61+
}
62+
63+
console.log('passed all checks');
64+
65+
// mute/unmute the user
66+
if(subcommand === 'mute') {
67+
member.roles.add(muteRole);
68+
interaction.reply({ content: `${member} has been muted`, ephemeral: true });
69+
}
70+
else if(subcommand === 'unmute') {
71+
member.roles.remove(muteRole);
72+
interaction.reply({ content: `${member} has been unmuted`, ephemeral: true });
73+
}
74+
}
75+
}
76+

src/commands/warn.js

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
const { SlashCommandBuilder } = require("@discordjs/builders");
2+
const { EmbedBuilder, PermissionsBitField } = require("discord.js");
3+
4+
module.exports = {
5+
helpinfo:
6+
"This comand is used to warn people aswell as to see a list of warnings",
7+
data: new SlashCommandBuilder()
8+
.setName("warn")
9+
.setDescription("Warn a user or see a list of warnings")
10+
.addSubcommand((subcommand) =>
11+
subcommand
12+
.setName("warn")
13+
.setDescription("warn a user")
14+
.addUserOption((option) =>
15+
option
16+
.setName("user")
17+
.setDescription("user to mute")
18+
.setRequired(true)
19+
)
20+
.addStringOption((option) =>
21+
option
22+
.setName("reason")
23+
.setDescription("reason for warning")
24+
.setMaxLength(150)
25+
.setRequired(true)
26+
)
27+
)
28+
.addSubcommand((subcommand) =>
29+
subcommand
30+
.setName("list")
31+
.setDescription("see a list of warnings")
32+
.addUserOption((option) =>
33+
option
34+
.setName("user")
35+
.setDescription("user to see warnings for")
36+
.setRequired(true)
37+
)
38+
)
39+
.addSubcommand((subcommand) =>
40+
subcommand
41+
.setName("remove")
42+
.setDescription("remove a warning")
43+
.addUserOption((option) =>
44+
option
45+
.setName("user")
46+
.setDescription("user to remove warning from")
47+
.setRequired(true)
48+
)
49+
.addStringOption((option) =>
50+
option
51+
.setName("ID")
52+
.setDescription("ID of the warning to remove")
53+
.setRequired(true)
54+
)
55+
),
56+
57+
async execute(interaction) {
58+
const subcommand = interaction.options.getSubcommand();
59+
const member = interaction.guild.members.cache.get(
60+
interaction.options.getUser("user").id
61+
);
62+
const guild = interaction.guild;
63+
const moderator = interaction.guild.members.cache.get(interaction.user.id);
64+
65+
// Checks before mute or unmute
66+
if (!member) {
67+
return interaction.reply({
68+
content: "User is not in the guild",
69+
ephemeral: true,
70+
});
71+
}
72+
73+
// makes sure the user has the kick permission
74+
if (!moderator.permissions.has(PermissionsBitField.Flags.ModerateMembers)) {
75+
return interaction.reply({
76+
content: "You do not have permission to mute/unmute members!",
77+
ephemeral: true,
78+
});
79+
}
80+
81+
// makes sure the user is not the bot
82+
if (member.bot) {
83+
return interaction.reply({
84+
content: "You cannot warn a bot!",
85+
ephemeral: true,
86+
});
87+
}
88+
89+
// makes sure the user is not admin
90+
if (member === moderator) {
91+
return interaction.reply({
92+
content: "You cannot do this to yourself!",
93+
ephemeral: true,
94+
});
95+
}
96+
97+
// IMPORTANT THIS IS WHERE THE WARN COMMAND IS HANDLED
98+
99+
if (subcommand === "warn") {
100+
const reason = interaction.options.getString("reason");
101+
102+
/*
103+
This is where you need to write the code to interact with the database for when a user is warned
104+
105+
you can get the targeted user from the `member` variable
106+
you can get the moderator from the `moderator` variable
107+
you cant get the reason from the `reason` variable
108+
you can get the guild from the `guild` variable
109+
*/
110+
111+
//reply to the slash command with a succesfful message
112+
interaction.reply({
113+
content: `${moderator} has warned ${member.user.tag} for ${reason}`,
114+
});
115+
} else if (subcommand === "list") {
116+
/*
117+
This is where you need to write the code to interact with the database for when a admin is requesting a list of warnings for a user
118+
119+
you can get the targeted user from the `member` variable
120+
you can get the moderator from the `moderator` variable
121+
you cant get the reason from the `reason` variable
122+
you can get the guild from the `guild` variable
123+
*/
124+
125+
const mockWarnings = [
126+
{
127+
id: "some random id dosnt matter how it is generated",
128+
moderator: "Moderator#1234",
129+
reason: "This is a mock warning",
130+
date: "2020-01-01",
131+
},
132+
{
133+
id: "some random id dosnt matter how it is generated",
134+
moderator: "Moderator#1234",
135+
reason: "This is a mock warning",
136+
date: "2020-01-02",
137+
},
138+
];
139+
140+
// use this embed to display the list of warnings
141+
const ResponseEmbed = new EmbedBuilder()
142+
.setTitle("Warnings for " + member.user.tag)
143+
.addFields(
144+
mockWarnings.map((warning) => {
145+
return {
146+
name: `${warning.moderator} - ${warning.id}`,
147+
value: `${warning.reason}`,
148+
};
149+
})
150+
)
151+
.setColor("#ff0000")
152+
.setTimestamp();
153+
154+
//reply to the slash command with a succesfful message
155+
interaction.reply({
156+
embeds: [ResponseEmbed],
157+
});
158+
} else if (subcommand === "remove") {
159+
const ID = interaction.options.getString("ID");
160+
161+
/*
162+
This is where you need to write the code to interact with the database for when a admin is removing a warning from a user
163+
164+
you can get the id of the warning from the `ID` variable
165+
you can get the targeted user from the `member` variable
166+
you can get the moderator from the `moderator` variable
167+
you can get the guild from the `guild` variable
168+
169+
*/
170+
171+
interaction.reply({
172+
content: `${moderator} has removed a warning from ${member.user.tag}`,
173+
});
174+
}
175+
},
176+
};

0 commit comments

Comments
 (0)