【发布时间】:2021-03-19 03:32:12
【问题描述】:
向我的音乐机器人添加播放命令后,我的音乐机器人出现意外缩进错误。有谁知道为什么会这样?我无法通过 ping 命令找到任何意外的缩进,但它仍然给出了该错误。感谢所有帮助。
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')
【问题讨论】:
-
错误发生在哪一行?
-
ping 命令在
@client.command()上发生
标签: python discord.py