0

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')

2 Answers2

1

you are missing the end of your try:

 try:
    global voice
    voice = await channel.connect()
    await voice.connect()
 except:
    print("An exception occurred")

@client.command()
async def ping(ctx):
    await ctx.send(f"Pong! {round(client.latency * 1000)}")

client.run('TOKEN')
            
Jean Camargo
  • 340
  • 3
  • 17
0

You may have used tabs somewhere and actual spaces somewhere else. Have you ran it through a linter like pylint, cake, or mccabe?