-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
107 lines (102 loc) · 3.13 KB
/
index.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
const {
Client,
GatewayIntentBits,
EmbedBuilder,
ButtonBuilder,
ButtonStyle,
} = require("discord.js");
const { DisTube } = require("distube");
const { REST, Routes, Collection } = require("discord.js");
const fs = require("fs");
const { SpotifyPlugin } = require("@distube/spotify");
const { SoundCloudPlugin } = require("@distube/soundcloud");
const { YtDlpPlugin } = require("@distube/yt-dlp");
const dotenv = require("dotenv");
dotenv.config();
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.MessageContent,
],
});
client.distube = new DisTube(client, {
leaveOnStop: false,
emitNewSongOnly: true,
emitAddSongWhenCreatingQueue: false,
emitAddListWhenCreatingQueue: false,
plugins: [
new SpotifyPlugin({
emitEventsAfterFetching: true,
}),
new SoundCloudPlugin(),
new YtDlpPlugin(),
],
});
client.commands = new Collection();
const commands = [];
const commandFiles = fs
.readdirSync("./commands")
.filter((file) => file.endsWith(".js"));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
client.commands.set(command.data.name, command);
commands.push(command.data.toJSON());
}
const rest = new REST({ version: "10" }).setToken(process.env.TOKEN);
rest
.put(Routes.applicationCommands(process.env.BOTID), { body: commands })
.then((data) =>
console.log(`Successfully registered ${data.length} application commands.`)
)
.catch(console.error);
client.on("interactionCreate", async (interaction) => {
if (!interaction.isChatInputCommand()) return;
const command = client.commands.get(interaction.commandName);
if (!command) return;
try {
command.execute(client, interaction);
} catch (error) {
console.error(error);
}
});
client.once("ready", () => {
console.log("Ready!");
});
const embed = new EmbedBuilder();
const status = (queue) =>
`Volume: \`${queue.volume}%\` | Filter: \`${
queue.filters.names.join(", ") || "Off"
}\` | Loop: \`${
queue.repeatMode
? queue.repeatMode === 2
? "All Queue"
: "This Song"
: "Off"
}\` | Autoplay: \`${queue.autoplay ? "On" : "Off"}\``;
client.distube
.on("playSong", (queue, song) => {
embed
.setDescription(
`▶️ | Playing \`${song.name}\` - \`${
song.formattedDuration
}\`\nRequested by: ${song.user}\n${status(queue)}`
)
.setThumbnail(song.thumbnail)
.setColor("Random"),
queue.textChannel.send({ embeds: [embed] });
})
.on("error", (channel, e) => {
if (channel)
channel.send(`❌ | An error encountered: ${e.toString().slice(0, 1974)}`);
else console.error(e);
})
.on("empty", (channel) =>
channel.send("Voice channel is empty! Leaving the channel...")
)
.on("searchNoResult", (message, query) =>
message.channel.send(`❌ | No result found for \`${query}\`!`)
)
.on("finish", (queue) => queue.textChannel.send("Finished!"));
client.login(process.env.TOKEN);