Skip to content

Commit

Permalink
fix: crash related to Spotify lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
zapteryx committed Oct 18, 2022
1 parent 680cb46 commit fe88c29
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/commands/play.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type {
import { checks } from '#src/lib/util/constants.js';
import { settings } from '#src/lib/util/settings.js';
import { getGuildLocaleString, getLocaleString } from '#src/lib/util/util.js';
import type { Item } from '@lavaclient/spotify';
import { SpotifyItemType } from '@lavaclient/spotify';
import type {
ChatInputCommandInteraction,
Expand Down Expand Up @@ -113,16 +114,14 @@ export default {
return;
}
await interaction.deferReply();
const query = interaction.options.getString('query'),
const query = interaction.options
.getString('query')
.replace('embed/', ''),
insert = interaction.options.getBoolean('insert');
let tracks = [],
msg = '',
extras = [];
if (
interaction.client.music.spotify.isSpotifyUrl(
query.replace('embed/', ''),
)
) {
if (interaction.client.music.spotify.isSpotifyUrl(query)) {
if (
!settings.features.spotify.enabled ||
!settings.features.spotify.client_id ||
Expand All @@ -134,9 +133,16 @@ export default {
);
return;
}
const item = await interaction.client.music.spotify.load(
query.replace('embed/', ''),
);
let item: Item;
try {
item = await interaction.client.music.spotify.load(query);
} catch (err) {
await interaction.replyHandler.locale(
'CMD.PLAY.RESPONSE.NO_RESULTS.SPOTIFY',
{ type: 'error' },
);
return;
}
switch (item?.type) {
case SpotifyItemType.Track: {
const track = await item.resolveYoutubeTrack();
Expand Down

0 comments on commit fe88c29

Please sign in to comment.