mirror of
https://github.com/musix-org/musix-oss
synced 2025-07-04 20:14:28 +00:00
Fix code to work on this decade
This commit is contained in:
251
index.js
251
index.js
@ -1,102 +1,94 @@
|
||||
const { Client, Util } = require('discord.js');
|
||||
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 = ('-')
|
||||
const client = new Client({ disableEveryone: true });
|
||||
const youtube = new YouTube(process.env.API_KEY);
|
||||
const queue = new Map();
|
||||
client.login(process.env.BOT_TOKEN);
|
||||
client.on('ready', () => {
|
||||
client.user.setActivity('-help', { type: 'LISTENING' })
|
||||
client.user.setStatus('dnd');
|
||||
const PREFIX = (process.env.BOT_PREFIX ?? "mx>");
|
||||
const client = new Client({
|
||||
intents: [
|
||||
"Guilds",
|
||||
"GuildMessages",
|
||||
"GuildVoiceStates",
|
||||
"MessageContent"
|
||||
],
|
||||
disableMentions: 'everyone'
|
||||
});
|
||||
client.on('message', async msg => {
|
||||
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.toUpperCase().startsWith(`MUSIX`)) {
|
||||
msg.channel.send('-help to see my commands.')
|
||||
}
|
||||
if (msg.content.startsWith(`${PREFIX}`)) {
|
||||
var guildms = client.guilds.find(x => x.name === 'Musix Support')
|
||||
var channelms = guildms.channels.find(x => x.name === 'log')
|
||||
var guildId = msg.guild.id
|
||||
if (!client.voiceConnections.has(guildId)) {
|
||||
const embed = new Discord.RichEmbed()
|
||||
.setTitle(`**User:** ${msg.author.id}, ${msg.member.displayName}, ${msg.author.tag}`)
|
||||
.addField(`**Message channel:** ${msg.channel.name}`, `Client is not in a Voice channel.`)
|
||||
.addField(`**Message Content:** ${msg.content}`, `**Message Guild:** ${msg.guild.name}, ${msg.guild.id}`)
|
||||
.setColor('#b50002')
|
||||
channelms.send(embed)
|
||||
} else {
|
||||
const embed = new Discord.RichEmbed()
|
||||
.setTitle(`**User:** ${msg.author.id}, ${msg.member.displayName}, ${msg.author.tag}`)
|
||||
.addField(`**Message channel:** ${msg.channel.name}`, `**Voice channel:** ${client.voiceConnections.get(guildId).channel.name}, User Voice channel: ${msg.member.voiceChannel}`)
|
||||
.addField(`**Message Content:** ${msg.content}`, `**Message Guild:** ${msg.guild.name}, ${msg.guild.id}`)
|
||||
.setColor('#b50002')
|
||||
channelms.send(embed)
|
||||
}
|
||||
if (msg.content === `${PREFIX}ping`) {
|
||||
msg.channel.send(`My current Ping: **${Math.floor(client.ping * 10) / 10} ms**.`)
|
||||
msg.channel.send(`My current Ping: **${Math.floor(client.ws.ping * 10) / 10} ms**.`);
|
||||
return;
|
||||
}
|
||||
if (msg.content === `${PREFIX}help`) {
|
||||
const embed = new Discord.RichEmbed()
|
||||
.setTitle('Commands for Musix!')
|
||||
.addField('```-play | -p```', 'Play a song.', true)
|
||||
.addField('```-queue | -q```', 'Display the queue.', true)
|
||||
.addField('```-nowplaying | -np```', 'Display whats currently playing.', true)
|
||||
.addField('```-volume```', 'Change or check the volume.', true)
|
||||
.addField('```-pause```', 'Pause the music.', true)
|
||||
.addField('```-resume```', 'Resume the music.', true)
|
||||
.addField('```-stop```', 'Stop the music, Clear the queue and leave the current voice channel.', true)
|
||||
.addField('```-skip | -s```', 'Skip a song.', true)
|
||||
.addField('```-invite```', 'Invite Musix.', true)
|
||||
.addField('```-ping```', 'See the current ping for Musix', true)
|
||||
.addField('```-info```', 'Display info and instructions.', true)
|
||||
.addField('```-help```', 'Display the help.', true)
|
||||
.setAuthor('Musix', 'https://cdn.discordapp.com/avatars/572405135658188800/04c6f22b7600ddecfbc245dd3ec10f9f.png?size=2048')
|
||||
.setColor('#b50002')
|
||||
msg.channel.send(embed);
|
||||
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.find(x => x.name === 'DJ') ? true : false;
|
||||
const embed = new Discord.RichEmbed()
|
||||
.setTitle('**Musix instructions and info**:')
|
||||
.addField('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!', 'DJ role existance: ' + dj, true)
|
||||
.addField('If you encounter any errors with musix please report about them on the offical musix support server!', 'https://discord.gg/rvHuJtB', true)
|
||||
.addField('On errors you can do -stop to reset the queue and try again!', line, true)
|
||||
.addField('Current Ping in milliseconds', `${Math.floor(client.ping * 10) / 10} ms`, true)
|
||||
.addField('Be careful with the Volume command! Volume is not recommended to be put over 3 with user volume at 100%!', 'Volume will reset to 1 always when a new song begins!', true)
|
||||
.setAuthor('Musix', 'https://cdn.discordapp.com/avatars/572405135658188800/04c6f22b7600ddecfbc245dd3ec10f9f.png?size=2048')
|
||||
.setColor('#b50002')
|
||||
msg.channel.send(embed);
|
||||
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: https://bit.ly/2VGcuBR')
|
||||
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.find(x => x.name === 'DJ')) {
|
||||
if (msg.member.roles.find(x => x.name === 'DJ')) {
|
||||
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)
|
||||
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.voiceChannel;
|
||||
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('CONNECT')) {
|
||||
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('SPEAK')) {
|
||||
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(.*)$/)) {
|
||||
@ -117,11 +109,13 @@ client.on('message', async msg => {
|
||||
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__.
|
||||
Please provide a value to select one of the search results ranging from 1-10.
|
||||
`);
|
||||
|
||||
try {
|
||||
var response = await msg.channel.awaitMessages(msg2 => msg2.content > 0 && msg2.content < 11, {
|
||||
maxMatches: 1,
|
||||
var response = await msg.channel.awaitMessages({
|
||||
filter: msg2 => msg2.content > 0 && msg2.content < 11,
|
||||
max: 1,
|
||||
time: 10000,
|
||||
errors: ['time']
|
||||
});
|
||||
@ -129,6 +123,7 @@ Please provide a value to select one of the search results ranging from __1-10__
|
||||
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.');
|
||||
@ -137,26 +132,26 @@ Please provide a value to select one of the search results ranging from __1-10__
|
||||
return handleVideo(video, msg, voiceChannel);
|
||||
}
|
||||
} else if (command === 'skip' || command === 's') {
|
||||
if (!msg.member.voiceChannel) return msg.channel.send(':x: You are not in a voice channel!');
|
||||
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.connection.dispatcher.end('Skipped');
|
||||
serverQueue.audioPlayer.stop();
|
||||
return;
|
||||
} else if (command === 'stop') {
|
||||
if (!msg.member.voiceChannel) return msg.channel.send(':x: You are not in a voice channel!');
|
||||
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.connection.dispatcher.end('Stopped!');
|
||||
serverQueue.audioPlayer.stop();
|
||||
return;
|
||||
} else if (command === 'volume') {
|
||||
if (!msg.member.voiceChannel) return msg.channel.send(':x: You are not in a voice channel!');
|
||||
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.connection.dispatcher.setVolumeLogarithmic(args[1] / 5);
|
||||
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.');
|
||||
@ -174,41 +169,27 @@ ${serverQueue.songs.map(song => `**-** ${song.title}`).join("\n")}
|
||||
} else if (command === 'pause') {
|
||||
if (serverQueue && serverQueue.playing) {
|
||||
serverQueue.playing = false;
|
||||
serverQueue.connection.dispatcher.pause();
|
||||
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.connection.dispatcher.resume();
|
||||
serverQueue.audioPlayer.unpause();
|
||||
return msg.channel.send(':play_pause: Resumed the music for you!');
|
||||
}
|
||||
return msg.channel.send(':x: There is nothing playing.');
|
||||
} else if (msg.content === '-devstop') {
|
||||
if (msg.author.id === '360363051792203779') {
|
||||
serverQueue.songs = [];
|
||||
serverQueue.connection.dispatcher.end('Stop');
|
||||
return
|
||||
}
|
||||
} else if (msg.content.startsWith('-eval')) {
|
||||
if (msg.author.id === '360363051792203779' || msg.author.id === '384002606621655040') {
|
||||
const args = msg.content.slice(6)
|
||||
msg.channel.send(eval(args));
|
||||
return
|
||||
} else {
|
||||
msg.channel.send('The evaluation command is only avaiable for the developers of Musix!')
|
||||
}
|
||||
}
|
||||
if (msg.content === `${PREFIX}`) return;
|
||||
msg.channel.send(':x: Unknown command! Type -help for the list of commands!')
|
||||
return;
|
||||
}
|
||||
if (msg.content === `${PREFIX}`) return;
|
||||
var coms = ['-play', '-queue', '-np', '-volume', '-pause', '-resume', '-stop', '-skip', '-ping', '-q', '-nowplaying', '-p', '-s', '-devstop', '-eval'];
|
||||
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.find(x => x.name === 'DJ')) {
|
||||
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;
|
||||
}
|
||||
@ -227,13 +208,13 @@ ${serverQueue.songs.map(song => `**-** ${song.title}`).join("\n")}
|
||||
|
||||
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.voiceChannel;
|
||||
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('CONNECT')) {
|
||||
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('SPEAK')) {
|
||||
if (!permissions.has(PermissionFlagsBits.Speak)) {
|
||||
return msg.channel.send(':x: I cannot speak in this voice channel, make sure I have the proper permissions!');
|
||||
}
|
||||
|
||||
@ -277,27 +258,27 @@ Please provide a value to select one of the search results ranging from 1-10.
|
||||
return handleVideo(video, msg, voiceChannel);
|
||||
}
|
||||
} else if (command === 'skip' || command === 's') {
|
||||
if (!msg.member.voiceChannel) return msg.channel.send(':x: You are not in a voice channel!');
|
||||
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.connection.dispatcher.end('Skipped');
|
||||
serverQueue.audioPlayer.stop();
|
||||
return undefined;
|
||||
} else if (command === 'stop') {
|
||||
if (!msg.member.voiceChannel) return msg.channel.send(':x: You are not in a voice channel!');
|
||||
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.connection.dispatcher.end('Stopped!');
|
||||
serverQueue.audioPlayer.stop();
|
||||
return undefined;
|
||||
} else if (command === 'volume') {
|
||||
if (!msg.member.voiceChannel) return msg.channel.send(':x: You are not in a voice channel!');
|
||||
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.connection.dispatcher.setVolumeLogarithmic(args[1] / 5);
|
||||
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.');
|
||||
@ -315,31 +296,17 @@ ${serverQueue.songs.map(song => `**-** ${song.title}`).join("\n")}
|
||||
} else if (command === 'pause') {
|
||||
if (serverQueue && serverQueue.playing) {
|
||||
serverQueue.playing = false;
|
||||
serverQueue.connection.dispatcher.pause();
|
||||
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.connection.dispatcher.resume();
|
||||
serverQueue.audioPlayer.unpause();
|
||||
return msg.channel.send(':play_pause: Resumed the music for you!');
|
||||
}
|
||||
return msg.channel.send(':x: There is nothing playing.');
|
||||
} else if (msg.content === '-devstop') {
|
||||
if (msg.author.id === '360363051792203779') {
|
||||
serverQueue.songs = [];
|
||||
serverQueue.connection.dispatcher.end('Stop');
|
||||
return
|
||||
}
|
||||
} else if (msg.content.startsWith('-eval')) {
|
||||
if (msg.author.id === '360363051792203779' || msg.author.id === '384002606621655040') {
|
||||
const args = msg.content.slice(6)
|
||||
msg.channel.send(eval(args));
|
||||
return
|
||||
} else {
|
||||
msg.channel.send('The evaluation command is only avaiable for the developers of Musix!')
|
||||
}
|
||||
}
|
||||
}
|
||||
if (msg.content === `${PREFIX}`) {
|
||||
@ -354,7 +321,7 @@ async function handleVideo(video, msg, voiceChannel, playlist = false) {
|
||||
const serverQueue = queue.get(msg.guild.id);
|
||||
const song = {
|
||||
id: video.id,
|
||||
title: Util.escapeMarkdown(video.title),
|
||||
title: video.title,
|
||||
url: `https://www.youtube.com/watch?v=${video.id}`
|
||||
};
|
||||
if (!serverQueue) {
|
||||
@ -362,16 +329,29 @@ async function handleVideo(video, msg, voiceChannel, playlist = false) {
|
||||
textChannel: msg.channel,
|
||||
voiceChannel: voiceChannel,
|
||||
connection: null,
|
||||
audioPlayer: createAudioPlayer({
|
||||
behaviors: {
|
||||
noSubscriber: NoSubscriberBehavior.Play,
|
||||
}
|
||||
}),
|
||||
audioResource: null,
|
||||
songs: [],
|
||||
volume: 5,
|
||||
volume: 50,
|
||||
playing: true
|
||||
};
|
||||
|
||||
queue.set(msg.guild.id, queueConstruct);
|
||||
|
||||
queueConstruct.songs.push(song);
|
||||
|
||||
try {
|
||||
var connection = await voiceChannel.join();
|
||||
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) {
|
||||
@ -391,21 +371,30 @@ function play(guild, song) {
|
||||
const serverQueue = queue.get(guild.id);
|
||||
|
||||
if (!song) {
|
||||
serverQueue.voiceChannel.leave();
|
||||
serverQueue.connection.destroy();
|
||||
queue.delete(guild.id);
|
||||
return;
|
||||
}
|
||||
|
||||
const dispatcher = serverQueue.connection.playStream(ytdl(song.url, { quality: `highestaudio`, filter: 'audioonly' }))
|
||||
.on('end', reason => {
|
||||
if (reason === 'Stream is not generating quickly enough.') console.log('Song ended.');
|
||||
else console.log(reason);
|
||||
serverQueue.audioPlayer
|
||||
.on(AudioPlayerStatus.Idle, () => {
|
||||
serverQueue.songs.shift();
|
||||
serverQueue.audioPlayer.removeAllListeners();
|
||||
play(guild, serverQueue.songs[0]);
|
||||
})
|
||||
.on('error', error => console.error(error));
|
||||
dispatcher.setVolumeLogarithmic(1 / 5);
|
||||
serverQueue.volume = 1
|
||||
.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}**`);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user