Command raised an exception: IndexError: Cannot choose from an empty sequence DISCORD.PY
Command raised an exception: IndexError: Cannot choose from an empty sequence DISCORD.PY
```
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 个朋友的频道中尝试过也是如此。有人可以帮忙吗?
似乎缺少 Intents,因为代码对我来说工作正常。
确保在 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
```
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 个朋友的频道中尝试过也是如此。有人可以帮忙吗?
似乎缺少 Intents,因为代码对我来说工作正常。
确保在 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