index.js (view raw)
1const fs = require('node:fs');
2const path = require('node:path');
3const { Client, Collection, GatewayIntentBits, ActivityType, PresenceUpdateStatus, Presence } = require('discord.js');
4const { token } = require(path.join(process.cwd(), 'config.json'));
5
6const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildVoiceStates] });
7
8client.commands = new Collection();
9const commandsPath = path.join(__dirname, 'commands');
10const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
11
12for (const file of commandFiles) {
13 const filePath = path.join(commandsPath, file);
14 const command = require(filePath);
15 client.commands.set(command.data.name, command);
16}
17
18const activities = [
19 { activity: ActivityType.Watching, subject: 'i cantieri'}, // sta guardando i cantieri
20 { activity: ActivityType.Playing, subject: 'briscola'}, // sta giocando a briscola
21 { activity: ActivityType.Competing, subject: 'prato fiorito'}, // in competizione su prato fiorito
22
23 { activity: ActivityType.Watching, subject: 'i bambini'},
24 { activity: ActivityType.Playing, subject: 'quel gioco là non mi viene il titolo'},
25 { activity: ActivityType.Competing, subject: 'cacata ranked al cesso pubblico'},
26]
27
28client.once('ready', () => {
29 const random = Math.floor(Math.random() * (activities.length));
30 const choice = activities[random]
31
32 client.user.setActivity(choice.subject, { type: choice.activity })
33 console.log('Bot online!');
34});
35
36client.on('interactionCreate', async interaction => {
37 if (!interaction.isChatInputCommand()) return;
38
39 const command = client.commands.get(interaction.commandName);
40
41 if (!command) return;
42
43 try {
44 await command.execute(interaction);
45 }
46 catch (error) {
47 console.error(error);
48 await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
49 }
50});
51
52client.login(token);