-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
65 lines (55 loc) · 2.32 KB
/
index.js
File metadata and controls
65 lines (55 loc) · 2.32 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
const { Client, Collection, Intents } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
const fs = require('fs');
client.commands = new Collection();
client.buttons = new Collection();
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
const buttonFiles = fs.readdirSync('./buttons').filter(file => file.endsWith('.js'));
const dataFiles = fs.readdirSync('./.data').filter(file => file.endsWith('.json'));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
client.commands.set(command.data.name, command);
}
for (const file of buttonFiles) {
const button = require(`./buttons/${file}`);
client.buttons.set(button.name, button);
}
/*
Discord bot made for Civilous' SCPF Engineering & Technical Services Department by mesemi#0758 (with help from Neostant#9194)
*/
client.once('ready', () => {
console.log(`[E&T Bot] Logged in! ✔️`);
console.log(`[E&T Bot] Currently registered data files: ` + dataFiles)
});
client.on('interactionCreate', async interaction => {
if (interaction.isCommand()) {
const command = client.commands.get(interaction.commandName);
if (!command) return;
try {
await command.execute(client, interaction);
} catch (error) {
console.log('[E&T Bot] There was an error while trying to execute: ' + command + ' ❌')
console.error(error);
return interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
}
} else if (interaction.isButton()) {
const button = client.buttons.get(interaction.customId)
if (!button) return;
try {
await button.execute(client, interaction);
} catch (error) {
console.log('[E&T Bot] There was an error while trying to respond to button: ' + button + ' ❌')
console.error(error);
return interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
}
} else {
return;
}
});
client.on('guildMemberRemove', async member => {
var data = require('/app/.data/data.json')
console.log("occured");
delete data.users[member.id]
fs.writeFile('/app/.data/data.json', JSON.stringify(data), function (err) { if (err) throw err;});
})
client.login(process.env.TOKEN);