【问题标题】:Searching in lists of lists --- get answers for each list --- just want one answer在列表列表中搜索 --- 获得每个列表的答案 --- 只想要一个答案
【发布时间】:2020-02-14 22:52:35
【问题描述】:

我想检查一下 ctx.author 是否连接到这个不和谐公会的任何语音频道。 机器人会这样做,但是对于 ctx.author 不存在的每个频道,机器人都会发送消息“您需要连接到语音频道!” 如何从机器人检查的成员列表中创建一个列表?

voice_channel_list = ctx.guild.voice_channels
for voice_channels in voice_channel_list:
    if not ctx.author in voice_channels.members:
        await ctx.send(embed=discord.Embed(color=discord.Color.red(), description=("You need to be connected to a voice-channel!")))
    elif ctx.author in voice_channels.members:
        pass #does something

【问题讨论】:

    标签: python-3.x list discord.py discord.py-rewrite


    【解决方案1】:

    您不需要遍历语音通道,Member 有一个 voice 属性,您可以直接检查。

    if ctx.author.voice is None:
        await ctx.send(embed=discord.Embed(color=discord.Color.red(), description=("You need to be connected to a voice-channel!")))
    else:
        pass #does something
    

    【讨论】:

    • 谢谢,它有效。当我在文档中搜索某些内容时,我找不到它。 ?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-23
    • 1970-01-01
    • 2022-11-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多