【问题标题】:Command raised an exception: IndexError: Cannot choose from an empty sequence DISCORD.PY命令引发异常:IndexError:无法从空序列 DISCORD.PY 中选择
【发布时间】:2021-07-17 23:05:02
【问题描述】:
```
async def randomtokick(ctx):
    anychannel = ctx.message.author.voice.channel.id
    voice_channel = client.get_channel(anychannel)
    # Join the voice channel
    member_to_kick: discord.Member = random.choice(voice_channel.members)
    voice_client: discord.VoiceClient = await voice_channel.connect()
    await ctx.send(member_to_kick)
    await member_to_kick.edit(voice_channel = None)
```

我遇到了麻烦,因为机器人显然无法创建语音频道中的成员列表,即使我在与 5 个朋友的频道中尝试过也是如此。有人可以帮忙吗?

【问题讨论】:

    标签: python list discord.py member


    【解决方案1】:

    似乎缺少 Intent,因为代码对我来说很好。

    确保在您的应用程序的Discord Developer Portal 中打开它们。

    您可以在这里找到它们: 导航到您的应用程序 -> 机器人 -> 向下滚动 -> 打勾

    要将它们实现到您的代码中,您可以使用以下代码:

    intents = discord.Intents.all() # Imports all the Intents
    client = commands.Bot(command_prefix="YourPrefix", intents=intents) # Or whatever you use
    

    或者只是成员意图:

    intents = discord.Intents.default() # Imports the default intents
    intents.members = True
    client = discord.Client(intents=intents) # Or whatever you defined/use
    

    【讨论】:

      猜你喜欢
      • 2020-09-03
      • 2019-09-19
      • 1970-01-01
      • 2021-05-02
      • 1970-01-01
      • 2022-01-02
      • 1970-01-01
      • 1970-01-01
      • 2018-12-09
      相关资源
      最近更新 更多