1
0
mirror of https://github.com/musix-org/musix-oss synced 2024-11-14 16:00:17 +00:00
musix-oss/commands/playlist/play.js

70 lines
3.5 KiB
JavaScript
Raw Normal View History

2024-02-09 09:53:30 +00:00
const { PermissionFlagsBits } = require("discord.js");
const { createAudioPlayer, getVoiceConnection, joinVoiceChannel, NoSubscriberBehavior } = require("@discordjs/voice");
module.exports = {
name: 'play',
2024-02-09 09:53:30 +00:00
async execute(message, args, client, prefix) {
const serverQueue = client.queue.get(message.guild.id);
2024-02-09 09:53:30 +00:00
const voiceChannel = message.member.voice.channel;
if (!voiceChannel) return message.channel.send(':x: I\'m sorry but you need to be in a voice channel to play music!');
const permissions = voiceChannel.permissionsFor(message.client.user);
2024-02-09 09:53:30 +00:00
if (!permissions.has(PermissionFlagsBits.Connect)) {
return message.channel.send(':x: I cannot connect to your voice channel, make sure I have the proper permissions!');
}
2024-02-09 09:53:30 +00:00
if (!permissions.has(PermissionFlagsBits.Speak)) {
return message.channel.send(':x: I cannot speak in your voice channel, make sure I have the proper permissions!');
}
let songs;
if (!voiceChannel) return message.channel.send(':x: I\'m sorry but you need to be in a voice channel to play music!');
if (args[2]) {
if (client.global.db.guilds[args[2]].premium && client.global.db.playlists[args[2]].saved) {
songs = client.global.db.playlists[args[2]].songs;
} else return message.channel.send(':x: There is no queue saved for this guild!')
} else {
songs = client.global.db.playlists[message.guild.id].songs;
}
if (client.global.db.playlists[message.guild.id].saved) {
if (!serverQueue) {
const construct = {
textChannel: message.channel,
2024-02-09 09:53:30 +00:00
voiceChannel: message.member.voice.channel,
connection: null,
2024-02-09 09:53:30 +00:00
audioPlayer: createAudioPlayer({
behaviors: {
noSubscriber: NoSubscriberBehavior.Play,
}
}),
songs: [...songs],
volume: client.global.db.guilds[message.guild.id].defaultVolume,
2019-11-23 07:31:40 +00:00
playing: false,
2019-11-19 13:59:14 +00:00
looping: false,
2019-11-23 07:31:40 +00:00
paused: false,
2019-11-19 13:59:14 +00:00
votes: 0,
voters: [],
votesNeeded: null
};
client.queue.set(message.guild.id, construct);
message.channel.send(":white_check_mark: Queue set!");
try {
2024-02-09 09:53:30 +00:00
const connection =
getVoiceConnection(voiceChannel.guild.id) ??
joinVoiceChannel({
channelId: voiceChannel.id,
guildId: voiceChannel.guild.id,
adapterCreator: voiceChannel.guild.voiceAdapterCreator
});
construct.connection = connection;
client.funcs.play(message.guild, construct.songs[0], client, message, 0, false);
} catch (error) {
client.queue.delete(message.guild.id);
return message.channel.send(`:x: An error occured: ${error}`);
}
} else {
2024-02-09 09:53:30 +00:00
serverQueue.audioPlayer.stop();
serverQueue.songs = [...client.global.db.playlists[message.guild.id].songs];
message.channel.send(":white_check_mark: Queue set!");
}
} else return message.channel.send(':x: There is no queue set for this server!')
}
2024-02-09 09:53:30 +00:00
};