【问题标题】:How to fix discord music bot attribute如何修复不和谐的音乐机器人属性
【发布时间】:2021-08-08 06:04:10
【问题描述】:

错误:

discord.ext.commands.errors.CommandInvokeError:命令引发异常:AttributeError:“VoiceState”对象没有属性“voice_channel”

代码:

from discord.ext import commands
import random
import youtube_dl

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

【问题讨论】:

    标签: python discord


    【解决方案1】:

    尝试使用voice.channel 而不是voice.voice_channel

    from discord.ext import commands
    import random
    import youtube_dl
    
    @client.command(pass_context=True)
    async def join(ctx):
      channel = ctx.message.author.voice.channel
      await client.join_voice_channel(channel)
    

    client.join_voice_channel 也不起作用。使用这样的东西:

    from discord.ext import commands
    from discord.utils import get
    import random
    import youtube_dl
        
    @client.command(pass_context=True)
    async def join(ctx):
        chn = ctx.message.author.voice.channel
        if not chn:
            await ctx.send("Error: Connect to voice channel")
            return
        voice = get(bot.voice_clients, guild=ctx.guild)
        if voice and voice.is_connected():
            await voice.move_to(chn)
    

    【讨论】:

      猜你喜欢
      • 2020-09-23
      • 2019-04-04
      • 2020-06-20
      • 2019-02-26
      • 2018-08-24
      • 2019-08-03
      • 2021-11-24
      • 1970-01-01
      • 2021-11-03
      相关资源
      最近更新 更多