After adding a play command to my music bot, my music bot is getting an Unexpected Indent error. Does anyone see why this is happening? I couldn't find any unexpected indents by the ping command, but still it gives that error. All help is appreciated.
import discord
import youtube_dl
import subprocess
import os
from discord import FFmpegPCMAudio
from discord.ext import commands
client = commands.Bot(command_prefix = '.')
@client.event
async def on_ready():
print("bot online")
@client.command()
async def play(ctx, url):
song_there = os.path.isfile("song.mp3")
try:
if song_there:
os.remove("song.mp3")
except PermissionError:
await ctx.send("There is already music playing!")
ydl_opts = {
'format': 'bestaudio/best',
'postprocessors': [{
'key': 'FFmpegExtractAudio',
'preferredcodec': 'mp3',
'preferredquality': '192',
}],
}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
ydl.download([url])
for file in os.listdir("./"):
if file.endswith(".mp3"):
os.rename(file, "song.mp3")
voice.play(discord.FFmpegPCMAudio("song.mp3"))
try:
channel = ctx.message.author.voice.channel
except:
await ctx.send(":x: Please get in a voice channel, then try again!")
return
try:
global voice
voice = await channel.connect()
await voice.connect()
@client.command()
async def ping(ctx):
await ctx.send(f"Pong! {round(client.latency * 1000)}")
client.run('TOKEN')