-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.js
110 lines (95 loc) · 3.35 KB
/
bot.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
const { Client, Collection, GatewayIntentBits, Partials } = require('discord.js');
const { DisTube } = require('distube');
const { SpotifyPlugin } = require('@distube/spotify');
const { SoundCloudPlugin } = require('@distube/soundcloud');
const { YtDlpPlugin } = require('@distube/yt-dlp');
const { bgBlue, bgYellow, bgGreen, bgCyan, bgRed } = require('colorette');
const { readdirSync } = require('fs');
const { emoji, token } = require('./config.json');
const logger = require('./modules/logger.js');
// Cliente Discord part
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildVoiceStates,
],
partials: [Partials.Channel, Partials.Reaction],
});
// Set commands, slash commands and eventes on containers
const commands = new Collection();
const aliases = new Collection();
const slashcmds = new Collection();
client.emotes = emoji;
client.container = {
commands,
aliases,
slashcmds,
};
// Cliente Music Part
client.distube = new DisTube(client, {
leaveOnStop: false,
emitNewSongOnly: true,
emitAddSongWhenCreatingQueue: true,
emitAddListWhenCreatingQueue: true,
plugins: [
new SpotifyPlugin({ emitEventsAfterFetching: true }),
new SoundCloudPlugin(),
new YtDlpPlugin(),
],
});
const status = (queue) =>
`Volume: \`${(queue.volume = 100)}%\` | Filter: \`${
queue.filters.names.join(', ') || 'Off'
}\` | Loop: \`${
queue.repeatMode ? (queue.repeatMode === 2 ? 'All Queue' : 'This Song') : 'Off'
}\` | Autoplay: \`${queue.autoplay ? 'On' : 'Off'}\``;
// Initialization funciotn
const init = async () => {
// Search a load the commands
readdirSync('./commands/').map(async (dir) => {
readdirSync(`./commands/${dir}/`).map(async (cmd) => {
const props = require(`./commands/${dir}/${cmd}`);
logger.log(`Loading ${bgBlue('Command')}: ${props.help.name}`, 'log');
client.container.commands.set(props.help.name, props);
props.conf.aliases.forEach((alias) => {
client.container.aliases.set(alias, props.help.name);
});
});
});
// Search a load the slash commands
readdirSync('./slash').map(async (dir) => {
readdirSync(`./slash/${dir}/`).map(async (cmd) => {
const props = require(`./slash/${dir}/${cmd}`);
logger.log(`Loading ${bgYellow('Slash command')}: ${props.name}`, 'log');
client.container.slashcmds.set(props.name, props);
});
});
// Search the discord's events
const loadEvent = (dirs) => {
const events = readdirSync(`./events/${dirs}/`).filter((d) => d.endsWith('js'));
for (const file of events) {
const event = require(`./events/${dirs}/${file}`);
const eventName = file.split('.')[0];
logger.log(`Loading ${bgGreen('Event')}: ${eventName}`, 'log');
client.on(eventName, event.bind(null, client));
}
};
['client', 'guild'].forEach((x) => loadEvent(x));
// Search the music's events
const loadMusic = () => {
const events = readdirSync('./events/music/').filter((d) => d.endsWith('js'));
for (const file of events) {
const event = require(`./events/music/${file}`);
const eventName = file.split('.')[0];
logger.log(`Loading ${bgCyan('Music Event')}: ${eventName}`, 'log');
client.distube.on(eventName, event.bind(null, client, status));
}
};
['music'].forEach((x) => loadMusic(x));
client.login(token);
};
init();