【问题标题】:Discord bot joining VCDiscord 机器人加入 VC
【发布时间】:2021-05-13 07:50:46
【问题描述】:

我正在尝试让我的机器人加入 VC,但它不起作用。

这是我得到的

@client.command(pass_context=True)
async def join(ctx):
    channel = ctx.author.voice.voice_channel
    await client.join_voice_channel(channel)

我不知道这是否有用,但这是我收到的错误消息:

Traceback (most recent call last):
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 85, in wrapped
    ret = await coro(*args, **kwargs)
  File "main.py", line 74, in join
    channel = ctx.author.voice.voice_channel
AttributeError: 'VoiceState' object has no attribute 'voice_channel'

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

Traceback (most recent call last):
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 939, in invoke
    await ctx.command.invoke(ctx)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 863, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 94, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'VoiceState' object has no attribute 'voice_channel'

【问题讨论】:

    标签: python discord.py


    【解决方案1】:

    如果您查看discord.VoiceState object 的文档,您会发现该属性是channel,而不是voice_channel。因此:

    @client.command(pass_context=True)
    async def join(ctx):
        channel = ctx.author.voice.channel
        await client.join_voice_channel(channel)
    

    或者只是

    @client.command(pass_context=True)
    async def join(ctx):
        await client.join_voice_channel(ctx.author.voice.channel)
    

    【讨论】:

      猜你喜欢
      • 2021-07-20
      • 2020-04-07
      • 2020-07-16
      • 2019-05-24
      • 2021-07-24
      • 2021-09-16
      • 1970-01-01
      • 2021-04-01
      • 2021-02-02
      相关资源
      最近更新 更多