REF: Better Layout of Modules
FEAT: Added Code Needed to do Twitch
This commit is contained in:
parent
965a7d5637
commit
4f3bc7669d
@ -10,3 +10,6 @@ SPOTIPY_CLIENT_SECRET = os.getenv("SPOTIPY_CLIENT_SECRET")
|
||||
SPOTIPY_REDIRECT_URI = os.getenv("SPOTIPY_REDIRECT_URI")
|
||||
PLEX_URL = os.getenv("PLEX_URL")
|
||||
PLEX_TOKEN = os.getenv("PLEX_TOKEN")
|
||||
TWITCH_CLIENT_ID = os.getenv("TWITCH_CLIENT_ID")
|
||||
TWITCH_CLIENT_SECRET = os.getenv("TWITCH_CLIENT_SECRET")
|
||||
TWITCH_CHANNEL = os.getenv("TWITCH_CHANNEL")
|
||||
|
7
main.py
7
main.py
@ -8,12 +8,11 @@ class Selena(discord.Client):
|
||||
self.tree = discord.app_commands.CommandTree(self)
|
||||
|
||||
async def setup_hook(self):
|
||||
guild = discord.Object(id=config.DISCORD_GUILD_ID)
|
||||
modules = ["modules.spotify_module", "modules.plex_module"]
|
||||
modules = ["modules.media.spotify_module",
|
||||
"modules.media.plex_module"]
|
||||
for module in modules:
|
||||
await self.load_extension(module)
|
||||
# self.tree.copy_global_to(guild=guild)
|
||||
await self.tree.sync(guild=guild)
|
||||
await self.tree.sync()
|
||||
|
||||
async def load_extension(self, name):
|
||||
module = __import__(name, fromlist=["setup"])
|
||||
|
@ -74,6 +74,37 @@ class SpotifyModule:
|
||||
except Exception as e:
|
||||
await interaction.followup.send(f"An error occurred: {e}")
|
||||
|
||||
@app_commands.command(
|
||||
name="play_playlist",
|
||||
description="Play a playlist by searching for it"
|
||||
)
|
||||
async def play_playlist(interaction: discord.Interaction, query: str):
|
||||
await interaction.response.defer()
|
||||
try:
|
||||
results = self.sp.search(q=query, limit=1, type="playlist")
|
||||
if not results["playlists"]["items"]:
|
||||
await interaction.followup.send("No results found")
|
||||
return
|
||||
|
||||
playlist = results["playlists"]["items"][0]
|
||||
uri = playlist["uri"]
|
||||
|
||||
devices = self.sp.devices()
|
||||
if not devices["devices"]:
|
||||
await interaction.followup.send(
|
||||
"No active devices found. Please open Spotify on a "
|
||||
"device."
|
||||
)
|
||||
return
|
||||
|
||||
self.sp.start_playback(context_uri=uri)
|
||||
await interaction.followup.send(
|
||||
f"Now playing playlist: {playlist['name']} by "
|
||||
f"{playlist['owner']['display_name']}"
|
||||
)
|
||||
except Exception as e:
|
||||
await interaction.followup.send(f"An error occurred: {e}")
|
||||
|
||||
@app_commands.command(
|
||||
name="pause", description="Pause the currently playing track"
|
||||
)
|
||||
@ -122,6 +153,7 @@ class SpotifyModule:
|
||||
|
||||
self.bot.tree.add_command(current_track)
|
||||
self.bot.tree.add_command(play_track)
|
||||
self.bot.tree.add_command(play_playlist)
|
||||
self.bot.tree.add_command(pause)
|
||||
self.bot.tree.add_command(resume)
|
||||
self.bot.tree.add_command(next_track)
|
Loading…
x
Reference in New Issue
Block a user