在Linux上使用discord.py时出现错误"Bot"对象没有属性"join_voice_channel" [英] Using discord.py on linux I get the error 'Bot' object has no attribute 'join_voice_channel'

查看:94
本文介绍了在Linux上使用discord.py时出现错误"Bot"对象没有属性"join_voice_channel"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有问题的代码:

bot = commands.Bot(command_prefix='!')
@bot.command(pass_context=True)
    async def yt(ctx, url):
    author = ctx.message.author
    voice_channel = author.voice.channel
    vc = await bot.join_voice_channel(voice_channel)

    player = await vc.create_ytdl_player(url, before_options="-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5")
    player.start()

我收到的错误:

Traceback (most recent call last):
    File "/home/wilkins30/.local/lib/python3.7/site-packages/discord/ext/commands/core.py", line 79, in wrapped
        ret = await coro(*args, **kwargs)
    File "OverBot.py", line 286, in one
        vc = await bot.join_voice_channel(voice_channel)
AttributeError: 'Bot' object has no attribute 'join_voice_channel'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
    File "/home/wilkins30/.local/lib/python3.7/site-packages/discord/ext/commands/bot.py", line 863, in invoke
        await ctx.command.invoke(ctx)
    File "/home/wilkins30/.local/lib/python3.7/site-packages/discord/ext/commands/core.py", line 727, in invoke
        await injected(*ctx.args, **ctx.kwargs)
    File "/home/wilkins30/.local/lib/python3.7/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 'join_voice_channel'

我在Google虚拟机上的Ubuntu 19中运行python3.因此,我四处张望,只能找到线程谈论此问题但是那里的解决方案没有用.这在Windows环境中对我有用.这使我相信未加载该文件,因此我重新安装了该文件,并验证了该文件已被成功调用.我也创建了虚拟机的新实例,但也无济于事.此刻我迷路了.

I am running python3 in Ubuntu 19 on a google virtual machine. So I have looked all over and could only find this thread talking about the issue but solutions there didn't work. This worked for me in a windows environment. which lead me to believe it was opus not being loaded so I reinstalled that and verified that it was being successfully called. I have also created a fresh instance of the virtual machine to no avail as well. I'm sort of lost at the moment.

推荐答案

discord.py的较新版本(称为rewrite分支)不再具有client.join_voice_channel().这已更改为VoiceChannel.connect.请参见此处.

The newer versions of discord.py, referred to as the rewrite branch, no longer has client.join_voice_channel(). This has been changed to VoiceChannel.connect. See documentation here.

之前:

vc = await client.join_voice_channel(channel)
player = vc.create_ffmpeg_player('testing.mp3', after=lambda: print('done'))
player.start()

player.is_playing()
player.pause()
player.resume()
player.stop()
# ...

之后:

vc = await channel.connect()
vc.play(discord.FFmpegPCMAudio('testing.mp3'), after=lambda e: print('done', e))
vc.is_playing()
vc.pause()
vc.resume()
vc.stop()
# ...

由于新版本中有许多更改,因此您可能必须花费一些时间来迁移代码.如果要安装discord.py的较旧版本(称为async分支),则可以通过在Linux计算机上运行以下命令来完成安装.

As there are many changes in the new version, you may have to spend some time to migrate your code. If you would like to install the older version of discord.py, referred to as the async branch, then you can do so by running the following command on your linux machine.

sudo python3 -m pip install discord.py==0.16.12 --force-reinstall

这篇关于在Linux上使用discord.py时出现错误"Bot"对象没有属性"join_voice_channel"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆