JaBa/commands/Music/play.c.js

69 lines
2.3 KiB
JavaScript
Raw Normal View History

2024-09-19 23:58:06 +05:00
const { ContextMenuCommandBuilder, ApplicationCommandType, PermissionsBitField, InteractionContextType, ApplicationIntegrationType } = 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
*/
constructor() {
super({
command: new ContextMenuCommandBuilder()
.setName("Add to Queue")
.setType(ApplicationCommandType.Message)
.setIntegrationTypes([ApplicationIntegrationType.GuildInstall])
.setContexts([InteractionContextType.Guild]),
dirname: __dirname,
ownerOnly: false,
});
}
/**
*
2023-11-05 16:03:23 +05:00
* @param {import("../../base/Client")} client
* @param {import("discord.js").MessageContextMenuCommandInteraction} interaction
*/
async execute(client, interaction) {
await interaction.deferReply();
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-30 12:19:44 +05:00
voice = interaction.member.voice.channel;
if (!voice) return interaction.error("music/play:NO_VOICE_CHANNEL", null, { edit: true });
2024-04-30 12:19:44 +05:00
const perms = voice.permissionsFor(client.user);
if (!perms.has(PermissionsBitField.Flags.Connect) || !perms.has(PermissionsBitField.Flags.Speak)) return interaction.error("music/play:VOICE_CHANNEL_CONNECT", null, { edit: true });
2024-04-30 12:19:44 +05:00
const searchResult = await client.player.search(query, {
requestedBy: interaction.user,
});
2024-04-30 12:19:44 +05:00
if (!searchResult.hasTracks()) {
return interaction.error("music/play:NO_RESULT", { query }, { edit: true });
} else {
await client.player.play(voice, searchResult, {
nodeOptions: {
metadata: interaction,
},
selfDeaf: true,
leaveOnEnd: false,
leaveOnStop: true,
skipOnNoStream: true,
maxSize: 100,
maxHistorySize: 50,
});
2024-04-30 12:19:44 +05:00
interaction.editReply({
content: interaction.translate("music/play:ADDED_QUEUE", {
songName: searchResult.hasPlaylist() ? searchResult.playlist.title : searchResult.tracks[0].title,
2024-11-30 22:13:23 +05:00
songURL: searchResult.hasPlaylist() ? searchResult.playlist.url : searchResult.tracks[0].url,
2024-04-30 12:19:44 +05:00
}),
});
}
}
}
module.exports = PlayContext;