-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmusic.js
More file actions
320 lines (292 loc) · 9.33 KB
/
music.js
File metadata and controls
320 lines (292 loc) · 9.33 KB
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
const app = require("express")();
app.get("/", (req, res) => {
res.send("Server is up and running!");
});
app.listen(8080);
require("dotenv").config();
const Discord = require("discord.js");
const DisTube = require("distube");
const { prefix } = require("./config.json");
const client = new Discord.Client();
const distube = new DisTube(client, {
searchSongs: false,
emitNewSongOnly: true,
highWaterMark: 1 << 25,
});
client.on("ready", () => {
console.log(`Logged in as ${client.user.tag}!`);
client.user.setActivity(`${client.channels.cache.size} Channels | ?help`, {
type: "WATCHING",
});
});
client.on("guildCreate", (guild) => {
guild.createRole({ name: "Muted", color: "#313131" });
console.log("Joined a new server: " + guild.name);
console.log("It has " + guild.memberCount + " members ;)");
});
client.on("guildDelete", (guild) => {
console.log("Left the server:" + guild.name);
});
let connectionDispatcher;
const filters = [
"3d",
"bassboost",
"echo",
"karaoke",
"nightcore",
"vaporwave",
"flanger",
];
client.login(process.env.TOKEN);
client.on("message", async (message) => {
if (message.author.bot) {
return;
}
if (message.author.bot || !message.content.startsWith(prefix)) return;
const args = message.content.slice(prefix.length).split(" ");
const command = args.shift().toLowerCase();
const voiceChannel = message.member.voice.channel;
if (command === "radio-start") {
if (!voiceChannel) {
return message.channel.send("You need to be in a voice channel!");
}
const permissions = voiceChannel.permissionsFor(message.client.user);
if (!permissions.has("CONNECT") || !permissions.has("SPEAK")) {
return message.channel.send(
"I don't have permissions to join and speak in that voice channel!"
);
}
voiceChannel.join().then((connection) => {
connectionDispatcher = connection.play(
"https://coderadio-admin.freecodecamp.org/radio/8010/radio.mp3"
);
const radio_play_embed = new Discord.MessageEmbed()
.setTitle("Started Playing the Radio!")
.setDescription(
"**:white_check_mark: Joined the Voice Channel and Playing the radio.** \n \n *Powered by FreeCodeCamp Radio*"
)
.setThumbnail(
"https://media.discordapp.net/attachments/793772583946027050/801479779441967144/Z.png"
)
.setColor("RANDOM")
.setFooter(
client.user.username,
client.user.displayAvatarURL()
);
message.channel.send(radio_play_embed);
});
}
if (command === "radio-stop") {
if (connectionDispatcher) {
connectionDispatcher.end();
voiceChannel.leave();
message.channel.send(
":white_check_mark: Stopped the Radio and left the Voice channel!"
);
}
}
if (command === "radio-pause") {
if (connectionDispatcher) {
if (connectionDispatcher) {
connectionDispatcher.end();
return message.channel.send(
":white_check_mark: Paused the Music and resting in the voice channel!"
);
}
}
}
if (command === "ping") {
return embedbuilder(
client,
message,
`sBLUE`,
`PING:`,
`\`${client.ws.ping} ms\``
);
}
if (message.content === "test") {
const to_play = args.join(" ");
message.channel.send(`${to_play}`);
}
if (command === "play" || command === "p") {
const to_play = args.join(" ");
message.channel.send(
"<:YouTube:801465200775135282> **Searching** :mag_right: `" +
`${to_play}` +
"`"
);
return distube.play(message, args.join(" "));
}
if (command === "skip" || command === "s") {
message.channel.send(":white_check_mark: Song Skipped!");
return distube.skip(message);
}
if (command === "stop" || command === "leave") {
message.channel.send(
":white_check_mark: Cleared the Queue and Left the Voice Channel!"
);
distube.stop(message);
}
if (command === "seek") {
embedbuilder(
client,
message,
"GREEN",
"Seeked!",
`seeked the song for \`${args[0]} seconds\``
);
return distube.seek(message, Number(args[0] * 1000));
}
if (filters.includes(command)) {
let filter = distube.setFilter(message, command);
return embedbuilder(
client,
message,
"YELLOW",
"Adding filter!",
filter
);
}
if (command === "volume" || command === "vol") {
embedbuilder(
client,
message,
"GREEN",
"VOLUME!",
`changed volume to \`${args[0]} %\``
);
return distube.setVolume(message, args[0]);
}
if (command === "queue" || command === "qu") {
let queue = distube.getQueue(message);
let curqueue = queue.songs
.map(
(song, id) =>
`**${id + 1}**. ${song.name} - \`${
song.formattedDuration
}\``
)
.join("\n");
return embedbuilder(
client,
message,
"GREEN",
"Current Queue!",
curqueue
);
}
if (command === "loop" || command === "repeat") {
if (0 <= Number(args[0]) && Number(args[0]) <= 2) {
distube.setRepeatMode(message, parseInt(args[0]));
embedbuilder(
client,
message,
"GREEN",
"Repeat mode set to:!",
`${args[0]
.replace("0", "OFF")
.replace("1", "Repeat song")
.replace("2", "Repeat Queue")}`
);
} else {
embedbuilder(
client,
message,
"RED",
"ERROR",
`Please use a number between **0** and **2** | *(0: disabled, 1: Repeat a song, 2: Repeat all the queue)*`
);
}
}
});
//queue
const status = (queue) =>
`Volume: \`${queue.volume}\` | Filter: \`${
queue.filter || "OFF"
}\` | Loop: \`${
queue.repeatMode
? queue.repeatMode === 2
? "All Queue"
: "This Song"
: "Off"
}\` | Autoplay: \`${queue.autoplay ? "On" : "Off"}\``;
//distube
distube
.on("playSong", (message, queue, song) => {
embedbuilder(
client,
message,
"GREEN",
"Playing new Song!",
`Song: \`${song.name}\` - \`${
song.formattedDuration
}\` \n\nRequested by: ${song.user}\n${status(queue)}`
);
})
.on("addSong", (message, queue, song) => {
embedbuilder(
client,
message,
"GREEN",
"Added a Song!",
`Song: \`${song.name}\` - \`${song.formattedDuration}\` \n\nRequested by: ${song.user}`
);
})
.on("playList", (message, queue, playlist, song) => {
embedbuilder(
client,
message,
"GREEN",
"Playling playlist",
`Playlist: \`${playlist.title}\` - \`${
playlist.total_items
} songs\` \n\nRequested by: ${
song.user
}\n\nstarting playing Song: \`${song.name}\` - \`${
song.formattedDuration
}\`\n${status(queue)}`
);
})
.on("addList", (message, queue, song) => {
embedbuilder(
client,
message,
"GREEN",
"Added a Playling!",
`Playlist: \`${playlist.title}\` - \`${playlist.total_items} songs\` \n\nRequested by: ${song.user}`
);
})
.on("searchResult", (message, result) => {
let i = 0;
embedbuilder(
client,
message,
"YELLOW",
"",
`**Choose an option from below**\n${result
.map(
(song) =>
`**${++i}**. ${song.name} - \`${
song.formattedDuration
}\``
)
.join(
"\n"
)}\n*Enter anything else or wait 60 seconds to cancel*`
);
})
// DisTubeOptions.searchSongs = true
.on("searchCancel", (message) =>
embedbuilder(client, message, "RED", `Searching canceled`, "")
)
.on("error", (message, err) =>
embedbuilder(client, message, "RED", "An error encountered:", err)
);
function embedbuilder(client, message, color, title, description) {
let embed = new Discord.MessageEmbed()
.setColor(color)
.setFooter(client.user.username, client.user.displayAvatarURL());
if (title) embed.setTitle(title);
if (description) embed.setDescription(description);
return message.channel.send(embed);
}