im试图使用youtube_dl使Discord机器人将youtube的音频播放到vc。在聊天中运行play [youtube url]时出现一些错误
Traceback (most recent call last):
File "C:\Users\User\AppData\Local\Programs\Python\Python37-32\lib\site-packages\discord\ext\commands\core.py", line 79, in wrapped
ret = await coro(*args, **kwargs)
File "C:\Users\User\AppData\Local\Programs\Python\Python37-32\bot1.py", line 169, in play
voice_client = client.voice_client_in(server)
AttributeError: 'Bot' object has no attribute 'voice_client_in'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\User\AppData\Local\Programs\Python\Python37-32\lib\site-packages\discord\ext\commands\bot.py", line 863, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\User\AppData\Local\Programs\Python\Python37-32\lib\site-packages\discord\ext\commands\core.py", line 728, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Users\User\AppData\Local\Programs\Python\Python37-32\lib\site-packages\discord\ext\commands\core.py", line 88, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'Bot' object has no attribute 'voice_client_in'
这是我为使机器人加入VC而编写的代码,它可以正确加入,但是在播放某些内容时,没有任何响应,并且给出了上面显示的错误。
@client.command()
async def join(ctx):
channel = ctx.author.voice.channel
await channel.connect()
@client.command()
async def leave(ctx):
await ctx.voice_client.disconnect()
@client.command(pass_context=True)
async def play(ctx, url):
server = ctx.message.guild
voice_client = client.voice_client_in(server)
players = await channel.connect_ytdl_player(url)
players[server.id] = player
player.start()
我猜这是由于不和谐的重写api造成的,可以在此处进行更改以便正确运行。任何帮助将不胜感激
答案 0 :(得分:0)
请使用discord.Guild.voice_client而不是使用voice_client_in(我假设这是来自预重写),如果适用,它将返回与该服务器/行会关联的voice_client。
所以您将拥有类似的东西:
voice_client = ctx.guild.voice_client
编辑说明:如果您使用的是重写,则装饰器上不再需要pass_context。如果您不使用重写,则强烈建议进行更新,因为另一个分支不再被更新。