-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstaff.js
201 lines (174 loc) · 6.63 KB
/
staff.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
const { EmbedBuilder } = require('discord.js');
// Function to get a user by ID, mention, or username
async function getUser(message, identifier) {
// Check for a mention
const userMention = message.mentions.users.first();
if (userMention) return userMention;
// Check if it's a user ID
if (!isNaN(identifier)) {
try {
return await message.guild.members.fetch(identifier);
} catch {
// Not found; continue to check username
}
}
// Lastly, check by username
const members = await message.guild.members.fetch();
const member = members.find(member => member.user.username.toLowerCase() === identifier.toLowerCase());
return member || null; // Return the member found or null if not found
}
module.exports = {
ban: async (message, args) => {
const userIdentifier = args[0];
if (!userIdentifier) {
const embed = new EmbedBuilder()
.setColor('#ff0000')
.setDescription('Please provide the ID, mention, or username of the user to ban.');
return message.reply({ embeds: [embed] });
}
const reason = args.slice(1).join(' ') || 'No reason provided';
const user = await getUser(message, userIdentifier);
if (!user) {
const embed = new EmbedBuilder()
.setColor('#ff0000')
.setDescription('User not found. Please provide a valid user ID, mention, or username.');
return message.reply({ embeds: [embed] });
}
if (!user.bannable) {
const embed = new EmbedBuilder()
.setColor('#ff0000')
.setDescription('I cannot ban this user.');
return message.reply({ embeds: [embed] });
}
await user.ban({ reason });
const embed = new EmbedBuilder()
.setColor('#00ff00')
.setDescription(`${user.user.tag} has been banned for: ${reason}`);
message.reply({ embeds: [embed] });
},
kick: async (message, args) => {
const userIdentifier = args[0];
if (!userIdentifier) {
const embed = new EmbedBuilder()
.setColor('#ff0000')
.setDescription('Please provide the ID, mention, or username of the user to kick.');
return message.reply({ embeds: [embed] });
}
const reason = args.slice(1).join(' ') || 'No reason provided';
const user = await getUser(message, userIdentifier);
if (!user) {
const embed = new EmbedBuilder()
.setColor('#ff0000')
.setDescription('User not found. Please provide a valid user ID, mention, or username.');
return message.reply({ embeds: [embed] });
}
if (!user.kickable) {
const embed = new EmbedBuilder()
.setColor('#ff0000')
.setDescription('I cannot kick this user.');
return message.reply({ embeds: [embed] });
}
await user.kick(reason);
const embed = new EmbedBuilder()
.setColor('#00ff00')
.setDescription(`${user.user.tag} has been kicked for: ${reason}`);
message.reply({ embeds: [embed] });
},
mute: async (message, args) => {
const userIdentifier = args[0];
if (!userIdentifier) {
const embed = new EmbedBuilder()
.setColor('#ff0000')
.setDescription('Please provide the ID, mention, or username of the user to mute.');
return message.reply({ embeds: [embed] });
}
let muteRole = message.guild.roles.cache.find(role => role.name.toLowerCase() === 'muted');
if (!muteRole) {
try {
muteRole = await message.guild.roles.create({
name: 'Muted',
color: '#514f48',
permissions: []
});
message.guild.channels.cache.forEach(async (channel) => {
await channel.permissionOverwrites.edit(muteRole, {
SendMessages: false,
AddReactions: false,
Speak: false
});
});
const embed = new EmbedBuilder()
.setColor('#00ff00')
.setDescription('Mute role was not found, so I created one.');
message.channel.send({ embeds: [embed] });
} catch (error) {
const embed = new EmbedBuilder()
.setColor('#ff0000')
.setDescription('I do not have sufficient permissions to create the "Muted" role.');
return message.reply({ embeds: [embed] });
}
}
const member = await getUser(message, userIdentifier);
if (!member) {
const embed = new EmbedBuilder()
.setColor('#ff0000')
.setDescription('User not found. Please provide a valid user ID, mention, or username.');
return message.reply({ embeds: [embed] });
}
await member.roles.add(muteRole);
const embed = new EmbedBuilder()
.setColor('#00ff00')
.setDescription(`${member.user.tag} has been muted.`);
message.reply({ embeds: [embed] });
},
unmute: async (message, args) => {
const userIdentifier = args[0];
if (!userIdentifier) {
const embed = new EmbedBuilder()
.setColor('#ff0000')
.setDescription('Please provide the ID, mention, or username of the user to unmute.');
return message.reply({ embeds: [embed] });
}
const muteRole = message.guild.roles.cache.find(role => role.name.toLowerCase() === 'muted');
if (!muteRole) {
const embed = new EmbedBuilder()
.setColor('#ff0000')
.setDescription('Mute role does not exist.');
return message.reply({ embeds: [embed] });
}
const member = await getUser(message, userIdentifier);
if (!member) {
const embed = new EmbedBuilder()
.setColor('#ff0000')
.setDescription('User not found. Please provide a valid user ID, mention, or username.');
return message.reply({ embeds: [embed] });
}
await member.roles.remove(muteRole);
const embed = new EmbedBuilder()
.setColor('#00ff00')
.setDescription(`${member.user.tag} has been unmuted.`);
message.reply({ embeds: [embed] });
},
unban: async (message, args) => {
const userIdentifier = args[0];
if (!userIdentifier) {
const embed = new EmbedBuilder()
.setColor('#ff0000')
.setDescription('Please provide the ID, mention, or username of the user to unban.');
return message.reply({ embeds: [embed] });
}
const userID = userIdentifier.replace(/\D/g, ''); // Get just the digits
try {
await message.guild.bans.remove(userID);
const embed = new EmbedBuilder()
.setColor('#00ff00')
.setDescription(`User with ID ${userID} has been unbanned.`);
message.reply({ embeds: [embed] });
} catch (error) {
const embed = new EmbedBuilder()
.setColor('#ff0000')
.setDescription(`Sorry, I couldn't unban the user. Make sure the ID is correct and I have sufficient permissions. Error: ${error}`);
message.reply({ embeds: [embed] });
}
}
};