-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
120 lines (120 loc) · 4.91 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
const fs = require('node:fs');
const path = require('node:path');
const { ActivityType, Client, Collection, EmbedBuilder, Events, GatewayIntentBits } = require('discord.js');
const { token, bannedUsers, bannedGuilds, discord, joinCh, leaveCh } = require('./config.json');
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMembers, GatewayIntentBits.GuildVoiceStates, GatewayIntentBits.DirectMessages], presence: {status: 'ONLINE', activities: [{type: ActivityType.Playing, name: '/info'}]} });
//
client.cooldowns = new Collection();
client.commands = new Collection();
const foldersPath = path.join(__dirname, 'src');
const commandFolders = fs.readdirSync(foldersPath);
//
for (const folder of commandFolders) {
const commandsPath = path.join(foldersPath, folder);
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath);
if ('data' in command && 'execute' in command) {
client.commands.set(command.data.name, command);
}
}
}
//
client.once(Events.ClientReady, () => {
console.log(`Ready! Logged in as ${client.user.tag}!`);
});
client.on(Events.InteractionCreate, async interaction => {
if (bannedUsers.includes(interaction.user.id)) {
const { userNotAllowed } = require('./src/embeds/embeds.js')
return interaction.reply({embeds: [userNotAllowed], ephemeral: true});
}
if (interaction.guild) {
if (bannedGuilds.includes(interaction.guild.id)) {
const { guildNotAllowed } = require('./src/embeds/embeds.js')
return interaction.reply({embeds: [guildNotAllowed], ephemeral: true});
}
}
//
if (!interaction.isChatInputCommand()) return;
const command = client.commands.get(interaction.commandName);
if (!command) return;
//
const { cooldowns } = client;
if (!cooldowns.has(command.name)) {
cooldowns.set(command.name, new Collection());
}
const now = Date.now();
const timestamps = cooldowns.get(command.name);
const defaultCooldownDuration = 3;
const cooldownAmount = (command.cooldown ?? defaultCooldownDuration) * 1000;
//
if (timestamps.has(interaction.user.id)) {
const expirationTime = timestamps.get(interaction.user.id) + cooldownAmount;
if (now<expirationTime) {
const expiredTimestamp = Math.round(expirationTime / 1000);
interaction.reply({ content: `Please wait <t:${expiredTimestamp}:R> more second(s) before reusing the \`${command.name}\` command.`, ephemeral: true });
return;
}
}
//
timestamps.set(interaction.user.id, now);
setTimeout(() => timestamps.delete(interaction.user.id), cooldownAmount);
try {
await command.execute(interaction);
} catch (error) {
console.error(error);
const { erbed } = require('./src/embeds/embeds.js')
erbed.setFooter(`${error}`)
if (interaction.replied) {
interaction.editReply({ embeds: [erbed], ephemeral: true })
} else {
interaction.reply({ embeds: [erbed], ephemeral: true })
}
}
});
client.on(Events.GuildCreate, guild => {
const joinch = client.channels.cache.get(joinCh)
const joinembed = new EmbedBuilder()
.setColor(0x00ff00)
.setTitle('Joined a new Guild')
.addFields(
{ name: 'Server name', value: `${guild.name}` },
{ name: '\u200B', value: '\u200B' },
{ name: 'Members', value: `${guild.memberCount}`, inline: true },
{ name: 'ID', value: `${guild.id}`, inline: true },
{ name: 'GuildsCount', value: `${client.guilds.cache.size}`, inline: true },
)
.setTimestamp();
if (guild.icon) {
joinembed.setThumbnail(`${guild.iconURL({ size: 2048 }) }`);
}
joinch.send({embeds:[joinembed]});
if (bannedGuilds.includes(guild.id)) {
guild.leave()
joinch.send('This Guild is blacklisted. The Bot left the guild.')
}
});
client.on(Events.GuildDelete, async guild => {
if (client.isReady()) {
const leavech = await client.channels.fetch(leaveCh);
const leaveEmbed = new EmbedBuilder()
.setColor(0xff0000)
.setTitle('Left a Guild')
.addFields(
{ name: 'Server Name', value: `${guild.name}`},
{ name: '\u200B', value: '\u200B' },
{ name: 'Members', value: `${guild.memberCount}`, inline: true },
{ name: 'ID', value: `${guild.id}`, inline: true },
{ name: 'GuildsCount', value: `${client.guilds.cache.size}`, inline: true },
)
.setTimestamp();
if (guild.icon) {
leaveEmbed.setThumbnail(`${guild.iconURL({ size: 2048 }) }`)
}
leavech.send({ embeds: [leaveEmbed] })
}
});
process.on('unhandledRejection', console.error)
process.on('uncaughtException', console.error)
client.login(token)