Protect against results being None

This commit is contained in:
Parker M. 2024-12-15 22:44:38 -06:00
parent 2399336f6f
commit 78ebd84275
Signed by: parker
GPG Key ID: 505ED36FC12B5D5E
3 changed files with 12 additions and 8 deletions

View File

@ -63,7 +63,7 @@ class Play(commands.Cog):
dzsearch = f"dzsearch:{query}"
results = await player.node.get_tracks(dzsearch)
# If Deezer returned nothing
if not results.tracks or results.load_type in (
if not (results and results.tracks) or results.load_type in (
LoadType.EMPTY,
LoadType.ERROR,
):
@ -71,7 +71,9 @@ class Play(commands.Cog):
ytmsearch = f"ytmsearch:{query}"
results = await player.node.get_tracks(ytmsearch)
# If YouTube Music returned nothing
if not results.tracks or results.load_type in (
if not (
results and results.tracks
) or results.load_type in (
LoadType.EMPTY,
LoadType.ERROR,
):
@ -82,7 +84,7 @@ class Play(commands.Cog):
results = await player.node.get_tracks(query)
# If there are no results found, set results/embed to None, handled further down
if not results.tracks or results.load_type in (
if not (results and results.tracks) or results.load_type in (
LoadType.EMPTY,
LoadType.ERROR,
):

View File

@ -62,14 +62,14 @@ async def add_song_recommendations(
ytsearch = f"ytsearch:{song} by {artist} audio"
results = await player.node.get_tracks(ytsearch)
if not results.tracks or results.load_type in (
if not (results and results.tracks) or results.load_type in (
LoadType.EMPTY,
LoadType.ERROR,
):
dzsearch = f"dzsearch:{song}"
results = await player.node.get_tracks(dzsearch)
if not results.tracks or results.load_type in (
if not (results and results.tracks) or results.load_type in (
LoadType.EMPTY,
LoadType.ERROR,
):

View File

@ -30,7 +30,7 @@ class CustomAudioTrack(DeferredAudioTrack):
): # Load our 'actual' playback track using the metadata from this one.
dzsearch = f"dzsearch:{self.title} {self.author}"
results = await client.get_tracks(dzsearch)
if not results.tracks or results.load_type in (
if not (results and results.tracks) or results.load_type in (
LoadType.EMPTY,
LoadType.ERROR,
):
@ -38,14 +38,16 @@ class CustomAudioTrack(DeferredAudioTrack):
ytmsearch = f"ytmsearch:{self.title} {self.author}"
results = await client.get_tracks(ytmsearch)
if not results.tracks or results.load_type in (
if not (results and results.tracks) or results.load_type in (
LoadType.EMPTY,
LoadType.ERROR,
):
ytsearch = f"ytsearch:{self.title} {self.author} audio"
results = await client.get_tracks(ytsearch)
if not results.tracks or results.load_type in (
if not (
results and results.tracks
) or results.load_type in (
LoadType.EMPTY,
LoadType.ERROR,
):