-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.js
More file actions
141 lines (115 loc) · 4.75 KB
/
Main.js
File metadata and controls
141 lines (115 loc) · 4.75 KB
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
//#region Initialization
//File System
const fs = require('fs');
const path = require('path');
//Discord
const { Bot_Token } = require('./config.json');
const token = Bot_Token;
const { Client, ActivityType, Collection, GatewayIntentBits, ActionRowBuilder, ButtonBuilder, ButtonStyle, Events } = require('discord.js');
const { GuildStickerManager } = require('discord.js');
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMembers, GatewayIntentBits.GuildVoiceStates] });
//Music
const queue = new Map();
module.exports.queue = queue;
//#endregion
//#region Adding the commands folder
client.commands = new Collection();
const commandFolders = fs.readdirSync('./commands');
//command subfolders files
for (const folder of commandFolders) {
const folderPath = path.join('./commands', folder);
if (!fs.lstatSync(folderPath).isDirectory()) continue;
const commandFiles = fs.readdirSync(folderPath).filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require("./" + path.join(folderPath, file).replace(/\\/g, '/'));
//we use try catch here because register slash cant read command.data.name for some reason
try {
client.commands.set(command.data.name, command);
}
catch (error) {
console.log(error);
}
}
}
//main commands folder files
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require("./" + path.join('./commands', file).replace(/\\/g, '/'));
client.commands.set(command.data.name, command);
}
//#endregion
//#region Adding the buttons folder
client.buttons = new Collection();
const buttonFiles = fs.readdirSync('./buttons').filter(file => file.endsWith('.js'));
for (const file of buttonFiles) {
const button = require("./" + path.join('/buttons', file).replace(/\\/g, '/'));
client.buttons.set(button.data.data.custom_id, button);
}
//#endregion
//#region When the bot boots up
client.once('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
client.user.setActivity('Sniffing', { type: ActivityType.Competing });
});
//#endregion
//#region when the bot joins a new guild
client.on('guildCreate', async guild => {
var i = "0";
//#region Membercount for server
list.members.cache.each(member => {
if (!member.user.bot) { i++ };
}, (err) => {
if (err) throw err;
});
//#endregion
console.log(`joined server ${guild.name} (${guild.id}) with: ${i} members`);
});
//#endregion
//#region when there is an interaction event
client.on('interactionCreate', async(interaction) => {
if (!interaction.isCommand() && !interaction.isButton()) return;
//get the serverQueue from the queue map
const serverQueue = queue.get(interaction.guild.id);
//set interaction.guild.serverQueue to the serverQueue
interaction.guild.serverQueue = serverQueue;
//if out interaction was a button interaction
if (interaction.isButton()) {
//log the button press
console.log(`${getTime()} /g${interaction.guildId}/c${interaction.channelId}/u${interaction.user.id}/ used Button (${interaction.customId})`);
//get the button that was pressed
const button = client.buttons.get(interaction.customId);
if (!button) return;
//execute the apropriate button command
try {
await button.execute(interaction);
} catch (error) {
console.error(error);
await interaction.reply({ content: 'There was an error while clicking this button!', ephemeral: true });
}
} else {
//log the command
console.log(`${getTime()} /g${interaction.guildId}/c${interaction.channelId}/u${interaction.user.id}/ used Slash (${interaction.commandName})`);
//get the slash command that was used
const command = client.commands.get(interaction.commandName);
if (!command) return;
//execute the apropriate slash command command
try {
await command.execute(interaction);
} catch (error) {
console.error(error);
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
}
}
});
//#endregion
//function to get the time
function getTime() {
const now = new Date();
const day = String(now.getDate()).padStart(2, '0');
const month = String(now.getMonth() + 1).padStart(2, '0'); // Months are zero-based, so we add 1
const year = now.getFullYear();
const hours = String(now.getHours()).padStart(2, '0');
const minutes = String(now.getMinutes()).padStart(2, '0');
return `${day}.${month}.${year}-${hours}:${minutes}`;
}
client.login(token);