mirror of
https://github.com/musix-org/musix-oss
synced 2026-05-16 04:23:55 +00:00
Compare commits
235 Commits
v3
...
f412d12ecb
| Author | SHA1 | Date | |
|---|---|---|---|
| f412d12ecb | |||
| 2a9e9a75bf | |||
| a2335ea183 | |||
| 453f896705 | |||
| 703c2ff47d | |||
| 6f0632b603 | |||
| 05d7422935 | |||
| 8834d5ce9e | |||
| 02092b6665 | |||
| b62316eba8 | |||
| a489ed045d | |||
| 1dfe6e0225 | |||
| 5d82b4f785 | |||
| c670296ea8 | |||
| c6485d1173 | |||
| fc2bb4e859 | |||
| 740d73ddc2 | |||
| e0acae29ac | |||
| dd8546a7b5 | |||
| c9c4c1b4f5 | |||
| 4b5fea03ee | |||
| 705e93757a | |||
| 93583d88f8 | |||
| aeb235cd87 | |||
| bc1477bdd8 | |||
| d7f112c521 | |||
| 484ee0cbda | |||
| 04a2dd4cb0 | |||
| f1b31d05a3 | |||
| 0ed33d0062 | |||
| e56e0b0506 | |||
| 1f61e8e0c0 | |||
| 66228e844a | |||
| 8a3f366fc5 | |||
| 3ba456c831 | |||
| 12930c874a | |||
| 15be34eaf4 | |||
| 67297de278 | |||
| 9c242c49ed | |||
| 0e223bcae3 | |||
| 0eca2c9bcd | |||
| d6bf153fa3 | |||
| 296d6e126a | |||
| e969bc438e | |||
| a02ba028e1 | |||
| 62c306ab4e | |||
| 89fbaca14e | |||
| 13936662f5 | |||
| 672c693a17 | |||
| 2cdaabfe00 | |||
| 54945b65fd | |||
| 1b074a3f0e | |||
| 95ce5b3e57 | |||
| 60dd4aee38 | |||
| 4e15848715 | |||
| efcaac75c5 | |||
| 6c2ea285b7 | |||
| 48b9f68848 | |||
| f1f5a81feb | |||
| d2fc8552f1 | |||
| 5c2f5fdb73 | |||
| 68c7c7874c | |||
| 3f44d06776 | |||
| d2bad4ee78 | |||
| 83d0aa5a8c | |||
| 6d5bcb0608 | |||
| def022897b | |||
| 38fc626039 | |||
| 04d6855bc8 | |||
| 34b3545a24 | |||
| b1598f5f28 | |||
| 806a3db028 | |||
| 44401d666c | |||
| bb6e1d28b9 | |||
| 3dd931282e | |||
| ea19532261 | |||
| c424c93330 | |||
| a527f84c29 | |||
| cd0fc2beff | |||
| 53241c9062 | |||
| bd1042f2ee | |||
| dffe362648 | |||
| d33ffc042a | |||
| 35739461ba | |||
| 440c7fe99e | |||
| e75e6b4785 | |||
| 5479359f9a | |||
| 8a959de014 | |||
| 26841615a0 | |||
| 3889c69eb3 | |||
| 5a87b39d09 | |||
| 57aa500ee7 | |||
| f23f819a3c | |||
| a58152a896 | |||
| 2042a72b39 | |||
| b2fd69a6bd | |||
| 66332da136 | |||
| 0d1c00fd53 | |||
| 2b6db0e070 | |||
| 6b49a56f71 | |||
| 1c74df8e4e | |||
| c5d5b049f3 | |||
| 47cd3e1539 | |||
| 4abc7ff3df | |||
| e039afb074 | |||
| fac41faf9e | |||
| 1d36a9d285 | |||
| c0651f1ba1 | |||
| 53f9b2bb72 | |||
| b31669bd9f | |||
| aac527787e | |||
| 3c8e6ae403 | |||
| 4fb86fade4 | |||
| ed5702c964 | |||
| 493df7e240 | |||
| 91098e2973 | |||
| ee5a55de50 | |||
| 8af2a345d0 | |||
| b30d497658 | |||
| 07534038d3 | |||
| 0e0d90c859 | |||
| 5bde5f2a02 | |||
| 668b6de332 | |||
| d65d5aae9e | |||
| f64f5dba92 | |||
| d9e7d8d3ad | |||
| 47548f66d0 | |||
| 13b1a320ff | |||
| 0e39d7f210 | |||
| 2ee9414b90 | |||
| c5ca2ec569 | |||
| b4818b6ca4 | |||
| b55e4f25ce | |||
| cb10d308a0 | |||
| f7d19118e9 | |||
| 1eded156f7 | |||
| 337bfe3a87 | |||
| 77b1c5fcd3 | |||
| c0daa44536 | |||
| 8b821c5bb1 | |||
| 02e69b9398 | |||
| e3b3178a5f | |||
| 41dc95cf1b | |||
| c43698aa17 | |||
| 397ad03821 | |||
| 477707c341 | |||
| de81037f05 | |||
| 9a6941aedf | |||
| 85b5a1b26c | |||
| dd4e240925 | |||
| 730ce0dc1c | |||
| 1d224327bf | |||
| 4680497b0e | |||
| adb964cef0 | |||
| 49d9b04d05 | |||
| ac55c4ec9f | |||
| ad3a5c751d | |||
| 6a1d049938 | |||
| 3dea69bfec | |||
| c6a15eb1a0 | |||
| ca99bb7f9c | |||
| 5400f0d14f | |||
| 02d6d42173 | |||
| fdb012be2d | |||
| 4c013f2df7 | |||
| 1b36d9b7f5 | |||
| 33d3907512 | |||
| 2e2f7c2e9a | |||
| 04662353f2 | |||
| 6646f7c118 | |||
| ed6710eacb | |||
| 41b8199958 | |||
| 43a2f99cb0 | |||
| e37beacaf3 | |||
| 0f2a622a84 | |||
| fd30344bd8 | |||
| b966010a37 | |||
| 20938dd9b9 | |||
| 728ea82a7d | |||
| 99e5c6903d | |||
| 2a0d3aab24 | |||
| b8dc88ed85 | |||
| 4a85a7e842 | |||
| ee4829ca28 | |||
| 1b2a6fd7e3 | |||
| 36e1ea30bd | |||
| a40248bc4a | |||
| 2a308321ae | |||
| 38197d8ce9 | |||
| 1e645020cc | |||
| 2771302154 | |||
| c065136b8a | |||
| 735dec1949 | |||
| eb8774b289 | |||
| b66a3b73d7 | |||
| 81eda3780d | |||
| fc9d955a68 | |||
| 54a8d3174d | |||
| 1f0180cf13 | |||
| 6af5b45823 | |||
| b0eac04971 | |||
| bfb105808d | |||
| a33fcd9c40 | |||
| 6b70f6599d | |||
| ca15b1361e | |||
| 33e87d8774 | |||
| eb039662f1 | |||
| 9e7d75927b | |||
| 7e6a6a03ef | |||
| 04314762cc | |||
| b8416bac27 | |||
| bd3008c072 | |||
| 43b71ddb69 | |||
| 936befb259 | |||
| 551007caee | |||
| 23f5cdfce3 | |||
| eb40a640d2 | |||
| f7274b1ce9 | |||
| c703f244a1 | |||
| 9aa5dc7769 | |||
| 60db516870 | |||
| e5df70d320 | |||
| bc636ce416 | |||
| e24b4f0899 | |||
| aef0d98225 | |||
| 97ee60c9a2 | |||
| 46ca9b4f25 | |||
| 61de1c2041 | |||
| 7ebcec8eed | |||
| 3bf7adf902 | |||
| 13ba629479 | |||
| 2aaf8ba525 | |||
| c525181752 | |||
| 5eb0264906 | |||
| cbdffcf19c |
@@ -0,0 +1,3 @@
|
||||
DISCORD_API_TOKEN=
|
||||
BOT_PREFIX=
|
||||
YOUTUBE_API_KEY=
|
||||
@@ -3,6 +3,9 @@ FROM docker.io/node:20-alpine
|
||||
#Dependencies
|
||||
RUN apk add --virtual .build-deps python3 make g++ gcc git
|
||||
|
||||
#Code Dependencies
|
||||
RUN apk add --virtual .code-deps ffmpeg
|
||||
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
COPY / /usr/src/app/
|
||||
|
||||
@@ -0,0 +1,400 @@
|
||||
const { AudioPlayerStatus, createAudioPlayer, createAudioResource, getVoiceConnection, joinVoiceChannel, NoSubscriberBehavior } = require('@discordjs/voice');
|
||||
const { Client, ActivityType, PermissionFlagsBits } = require('discord.js');
|
||||
const Discord = require('discord.js');
|
||||
const YouTube = require('simple-youtube-api')
|
||||
const ytdl = require('ytdl-core');
|
||||
const PREFIX = (process.env.BOT_PREFIX ?? "mx>");
|
||||
const client = new Client({
|
||||
intents: [
|
||||
"Guilds",
|
||||
"GuildMessages",
|
||||
"GuildVoiceStates",
|
||||
"MessageContent"
|
||||
],
|
||||
disableMentions: 'everyone'
|
||||
});
|
||||
const youtube = new YouTube(process.env.YOUTUBE_API_KEY);
|
||||
const queue = new Map();
|
||||
client.login(process.env.DISCORD_API_TOKEN);
|
||||
client.on('ready', () => {
|
||||
client.user.setActivity(`${PREFIX}help`, { type: ActivityType.Listening })
|
||||
client.user.setStatus('online');
|
||||
});
|
||||
client.on('messageCreate', async msg => {
|
||||
if (!msg.guild || msg.author.bot) return;
|
||||
if (msg.content.startsWith(`${PREFIX}`)) {
|
||||
if (msg.content === `${PREFIX}ping`) {
|
||||
msg.channel.send(`My current Ping: **${Math.floor(client.ws.ping * 10) / 10} ms**.`);
|
||||
return;
|
||||
}
|
||||
if (msg.content === `${PREFIX}help`) {
|
||||
const embed = new Discord.EmbedBuilder()
|
||||
.setTitle('Commands for ' + client.user.username + '!')
|
||||
.addFields(
|
||||
{ name: '```' + `${PREFIX}` + 'play | ' + `${PREFIX}` + 'p```', value: 'Play a song.', inline: true },
|
||||
{ name: '```' + `${PREFIX}` + 'queue | ' + `${PREFIX}` + 'q```', value: 'Display the queue.', inline: true },
|
||||
{ name: '```' + `${PREFIX}` + 'nowplaying | ' + `${PREFIX}` + 'np```', value: 'Display whats currently playing.', inline: true },
|
||||
{ name: '```' + `${PREFIX}` + 'volume```', value: 'Change or check the volume.', inline: true },
|
||||
{ name: '```' + `${PREFIX}` + 'pause```', value: 'Pause the music.', inline: true },
|
||||
{ name: '```' + `${PREFIX}` + 'resume```', value: 'Resume the music.', inline: true },
|
||||
{ name: '```' + `${PREFIX}` + 'stop```', value: 'Stop the music, Clear the queue and leave the current voice channel.', inline: true },
|
||||
{ name: '```' + `${PREFIX}` + 'skip | ' + `${PREFIX}` + 's```', value: 'Skip a song.', inline: true },
|
||||
{ name: '```' + `${PREFIX}` + 'invite```', value: 'Invite ' + client.user.username + '.', inline: true },
|
||||
{ name: '```' + `${PREFIX}` + 'ping```', value: 'See the current ping for ' + client.user.username, inline: true },
|
||||
{ name: '```' + `${PREFIX}` + 'info```', value: 'Display info and instructions.', inline: true },
|
||||
{ name: '```' + `${PREFIX}` + 'help```', value: 'Display the help.', inline: true }
|
||||
)
|
||||
.setAuthor({ name: client.user.username, iconURL: client.user.avatarURL() })
|
||||
.setColor('#b50002');
|
||||
msg.channel.send({ embeds: [embed] });
|
||||
return undefined;
|
||||
}
|
||||
if (msg.content === `${PREFIX}info`) {
|
||||
var line = '**>-----------------------------------------------------------------------<**';
|
||||
var dj = msg.guild.roles.cache.find(x => x.name === 'DJ') ? true : false;
|
||||
const embed = new Discord.EmbedBuilder()
|
||||
.setTitle('**' + client.user.username + ' instructions and info**:')
|
||||
.addFields(
|
||||
{ name: 'If your current guild has a role called \'DJ\' you will need it to use music commands! If your current guild doesn\'t have a role called \'DJ\' everyone can use music commands!', value:'DJ role existance: ' + dj, inline: true },
|
||||
{ name: 'If you encounter any errors with ' + client.user.username + ' please report about them on the offical ' + client.user.username + ' support server!', value: 'https://discord.gg/rvHuJtB', inline: true },
|
||||
{ name: `On errors you can do ${PREFIX}stop to reset the queue and try again!`, value: line, inline: true },
|
||||
{ name: 'Current Ping in milliseconds', value: `${Math.floor(client.ws.ping * 10) / 10} ms`, inline: true },
|
||||
{ name: 'Be careful with the Volume command! Volume is not recommended to be put over 3 with user volume at 100%!', value: 'Volume will reset to 1 always when a new song begins!', inline: true }
|
||||
)
|
||||
.setAuthor({ name: client.user.username, iconURL: client.user.avatarURL() })
|
||||
.setColor('#b50002');
|
||||
msg.channel.send({ embeds: [embed] });
|
||||
return undefined;
|
||||
}
|
||||
if (msg.content === `${PREFIX}invite`) {
|
||||
msg.channel.send('Invite me with:' + '\n' + 'https://discord.com/oauth2/authorize?client_id=' + client.user.id + '&permissions=2184465408&scope=applications.commands+bot');
|
||||
return undefined;
|
||||
}
|
||||
if (msg.member.guild.roles.cache.find(x => x.name === 'DJ')) {
|
||||
if (msg.member.roles.cache.find(x => x.name === 'DJ')) {
|
||||
const args = msg.content.split(' ');
|
||||
const searchString = args.slice(1).join(' ');
|
||||
const url = args[1] ? args[1].replace(/<(.+)>/g, '$1') : '';
|
||||
const serverQueue = queue.get(msg.guild.id);
|
||||
|
||||
let command = msg.content.toLowerCase().split(' ')[0];
|
||||
command = command.slice(PREFIX.length);
|
||||
|
||||
if (command === 'play' || command === 'p') {
|
||||
if (!args[1]) return msg.channel.send(':x: I\'m sorry but you didn\'t specify a song');
|
||||
const voiceChannel = msg.member.voice.channel;
|
||||
if (!voiceChannel) return msg.channel.send(':x: I\'m sorry but you need to be in a voice channel to play music!');
|
||||
const permissions = voiceChannel.permissionsFor(msg.client.user);
|
||||
if (!permissions.has(PermissionFlagsBits.Connect)) {
|
||||
return msg.channel.send(':x: I cannot connect to your voice channel, make sure I have the proper permissions!');
|
||||
}
|
||||
if (!permissions.has(PermissionFlagsBits.Speak)) {
|
||||
return msg.channel.send(':x: I cannot speak in this voice channel, make sure I have the proper permissions!');
|
||||
}
|
||||
if (url.match(/^https?:\/\/(www.youtube.com|youtube.com)\/playlist(.*)$/)) {
|
||||
const playlist = await youtube.getPlaylist(url);
|
||||
const videos = await playlist.getVideos();
|
||||
for (const video of Object.values(videos)) {
|
||||
const video2 = await youtube.getVideoByID(video.id);
|
||||
await handleVideo(video2, msg, voiceChannel, true);
|
||||
}
|
||||
return msg.channel.send(`:white_check_mark: Playlist: **${playlist.title}** has been added to the queue!`);
|
||||
} else {
|
||||
try {
|
||||
var video = await youtube.getVideo(url);
|
||||
} catch (error) {
|
||||
try {
|
||||
var videos = await youtube.searchVideos(searchString, 10);
|
||||
let index = 0;
|
||||
msg.channel.send(`
|
||||
__**Song selection:**__
|
||||
${videos.map(video2 => `**${++index} -** ${video2.title}`).join('\n')}
|
||||
Please provide a value to select one of the search results ranging from 1-10.
|
||||
`);
|
||||
|
||||
try {
|
||||
var response = await msg.channel.awaitMessages({
|
||||
filter: msg2 => msg2.content > 0 && msg2.content < 11,
|
||||
max: 1,
|
||||
time: 10000,
|
||||
errors: ['time']
|
||||
});
|
||||
} catch (err) {
|
||||
return msg.channel.send(':x: Cancelling song selection.');
|
||||
}
|
||||
const videoIndex = parseInt(response.first().content);
|
||||
|
||||
var video = await youtube.getVideoByID(videos[videoIndex - 1].id);
|
||||
} catch (err) {
|
||||
return msg.channel.send(':x: I could not obtain any search results.');
|
||||
}
|
||||
}
|
||||
return handleVideo(video, msg, voiceChannel);
|
||||
}
|
||||
} else if (command === 'skip' || command === 's') {
|
||||
if (!msg.member.voice.channel) return msg.channel.send(':x: You are not in a voice channel!');
|
||||
if (!serverQueue) return msg.channel.send(':x: There is nothing playing that I could skip for you.');
|
||||
if (!serverQueue.songs[1]) return msg.channel.send(':x: Theres nothing to skip to!')
|
||||
serverQueue.audioPlayer.stop();
|
||||
return;
|
||||
} else if (command === 'stop') {
|
||||
if (!msg.member.voice.channel) return msg.channel.send(':x: You are not in a voice channel!');
|
||||
if (!serverQueue) return msg.channel.send(':x: There is nothing playing that I could stop for you.');
|
||||
serverQueue.songs = [];
|
||||
serverQueue.audioPlayer.stop();
|
||||
return;
|
||||
} else if (command === 'volume') {
|
||||
if (!msg.member.voice.channel) return msg.channel.send(':x: You are not in a voice channel!');
|
||||
if (!serverQueue) return msg.channel.send(':x: There is nothing playing.');
|
||||
if (!args[1]) return msg.channel.send(`The current volume is: **${serverQueue.volume}** :speaker:`);
|
||||
if (isNaN(args[1])) {
|
||||
return msg.channel.send(':x: I\'m sorry, But you need to enter a valid __number__.')
|
||||
}
|
||||
serverQueue.volume = args[1];
|
||||
serverQueue.audioResource.volume.setVolume(args[1] / 100);
|
||||
return msg.channel.send(`I set the volume to: **${args[1]}** 🔊`);
|
||||
} else if (command === 'np' || command === 'nowplaying') {
|
||||
if (!serverQueue) return msg.channel.send(':x: There is nothing playing.');
|
||||
return msg.channel.send(`:musical_note: Now playing: **${serverQueue.songs[0].title}**`);
|
||||
} else if (command === "queue" || command === 'q') {
|
||||
if (!serverQueue)
|
||||
return msg.channel.send(":x: There is nothing in the queue.");
|
||||
var queuemessage = `__**Song queue:**__
|
||||
${serverQueue.songs.map(song => `**-** ${song.title}`).join("\n")}
|
||||
**Now playing:** ${serverQueue.songs[0].title} :musical_note: `;
|
||||
if (queuemessage.length > 2000) {
|
||||
return msg.channel.send(":x: The queue has too many songs in it to show all in this channel. Try again after a few songs.");
|
||||
}
|
||||
return msg.channel.send(queuemessage);
|
||||
} else if (command === 'pause') {
|
||||
if (serverQueue && serverQueue.playing) {
|
||||
serverQueue.playing = false;
|
||||
serverQueue.audioPlayer.pause();
|
||||
return msg.channel.send(':pause_button: Paused the music for you!');
|
||||
}
|
||||
return msg.channel.send(':x: There is nothing playing.');
|
||||
} else if (command === 'resume') {
|
||||
if (serverQueue && !serverQueue.playing) {
|
||||
serverQueue.playing = true;
|
||||
serverQueue.audioPlayer.unpause();
|
||||
return msg.channel.send(':play_pause: Resumed the music for you!');
|
||||
}
|
||||
return msg.channel.send(':x: There is nothing playing.');
|
||||
}
|
||||
if (msg.content === `${PREFIX}`) return;
|
||||
msg.channel.send(`:x: Unknown command! Type ${PREFIX}help for the list of commands!`)
|
||||
return;
|
||||
}
|
||||
if (msg.content === `${PREFIX}`) return;
|
||||
var coms = [`${PREFIX}play`, `${PREFIX}queue`, `${PREFIX}np`, `${PREFIX}volume`, `${PREFIX}pause`, `${PREFIX}resume`, `${PREFIX}stop`, `${PREFIX}skip`, `${PREFIX}ping`, `${PREFIX}q`, `${PREFIX}nowplaying`, `${PREFIX}p`, `${PREFIX}s`];
|
||||
for (var i = 0; i < coms.length; i++) {
|
||||
if (msg.content.includes(coms[i])) {
|
||||
if (!msg.member.roles.cache.find(x => x.name === 'DJ')) {
|
||||
msg.channel.send(':x: i\'m sorry but you need to have the \'DJ\' role to use music commands!')
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
msg.channel.send(`:x: Unknown command! Type ${PREFIX}help for the list of commands!`)
|
||||
return;
|
||||
} else {
|
||||
const args = msg.content.split(' ');
|
||||
const searchString = args.slice(1).join(' ');
|
||||
const url = args[1] ? args[1].replace(/<(.+)>/g, '$1') : '';
|
||||
const serverQueue = queue.get(msg.guild.id);
|
||||
|
||||
let command = msg.content.toLowerCase().split(' ')[0];
|
||||
command = command.slice(PREFIX.length)
|
||||
|
||||
if (command === 'play' || command === 'p') {
|
||||
if (!args[1]) return msg.channel.send(':x: I think you forgot what you wanted to play!');
|
||||
const voiceChannel = msg.member.voice.channel;
|
||||
if (!voiceChannel) return msg.channel.send(':x: I\'m sorry but you need to be in a voice channel to play music!');
|
||||
const permissions = voiceChannel.permissionsFor(msg.client.user);
|
||||
if (!permissions.has(PermissionFlagsBits.Connect)) {
|
||||
return msg.channel.send(':x: I cannot connect to your voice channel, make sure I have the proper permissions!');
|
||||
}
|
||||
if (!permissions.has(PermissionFlagsBits.Speak)) {
|
||||
return msg.channel.send(':x: I cannot speak in this voice channel, make sure I have the proper permissions!');
|
||||
}
|
||||
|
||||
if (url.match(/^https?:\/\/(www.youtube.com|youtube.com)\/playlist(.*)$/)) {
|
||||
const playlist = await youtube.getPlaylist(url);
|
||||
const videos = await playlist.getVideos();
|
||||
for (const video of Object.values(videos)) {
|
||||
const video2 = await youtube.getVideoByID(video.id); // eslint-disable-line no-await-in-loop
|
||||
await handleVideo(video2, msg, voiceChannel, true); // eslint-disable-line no-await-in-loop
|
||||
}
|
||||
return msg.channel.send(`:white_check_mark: Playlist: **${playlist.title}** has been added to the queue!`);
|
||||
} else {
|
||||
try {
|
||||
var video = await youtube.getVideo(url);
|
||||
} catch (error) {
|
||||
try {
|
||||
var videos = await youtube.searchVideos(searchString, 10);
|
||||
let index = 0;
|
||||
msg.channel.send(`
|
||||
__**Song selection:**__
|
||||
${videos.map(video2 => `**${++index} -** ${video2.title}`).join('\n')}
|
||||
Please provide a value to select one of the search results ranging from 1-10.
|
||||
`);
|
||||
// eslint-disable-next-line max-depth
|
||||
try {
|
||||
var response = await msg.channel.awaitMessages(msg2 => msg2.content > 0 && msg2.content < 11, {
|
||||
maxMatches: 1,
|
||||
time: 10000,
|
||||
errors: ['time']
|
||||
});
|
||||
} catch (err) {
|
||||
return msg.channel.send(':x: No or invalid value entered, cancelling video selection.');
|
||||
}
|
||||
const videoIndex = parseInt(response.first().content);
|
||||
var video = await youtube.getVideoByID(videos[videoIndex - 1].id);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
return msg.channel.send(':x: I could not obtain any search results.');
|
||||
}
|
||||
}
|
||||
return handleVideo(video, msg, voiceChannel);
|
||||
}
|
||||
} else if (command === 'skip' || command === 's') {
|
||||
if (!msg.member.voice.channel) return msg.channel.send(':x: You are not in a voice channel!');
|
||||
if (!serverQueue) return msg.channel.send(':x: There is nothing playing that I could skip for you.');
|
||||
msg.channel.send('Skipped :thumbsup:')
|
||||
serverQueue.audioPlayer.stop();
|
||||
return undefined;
|
||||
} else if (command === 'stop') {
|
||||
if (!msg.member.voice.channel) return msg.channel.send(':x: You are not in a voice channel!');
|
||||
if (!serverQueue) return msg.channel.send(':x: There is nothing playing that I could stop for you.');
|
||||
msg.channel.send('Stopped the music! :stop_button:')
|
||||
serverQueue.songs = [];
|
||||
serverQueue.audioPlayer.stop();
|
||||
return undefined;
|
||||
} else if (command === 'volume') {
|
||||
if (!msg.member.voice.channel) return msg.channel.send(':x: You are not in a voice channel!');
|
||||
if (!serverQueue) return msg.channel.send(':x: There is nothing playing.');
|
||||
if (!args[1]) return msg.channel.send(`The current volume is: **${serverQueue.volume}** :speaker:`);
|
||||
if (isNaN(args[1])) {
|
||||
return msg.channel.send(':x: I\'m sorry, But you need to enter a valid __number__.')
|
||||
}
|
||||
serverQueue.volume = args[1];
|
||||
serverQueue.audioResource.volume.setVolume(args[1] / 100);
|
||||
return msg.channel.send(`I set the volume to: **${args[1]}** 🔊`);
|
||||
} else if (command === 'np' || command === 'nowplaying') {
|
||||
if (!serverQueue) return msg.channel.send(':x: There is nothing playing.');
|
||||
return msg.channel.send(`:musical_note: Now playing: **${serverQueue.songs[0].title}**`);
|
||||
} else if (command === "queue" || command === 'q') {
|
||||
if (!serverQueue)
|
||||
return msg.channel.send(":x: There is nothing in the queue.");
|
||||
var queuemessage = `__**Song queue:**__
|
||||
${serverQueue.songs.map(song => `**-** ${song.title}`).join("\n")}
|
||||
**Now playing:** ${serverQueue.songs[0].title} :musical_note: `;
|
||||
if (queuemessage.length < 2000) {
|
||||
return msg.channel.send(":x: The queue has too many songs in it to show all in this channel. Try again after a few songs");
|
||||
}
|
||||
return msg.channel.send(queuemessage);
|
||||
} else if (command === 'pause') {
|
||||
if (serverQueue && serverQueue.playing) {
|
||||
serverQueue.playing = false;
|
||||
serverQueue.audioPlayer.pause();
|
||||
return msg.channel.send(':pause_button: Paused the music for you!');
|
||||
}
|
||||
return msg.channel.send(':x: There is nothing playing.');
|
||||
} else if (command === 'resume') {
|
||||
if (serverQueue && !serverQueue.playing) {
|
||||
serverQueue.playing = true;
|
||||
serverQueue.audioPlayer.unpause();
|
||||
return msg.channel.send(':play_pause: Resumed the music for you!');
|
||||
}
|
||||
return msg.channel.send(':x: There is nothing playing.');
|
||||
}
|
||||
}
|
||||
if (msg.content === `${PREFIX}`) {
|
||||
return;
|
||||
}
|
||||
msg.channel.send(`:x: Unknown command! Type ${PREFIX}help for the list of commands!`)
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
async function handleVideo(video, msg, voiceChannel, playlist = false) {
|
||||
const serverQueue = queue.get(msg.guild.id);
|
||||
const song = {
|
||||
id: video.id,
|
||||
title: video.title,
|
||||
url: `https://www.youtube.com/watch?v=${video.id}`
|
||||
};
|
||||
if (!serverQueue) {
|
||||
const queueConstruct = {
|
||||
textChannel: msg.channel,
|
||||
voiceChannel: voiceChannel,
|
||||
connection: null,
|
||||
audioPlayer: createAudioPlayer({
|
||||
behaviors: {
|
||||
noSubscriber: NoSubscriberBehavior.Play,
|
||||
}
|
||||
}),
|
||||
audioResource: null,
|
||||
songs: [],
|
||||
volume: 50,
|
||||
playing: true
|
||||
};
|
||||
|
||||
queue.set(msg.guild.id, queueConstruct);
|
||||
|
||||
queueConstruct.songs.push(song);
|
||||
|
||||
try {
|
||||
const connection =
|
||||
getVoiceConnection(voiceChannel.guild.id) ??
|
||||
joinVoiceChannel({
|
||||
channelId: voiceChannel.id,
|
||||
guildId: voiceChannel.guild.id,
|
||||
adapterCreator: voiceChannel.guild.voiceAdapterCreator
|
||||
});
|
||||
queueConstruct.connection = connection;
|
||||
play(msg.guild, queueConstruct.songs[0]);
|
||||
} catch (error) {
|
||||
console.error(`I could not join the voice channel: ${error}`);
|
||||
queue.delete(msg.guild.id);
|
||||
return msg.channel.send(`:x: I could not join the voice channel: ${error}`);
|
||||
}
|
||||
} else {
|
||||
serverQueue.songs.push(song);
|
||||
if (playlist) return undefined;
|
||||
else return msg.channel.send(`:white_check_mark: **${song.title}** has been added to the queue!`);
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function play(guild, song) {
|
||||
const serverQueue = queue.get(guild.id);
|
||||
|
||||
if (!song) {
|
||||
serverQueue.connection.destroy();
|
||||
queue.delete(guild.id);
|
||||
return;
|
||||
}
|
||||
|
||||
serverQueue.audioPlayer
|
||||
.on(AudioPlayerStatus.Idle, () => {
|
||||
serverQueue.songs.shift();
|
||||
serverQueue.audioPlayer.removeAllListeners();
|
||||
play(guild, serverQueue.songs[0]);
|
||||
})
|
||||
.on('error', (error) => {
|
||||
console.error(error)
|
||||
});
|
||||
|
||||
const audioResource = createAudioResource(ytdl(song.url, { quality: `highestaudio`, filter: 'audioonly' }),{
|
||||
inlineVolume: true
|
||||
});
|
||||
|
||||
audioResource.volume.setVolume(serverQueue.volume / 100);
|
||||
|
||||
serverQueue.audioPlayer.play(audioResource);
|
||||
serverQueue.audioResource = audioResource;
|
||||
serverQueue.connection.subscribe(serverQueue.audioPlayer);
|
||||
|
||||
serverQueue.textChannel.send(`:musical_note: Start playing: **${song.title}**`);
|
||||
}
|
||||
Generated
+1663
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"name": "musix-oss",
|
||||
"version": "1.3.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"start": "node index.js",
|
||||
"start:dev": "nodemon",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"discord.js": "^14.24.2",
|
||||
"@discordjs/voice": "^0.19.0",
|
||||
"@discordjs/opus": "^0.10.0",
|
||||
"ms": "^2.1.3",
|
||||
"request": "^2.88.2",
|
||||
"simple-youtube-api": "^5.2.1",
|
||||
"ytdl-core": "^4.11.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"nodemon": "^3.1.11"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user