feat(play.js): add source option for track search and enhance search logic
This commit is contained in:
parent
3ba230e6e9
commit
9d7ff5e7e7
@ -12,8 +12,8 @@ services:
|
||||
# Removed LAVALINK_PLUGIN_URLS environment variable
|
||||
volumes:
|
||||
- ./application.yml:/opt/Lavalink/application.yml:ro,Z
|
||||
# Mount local plugins directory into the container
|
||||
- ./plugins:/plugins:ro
|
||||
# Mount local plugins directory into the container with SELinux label
|
||||
- ./plugins:/plugins:ro,Z
|
||||
# Add healthcheck to verify Lavalink is ready
|
||||
healthcheck:
|
||||
# Use CMD-SHELL to allow environment variable expansion for the password
|
||||
|
||||
@ -9,13 +9,23 @@ module.exports = {
|
||||
.addStringOption(option =>
|
||||
option.setName('query')
|
||||
.setDescription('The URL or search term for the song/playlist')
|
||||
.setRequired(true)),
|
||||
.setRequired(true))
|
||||
.addStringOption(option =>
|
||||
option.setName('source')
|
||||
.setDescription('Specify the search source (defaults to YouTube Music)')
|
||||
.setRequired(false)
|
||||
.addChoices(
|
||||
{ name: 'YouTube Music', value: 'youtubemusic' },
|
||||
{ name: 'YouTube', value: 'youtube' },
|
||||
{ name: 'SoundCloud', value: 'soundcloud' }
|
||||
)),
|
||||
async execute(interaction, client) {
|
||||
await interaction.deferReply(); // Defer reply immediately
|
||||
|
||||
const member = interaction.member;
|
||||
const voiceChannel = member?.voice?.channel;
|
||||
const query = interaction.options.getString('query');
|
||||
const source = interaction.options.getString('source'); // Get the source option
|
||||
|
||||
// 1. Check if user is in a voice channel
|
||||
if (!voiceChannel) {
|
||||
@ -67,9 +77,32 @@ module.exports = {
|
||||
logger.info(`Moved player to voice channel ${voiceChannel.name} (${voiceChannel.id}) for play command.`);
|
||||
}
|
||||
|
||||
// 4. Search for tracks
|
||||
// 4. Determine search identifier based on query and source
|
||||
let identifier;
|
||||
const isUrl = query.startsWith('http://') || query.startsWith('https://');
|
||||
|
||||
if (isUrl) {
|
||||
identifier = query; // Use URL directly
|
||||
} else {
|
||||
// Prepend search prefix based on source or default
|
||||
switch (source) {
|
||||
case 'youtube':
|
||||
identifier = `ytsearch:${query}`;
|
||||
break;
|
||||
case 'soundcloud':
|
||||
identifier = `scsearch:${query}`;
|
||||
break;
|
||||
case 'youtubemusic':
|
||||
default: // Default to YouTube Music if source is 'youtubemusic' or not provided
|
||||
identifier = `ytmsearch:${query}`;
|
||||
break;
|
||||
}
|
||||
}
|
||||
logger.debug(`Constructed identifier: ${identifier}`);
|
||||
|
||||
// 5. Search for tracks using the constructed identifier
|
||||
const searchResults = await musicPlayer.search({ // Use the player instance from the client
|
||||
query: query,
|
||||
identifier: identifier, // Pass the constructed identifier
|
||||
requester: interaction.user
|
||||
});
|
||||
|
||||
@ -81,7 +114,7 @@ module.exports = {
|
||||
return;
|
||||
}
|
||||
|
||||
// 5. Add track(s) to queue and create response embed
|
||||
// 6. Add track(s) to queue and create response embed
|
||||
const responseEmbed = new EmbedBuilder().setColor('#0099ff');
|
||||
|
||||
// Add first track (or all tracks if it's a playlist)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user