2023-11-04 16:56:10 +05:00
|
|
|
const { ContextMenuCommandBuilder, ApplicationCommandType, PermissionsBitField } = require("discord.js");
|
|
|
|
const BaseCommand = require("../../base/BaseCommand");
|
|
|
|
|
|
|
|
class PlayContext extends BaseCommand {
|
|
|
|
/**
|
|
|
|
*
|
2023-11-05 16:03:23 +05:00
|
|
|
* @param {import("../../base/Client")} client
|
2023-11-04 16:56:10 +05:00
|
|
|
*/
|
|
|
|
constructor() {
|
|
|
|
super({
|
|
|
|
command: new ContextMenuCommandBuilder()
|
|
|
|
.setName("Add to Queue")
|
|
|
|
.setType(ApplicationCommandType.Message)
|
|
|
|
.setDMPermission(false),
|
|
|
|
dirname: __dirname,
|
|
|
|
ownerOnly: false,
|
|
|
|
});
|
|
|
|
}
|
2024-02-06 21:45:53 +05:00
|
|
|
|
2023-11-04 16:56:10 +05:00
|
|
|
/**
|
|
|
|
*
|
2023-11-05 16:03:23 +05:00
|
|
|
* @param {import("../../base/Client")} client
|
2023-11-04 16:56:10 +05:00
|
|
|
* @param {import("discord.js").MessageContextMenuCommandInteraction} interaction
|
|
|
|
*/
|
|
|
|
async execute(client, interaction) {
|
|
|
|
await interaction.deferReply();
|
|
|
|
|
2023-11-20 20:14:15 +05:00
|
|
|
const links = interaction.targetMessage.content.match(/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)/g);
|
|
|
|
if (!links) return interaction.error("music/play:NO_LINK", null, { edit: true });
|
|
|
|
|
|
|
|
const query = links[0],
|
2024-04-29 15:57:02 +05:00
|
|
|
voice = interaction.member.voice;
|
2023-11-04 16:56:10 +05:00
|
|
|
if (!voice) return interaction.error("music/play:NO_VOICE_CHANNEL", null, { edit: true });
|
|
|
|
|
2024-04-29 15:57:02 +05:00
|
|
|
const perms = voice.channel.permissionsFor(client.user);
|
2023-11-04 16:56:10 +05:00
|
|
|
if (!perms.has(PermissionsBitField.Flags.Connect) || !perms.has(PermissionsBitField.Flags.Speak)) return interaction.error("music/play:VOICE_CHANNEL_CONNECT", null, { edit: true });
|
|
|
|
|
2024-04-29 15:57:02 +05:00
|
|
|
const player = await client.lavalink.createPlayer({
|
|
|
|
guildId: interaction.guildId,
|
|
|
|
voiceChannelId: voice.channelId,
|
|
|
|
textChannelId: interaction.channelId,
|
|
|
|
selfDeaf: true,
|
|
|
|
selfMute: false,
|
|
|
|
volume: 100,
|
2023-11-04 16:56:10 +05:00
|
|
|
});
|
|
|
|
|
2024-04-29 15:57:02 +05:00
|
|
|
await player.connect();
|
2023-11-04 16:56:10 +05:00
|
|
|
|
2024-04-29 15:57:02 +05:00
|
|
|
const res = await player.search({ query }, interaction.member);
|
2023-11-04 16:56:10 +05:00
|
|
|
|
2024-04-29 15:57:02 +05:00
|
|
|
if (res.loadType === "playlist") await player.queue.add(res.tracks);
|
|
|
|
else if (res.loadType === "search") await player.queue.add(res.tracks[0]);
|
|
|
|
else if (res.loadType === "track") await player.queue.add(res.tracks[0]);
|
|
|
|
else console.log(res);
|
2023-11-04 16:56:10 +05:00
|
|
|
|
2024-04-29 15:57:02 +05:00
|
|
|
if (!player.playing) await player.play();
|
|
|
|
|
|
|
|
interaction.editReply({
|
|
|
|
content: interaction.translate("music/play:ADDED_QUEUE", {
|
|
|
|
songName: res.loadType === "playlist" ? res.playlist.name : `${res.tracks[0].info.title} - ${res.tracks[0].info.author}`,
|
|
|
|
}),
|
|
|
|
});
|
2023-11-04 16:56:10 +05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = PlayContext;
|