-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
128 lines (110 loc) · 4.25 KB
/
app.js
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
/*
* Copyright (C) 2021 Wojciech Jablonski All rights reserved.
*
* This document is the property of Wojciech Jablonski <info@wojciechjablonski.com>.
* It is considered confidential and proprietary.
*
* This document may not be reproduced or transmitted in any form,
* in whole or in part, without the express written permission of
* Wojciech Jablonski <info@wojciechjablonski.com>.
*/
/* Libraries */
const {Client, GatewayIntentBits} = require('discord.js');
const dotenv = require("dotenv");
const {SlashCreator, GatewayServer} = require('slash-create');
const { DisTube } = require('distube');
const { SpotifyPlugin } = require('@distube/spotify');
const { SoundCloudPlugin } = require('@distube/soundcloud');
const { YtDlpPlugin } = require('@distube/yt-dlp');
const path = require('path');
const fs = require('fs');
/* Client Inizialization */
dotenv.config();
const CatLoggr = require('cat-loggr');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.DirectMessageReactions,
GatewayIntentBits.GuildBans,
GatewayIntentBits.GuildInvites,
GatewayIntentBits.GuildMessageTyping,
GatewayIntentBits.DirectMessageTyping,
GatewayIntentBits.GuildEmojisAndStickers,
GatewayIntentBits.MessageContent,
GatewayIntentBits.DirectMessages,
GatewayIntentBits.GuildIntegrations,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.GuildPresences,
GatewayIntentBits.GuildWebhooks
]
});
client.logger = new CatLoggr().setLevel(process.env.COMMANDS_DEBUG === 'true' ? 'debug' : 'info');
client.distube = new DisTube(client, {
directLink: true,
nsfw:true,
searchSongs: 5,
searchCooldown: 30,
leaveOnEmpty: true,
leaveOnFinish: false,
leaveOnStop: false,
emitNewSongOnly: true,
emitAddSongWhenCreatingQueue: false,
emitAddListWhenCreatingQueue: false,
youtubeCookie: process.env?.YT_COOKIE,
youtubeIdentityToken: process.env?.YT_ID,
plugins: [
new SpotifyPlugin({
emitEventsAfterFetching: true
}),
new SoundCloudPlugin(),
new YtDlpPlugin({ update: false })
]
})
const creator = new SlashCreator({
applicationID: process.env.APPLICATION_ID,
publicKey: process.env.PUBLIC_KEY,
token: process.env.TOKEN,
});
creator.on('debug', (message) => client.logger.log(message));
creator.on('warn', (message) => client.logger.warn(message));
creator.on('error', (error) => client.logger.error(error));
creator.on('synced', () => client.logger.info('Slash commands synced!'));
creator.on('commandRun', (command, _, ctx) => {
client.logger.info(`[${client.guilds.cache.get(ctx.guildID).name} (${ctx.guildID})] ${ctx.user.username}#${ctx.user.discriminator} (${ctx.user.id}) ran command ${command.commandName}`)
});
creator.on('commandRegister', (command) =>
client.logger.info(`Registered command ${command.commandName}`));
creator.on('commandError', (command, error) => client.logger.error(`Command ${command.commandName}:`, error));
creator
.withServer(
new GatewayServer(
(handler) => client.ws.on('INTERACTION_CREATE', handler)
)
)
.registerCommandsIn(path.join(__dirname, 'commands'))
.syncCommands({
syncPermissions: true
});
const events = fs.readdirSync('./events').filter(file => file.endsWith('.js'));
for (const file of events) {
client.logger.info(`Loaded event ${file}`);
const eventName = file.split(".")[0];
const event = new (require(`./events/${file}`))(client);
client.on(eventName, (...args) => event.create(...args));
delete require.cache[require.resolve(`./events/${file}`)];
}
const player = fs.readdirSync('./events/player').filter(file => file.endsWith('.js'));
for (const file of player) {
client.logger.info(`Loaded player event ${file}`);
const eventName = file.split(".")[0];
const event = new (require(`./events/player/${file}`))(client);
client.distube.on(eventName, (...args) => event.create(...args));
delete require.cache[require.resolve(`./events/player/${file}`)];
}
client.login(process.env.TOKEN);
module.exports = {
client
};