functions/music.js (view raw)
1const {
2 createAudioResource,
3 joinVoiceChannel,
4 AudioPlayerStatus,
5} = require('@discordjs/voice');
6const play = require('play-dl');
7const { MyQueue } = require('./myqueue')
8
9const q = new MyQueue();
10
11function getChannelConnection(channel) {
12 const guild = channel.guild;
13 return joinVoiceChannel({
14 channelId: channel.id,
15 guildId: guild.id,
16 adapterCreator: guild.voiceAdapterCreator
17 })
18}
19
20module.exports = {
21 async playUrls(urls, channel) {
22 if (!channel) {
23 console.log('Channel error:', channel);
24 return;
25 }
26
27 q.connection = getChannelConnection(channel);
28 return q.addArray(urls);
29 },
30 async playStream(url, channel) {
31 if (!channel) {
32 console.log('Channel error:', channel);
33 return;
34 }
35 q.connection = getChannelConnection(channel);
36 q.add(createAudioResource(url, { inputType: 'mp3' }));
37 },
38 async playOutro(url, channel) {
39 if (!channel) {
40 console.log('Channel error:', channel);
41 return;
42 }
43 q.connection = getChannelConnection(channel);
44 q.outro(url);
45 },
46 async getChannel(interaction) {
47 const member = interaction.member;
48 if (!member)
49 return 'Please use this in your current server.';
50
51 const channel = member.voice.channel;
52 if (!channel)
53 return 'You\'re not in a voice channel.';
54
55 return channel;
56 },
57 async stopMusic() {
58 return q.stop();
59 },
60 async skipMusic() {
61 return q.next();
62 },
63 async getQueue() {
64 return q.queue;
65 },
66 clearQueue() {
67 return q.clear();
68 }
69};