【发布时间】:2021-04-09 16:45:02
【问题描述】:
我尝试使用 youtube_dl 创建一个播放音乐的命令。我的 discord.py 版本是 1.5.1
这是我的代码:
@bot.command()
async def play(ctx, url: str):
await ctx.message.delete()
song_there = os.path.isfile("song.mp3")
try:
if song_there:
os.remove("song.mp3")
except PermissionError:
await ctx.send("Wait for the current playing music end or use the 'stop' command")
return
await ctx.send("Getting everything ready, playing audio soon")
print("Someone wants to play music let me get that ready for them...")
voice = get(bot.voice_clients, guild=ctx.guild)
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"))
voice.volume = 100
voice.is_playing()
但是我得到了这个输出:
TypeError: request() got an unexpected keyword argument 'guild'
错误在这一行voice = get(bot.voice_clients, guild=ctx.guild)
提前致谢
【问题讨论】:
标签: python discord discord.py discord.py-rewrite