all repos — simple-discord-music-bot @ 61364f5fe32e6420a82abd998c4a0baa264184e0

A Discord bot making use of discord.js and play-yt.

index.js (view raw)

 1const fs = require('node:fs');
 2const path = require('node:path');
 3const { Client, Collection, GatewayIntentBits, ActivityType } = 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
12let player;
13
14for (const file of commandFiles) {
15	const filePath = path.join(commandsPath, file);
16	const command = require(filePath);
17	client.commands.set(command.data.name, command);
18}
19
20const activities = [
21	{ activity: ActivityType.Watching, subject: 'i cantieri' }, // sta guardando i cantieri
22	{ activity: ActivityType.Playing, subject: 'briscola' }, // sta giocando a briscola
23	{ activity: ActivityType.Competing, subject: 'prato fiorito' }, // in competizione su prato fiorito
24
25	{ activity: ActivityType.Watching, subject: 'i bambini' },
26	{ activity: ActivityType.Playing, subject: 'quel gioco là non mi viene il titolo' },
27	{ activity: ActivityType.Playing, subject: 'mosca cieca in autostrada' },
28	{ activity: ActivityType.Competing, subject: 'cacata ranked al cesso pubblico' },
29];
30
31client.once('ready', () => {
32	const random = Math.floor(Math.random() * (activities.length));
33	const choice = activities[random];
34	client.user.setActivity(choice.subject, { type: choice.activity });
35	console.log('Bot online!');
36});
37
38client.on('interactionCreate', async interaction => {
39	if (!interaction.isChatInputCommand()) return;
40
41	const command = client.commands.get(interaction.commandName);
42
43	if (!command) return;
44
45	try {
46		await command.execute(interaction);
47	}
48	catch (error) {
49		console.error(error);
50		await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
51	}
52});
53
54if (!token)
55	throw 'Check your config.json!';
56
57client.login(token);