Skip to content

Commit

Permalink
Fix track loading bug and improve search functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
appujet committed Dec 31, 2023
1 parent 19daad3 commit 463c907
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 19 deletions.
7 changes: 3 additions & 4 deletions src/commands/music/Play.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export default class Play extends Command {
vc.voice.channel,
ctx.channel
);

const res = await this.client.queue.search(query);
const embed = this.client.embed();
switch (res.loadType) {
Expand All @@ -74,7 +74,7 @@ export default class Play extends Command {
});
break;
case LoadType.TRACK: {
const track = player.buildTrack(res.data[0], ctx.author);
const track = player.buildTrack(res.data, ctx.author);
if (player.queue.length > client.config.maxQueueSize)
return await ctx.sendMessage({
embeds: [
Expand All @@ -92,7 +92,7 @@ export default class Play extends Command {
embed
.setColor(this.client.color.main)
.setDescription(
`Added [${res.data[0].info.title}](${res.data[0].info.uri}) to the queue.`
`Added [${res.data.info.title}](${res.data.info.uri}) to the queue.`
),
],
});
Expand Down Expand Up @@ -134,7 +134,6 @@ export default class Play extends Command {
break;
}
case LoadType.SEARCH: {

const track1 = player.buildTrack(res.data[0], ctx.author);
if (player.queue.length > client.config.maxQueueSize)
return await ctx.sendMessage({
Expand Down
23 changes: 10 additions & 13 deletions src/events/client/InteractionCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
} from 'discord.js';

import { Context, Event, Lavamusic } from '../../structures/index.js';
import { LoadType } from 'shoukaku';

export default class InteractionCreate extends Event {
constructor(client: Lavamusic, file: string) {
Expand Down Expand Up @@ -199,24 +200,20 @@ export default class InteractionCreate extends Event {
const res = await this.client.queue.search(song);
let songs = [];
switch (res.loadType) {
case 'LOAD_FAILED':
break;
case 'NO_MATCHES':
break;
case 'TRACK_LOADED':
break;
case 'PLAYLIST_LOADED':
break;
case 'SEARCH_RESULT':
songs.push({
name: res.tracks[0].info.title,
value: res.tracks[0].info.uri,
case LoadType.SEARCH:
if (!res.data.length) return;
res.data.slice(0, 10).forEach(x => {
songs.push({
name: x.info.title,
value: x.info.uri,
});
});
break;
default:
break;
}
interaction.respond(songs).catch(() => {});

return await interaction.respond(songs).catch(() => {});
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/utils/SetupSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ async function setupStart(
});
break;
case LoadType.TRACK:
const track = player.buildTrack(res.data[0], message.author);
const track = player.buildTrack(res.data, message.author);

if (player.queue.length > client.config.maxQueueSize) {
await message.channel
Expand Down Expand Up @@ -106,7 +106,7 @@ async function setupStart(
embed
.setColor(client.color.main)
.setDescription(
`Added [${res.data[0].info.title}](${res.data[0].info.uri}) to the queue.`
`Added [${res.data.info.title}](${res.data.info.uri}) to the queue.`
),
],
})
Expand Down

0 comments on commit 463c907

Please sign in to comment.