all repos — simple-discord-music-bot @ f47db6558591aa10292c163eeb24ceed1becab50

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
12var 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
35	client.user.setActivity(choice.subject, { type: choice.activity });
36	console.log('Bot online!');
37});
38
39client.on('interactionCreate', async interaction => {
40	if (!interaction.isChatInputCommand()) return;
41
42	const command = client.commands.get(interaction.commandName);
43
44	if (!command) return;
45
46	try {
47		await command.execute(interaction);
48	}
49	catch (error) {
50		console.error(error);
51		await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
52	}
53});
54
55if (!token)
56	throw 'Check your config.json!';
57
58client.login(token);