-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
311 lines (228 loc) · 11.1 KB
/
index.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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
const { EmbedBuilder, ActionRowBuilder, ButtonBuilder, PermissionsBitField } = require('discord.js');
const { Client, IntentsBitField } = require('discord.js');
const prefix = '>';
require('dotenv').config();
const client = new Client({
intents: [
IntentsBitField.Flags.Guilds,
IntentsBitField.Flags.GuildMessages,
IntentsBitField.Flags.MessageContent,
IntentsBitField.Flags.GuildMembers,
]
});
client.on("ready", (c) => {
console.log(`✅ ${c.user.tag} is online.`);
client.user.setActivity('Activity');
});
client.on('interactionCreate', (interaction) => {
if (interaction.isChatInputCommand()) return;
})
client.on("messageCreate", (message) => {
if (!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).split(/ +/);
const command = args.shift().toLowerCase();
//message Array
const messageArray = message.content.split(" ");
const argument = messageArray.slice(1);
const cmd = messageArray[0];
//MODERATION COMMANDS
if (command === 'test'){
if (!message.member.permissions.has(PermissionsBitField.Flags.Administrator)) return message.channel.send("You don't have permission to use this command!");
message.channel.send("Bot is working!");
}
// BAN COMMAND
if (command === 'ban') {
const member = message.mentions.members.first() || message.guild.members.cache.get(argument[0]) || message.guild.members.cache.find(x => x.user.username.toLowerCase() === argument.slice(0).join(" " || x.user.username === argument[0]));
if (!message.member.permissions.has(PermissionsBitField.Flags.BanMembers)) {
const embed = new EmbedBuilder()
.setColor('Red')
.setTitle('No Permission')
.setDescription('You do not have permission to run this command.')
message.channel.send({ embeds: [embed] });
return;
}
if (!member) return message.channel.send("You must specify someone in this command!");
if (message.member === member) return message.channel.send("You cannot ban yourself");
if (!member.kickable) return message.channel.send("You cannot ban this person!");
let reason = argument.slice(1).join(" ") || "No reason given."
const embed = new EmbedBuilder()
.setColor("Blue")
.setDescription(`:white_check_mark: ${member.user} has been **banned** | ${reason}`)
const dmEmbed = new EmbedBuilder()
.setColor("Blue")
.setDescription(`:white_check_mark: You were **banned** from ${message.guild.name} | ${reason}`)
member.send({ embeds: [dmEmbed]}).catch(err => {
console.log(`${member.user} has their DMs off and cannot receive the ban message.`);
})
member.ban().catch(err => {
message.channel.send("There was an error banning this member");
})
message.channel.send({ embeds: [embed] });
}
//TIMEOUT COMMAND
if(command === 'timeout'){
const timeUser = message.mentions.members.first() || message.guild.members.cache.get(argument[0]) || message.guild.members.cache.find(x => x.user.username.toLowerCase() === argument.slice(0).join(" " || x.user.username === argument[0]));
const duration = argument[1];
if (!message.member.permissions.has(PermissionsBitField.Flags.ModerateMembers)) {
const embed = new EmbedBuilder()
.setColor('Red')
.setTitle('No Permission')
.setDescription('You do not have permission to run this command.')
message.channel.send({ embeds: [embed] });
return;
}
if (!timeUser) return message.channel.send("Please specify a member to timeout.");
if (message.member === timeUser) return message.channel.send("You cannot time yourself out!");
if (!duration) return message.channel.send("Please specify a duration in which you want the member to be timed out for.");
if (duration > 604800) return message.channel.send("Please specify a duration between 1 & 604800 (one week) seconds.");
if (isNaN(duration)) {
return message.channel.send("Please specify a valid number in the duration section.");
}
let reason = argument.slice(2).join(" ") || 'No reason given.';
const embed = new EmbedBuilder()
.setColor("Blue")
.setDescription(`:white_check_mark: ${timeUser.user} has been **timed out** for ${duration} seconds | ${reason}`)
const dmEmbed = new EmbedBuilder()
.setColor("Blue")
.setDescription(`:white_check_mark: You have been **timed out** in ${message.guild.name} for ${duration} seconds | ${reason}`)
timeUser.timeout(duration * 1000, reason);
message.channel.send({ embeds: [embed] });
timeUser.send({ embeds: [dmEmbed] }).catch(err => {
return;
});
}
//untimeout command
if (command === 'untimeout') {
const timeUser = message.mentions.members.first() || message.guild.members.cache.get(argument[0]) || message.guild.members.find(x => x.user.username.toLowerCase() === argument.slice(0).join(" " || x.user.username === argument[0]));
if (!message.member.permissions.has(PermissionsBitField.Flags.ModerateMembers)) {
const embed = new EmbedBuilder()
.setColor('Red')
.setTitle('No Permission')
.setDescription('You do not have permission to run this command.')
message.channel.send({ embeds: [embed] });
return;
}
if (!timeUser) return message.channel.send("Please specify a member to untimeout");
if (message.member === timeUser) return message.channel.send("You cannot untime yourself out.");
if (!timeUser.kickable) return message.channel.send("You cannot time this person out.");
let reason = argument.slice(1).join(" ") || 'No reason given.';
const embed = new EmbedBuilder()
.setColor("Blue")
.setDescription(`:white_check_mark: ${timeUser.user} has been **untimed out** | ${reason}`)
const dmEmbed = new EmbedBuilder()
.setColor("Blue")
.setDescription(`:white_check_mark: You have been **untimed out** in ${message.guild.name} | ${reason}`)
timeUser.timeout(null, reason);
message.channel.send({ embeds: [embed] });
timeUser.send({ embeds: [dmEmbed] }).catch(err => {
return;
});
}
if (command === 'unban') {
if (!message.member.permissions.has(PermissionsBitField.Flags.ModerateMembers)) {
const embed = new EmbedBuilder()
.setColor('Red')
.setTitle('No Permission')
.setDescription('You do not have permission to run this command.')
message.channel.send({ embeds: [embed] });
return;
}
const member = args[0];
let reason = argument.slice(1).join(" ") || 'No reason given.';
const embed = new EmbedBuilder()
.setColor("Blue")
.setDescription(`:white_check_mark: <@${member}> has been **unbanned** | ${reason}`)
message.guild.bans.fetch()
.then(async bans => {
if (bans.size == 0) return message.channel.send(`There is no one banned from this server.`);
let bannedID = bans.find(ban => ban.user.id == member);
if (!bannedID) return await message.channel.send(`The ID stated is not banned from this server.`);
await message.guild.bans.remove(member, reason).catch(err => {
return message.channel("There was an error unbanning this member");
})
await message.channel.send({ embeds: [embed] });
})
}
if (command === 'kick') {
const member = message.mentions.members.first() || message.guild.members.cache.get(argument[0]) || message.guild.members.cache.find(x => x.user.username.toLowerCase() === argument.slice(0).join(" ") || x.user.username === argument[0]);
if (!message.member.permissions.has(PermissionsBitField.Flags.KickMembers)) {
const embed = new EmbedBuilder()
.setColor('Red')
.setTitle('No Permission')
.setDescription('You do not have permission to run this command.')
message.channel.send({ embeds: [embed] });
return;
}
if (!member) return message.channel.send("You must specify someone in this command!");
if (message.member === member) return message.channel.send("You cannot kick yourself");
if (!member.kickable) return message.channel.send("You cannot kick this person!");
let reason = argument.slice(1).join(" ") || "No reason given.";
const embed = new EmbedBuilder()
.setColor("Orange")
.setDescription(`:boot: ${member.user} has been **kicked** | ${reason}`);
const dmEmbed = new EmbedBuilder()
.setColor("Orange")
.setDescription(`:boot: You were **kicked** from ${message.guild.name} | ${reason}`);
member.send({ embeds: [dmEmbed] }).catch(err => {
console.log(`${member.user.tag} has their DMs off and cannot receive the kick message.`);
});
member.kick(reason).catch(err => {
message.channel.send("There was an error kicking this member");
});
message.channel.send({ embeds: [embed] });
}
if (command === 'clear') {
const numToDelete = parseInt(argument[0]);
if (!message.member.permissions.has(PermissionsBitField.Flags.ManageMessages)) {
const embed = new EmbedBuilder()
.setColor('Red')
.setTitle('No Permission')
.setDescription('You do not have permission to run this command.')
message.channel.send({ embeds: [embed] });
return;
}
if (isNaN(numToDelete) || numToDelete <= 0) {
return message.channel.send("Please provide a valid number of messages to delete.");
}
message.channel.bulkDelete(numToDelete + 1)
.then(() => {
message.channel.send(`Cleared ${numToDelete} messages.`)
.then(msg => {
setTimeout(() => msg.delete(), 5000);
});
})
.catch(error => {
console.error('Error clearing messages:', error);
message.channel.send("An error occurred while clearing messages.");
});
}
//COMMANDS
if (command === 'ping') {
const executePing = async () => {
const startTime = Date.now();
const pingMessage = await message.channel.send("Pinging...");
const endTime = Date.now();
const ping = endTime - startTime;
const apiLatency = Math.round(message.client.ws.ping);
const embed = new EmbedBuilder()
.setColor("Green")
.setTitle(":signal_strength: **Bot Ping**")
.setDescription(`**API Latency:** ${apiLatency}ms | **Bot Latency:** ${ping}ms`);
await pingMessage.edit({ embeds: [embed] });
};
executePing();
}
if (command === 'quote') {
const quotes = [
"Life is what happens while you are busy making other plans. - John Lennon.",
"Success is not final, failure is not fatal: it is the courage to continue that counts. - Winston Churchill.",
"The best way to predict the future is to create it. - Abraham Lincoln.",
"It is not the load that breaks you, it is the way you carry it. - Lou Holtz.",
"Happiness is not something already made. It comes from your actions. - Dalai Lama"
];
// Seleziona una citazione casuale dall'array
const randomQuote = quotes[Math.floor(Math.random() * quotes.length)];
// Invia la citazione al canale
message.channel.send(`"${randomQuote}"`);
}
})