some changes to how disconnecting and data works
This commit is contained in:
parent
3d73b06b12
commit
7a70bc2c23
45
bot.py
45
bot.py
@ -3,7 +3,7 @@ import os
|
||||
import requests
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
from discord import NotFound, app_commands
|
||||
from discord import DiscordException, NotFound, app_commands
|
||||
from dotenv import load_dotenv
|
||||
|
||||
|
||||
@ -103,18 +103,23 @@ async def play(interaction: discord.Interaction, title: str):
|
||||
voice_client = interaction.guild.voice_client # Enables the voice feature for the bot
|
||||
# If its not connected to a voice channel, then connect to the channel that the caller is in
|
||||
if voice_client is None:
|
||||
voice_client = await channel.connect()
|
||||
voice_client = await user_channel.connect()
|
||||
|
||||
# If the caller is in a channel that its not already in, move there
|
||||
elif voice_client.channel != channel:
|
||||
await voice_client.move_to(channel)
|
||||
voice_client = await channel.connect()
|
||||
elif voice_client.channel != user_channel:
|
||||
await voice_client.move_to(user_channel)
|
||||
voice_client = await user_channel.connect()
|
||||
|
||||
#Pause the music that is currently playing
|
||||
if voice_client.is_playing():
|
||||
voice_client.stop()
|
||||
except NotFound as e:
|
||||
await interaction.response.send_message("You must be in a voice channel.")
|
||||
except discord.errors.NotFound as e:
|
||||
print(f"Error: {e}")
|
||||
await interaction.followup.send("Nope! Not in a voice!")
|
||||
return
|
||||
except discord.errors.Forbidden as e:
|
||||
print(f"Error: {e}")
|
||||
await interaction.followup.send("Not allowed in here!")
|
||||
return
|
||||
|
||||
|
||||
@ -191,21 +196,37 @@ async def search(interaction: discord.Interaction, title: str):
|
||||
|
||||
# Get the data
|
||||
data = await make_request(url, params, interaction)
|
||||
await interaction.followup.send("stuff")
|
||||
print(data)
|
||||
|
||||
return
|
||||
if not data:
|
||||
await interaction.followup.send(f"No song found matching `{title}`.")
|
||||
return
|
||||
|
||||
songs = data.get("Items", [])
|
||||
lines = []
|
||||
print(data.get("Items", []))
|
||||
return
|
||||
|
||||
for song in songs:
|
||||
title = song.get("Name")
|
||||
artist = song.get("AlbumArtist", ["Unknown Artist"])
|
||||
lines.append(f"**{title}** by *{artist}*")
|
||||
await interaction.followup.send("\n".join(lines))
|
||||
# for song in songs:
|
||||
# title = song.get("Title")
|
||||
# artist = song.get("AlbumArtist", ["Unknown Artist"])
|
||||
# lines.append(f"**{title}** by *{artist}*")
|
||||
# await interaction.followup.send("\n".join(lines))
|
||||
# end search -----
|
||||
|
||||
|
||||
# Disconnect command!
|
||||
# Disconnects from the voice channel
|
||||
@bot.tree.command(name="disconnect", description="Disconnects from current voice channel!")
|
||||
async def disconnect(interaction: discord.Interaction):
|
||||
if interaction.guild.voice_client == None:
|
||||
await interaction.response.send_message("I am not in any voice channel!")
|
||||
return
|
||||
await interaction.guild.voice_client.disconnect()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user