在 linux 上使用 discord.py 我得到错误 'Bot' object has no attribute 'join_voice_channel' [英] Using discord.py on linux I get the error 'Bot' object has no attribute 'join_voice_channel'

查看:29
本文介绍了在 linux 上使用 discord.py 我得到错误 'Bot' object has no attribute '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'

我在谷歌虚拟机上的 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' object has no attribute 'join_voice_channel'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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