【问题标题】:How to make a list of all voice channels for discord.py bot如何为 discord.py bot 列出所有语音通道
【发布时间】:2019-08-02 05:26:22
【问题描述】:

我需要服务器中所有语音通道的列表,我在文档中看到了 get_all_channels,但我不确定如何实现它。

https://discordpy.readthedocs.io/en/latest/api.html?highlight=voice%20channels

【问题讨论】:

    标签: python bots discord discord.py


    【解决方案1】:

    从1.0.0+版本开始,您可以通过discord.Guild.voice_channels获取所有语音通道:

    @client.command()
    async def channels(ctx):
        voice_channel_list = ctx.guild.voice_channels
        # ...
    

    【讨论】:

      【解决方案2】:

      循环通过Server.channels 检查Channel.typeChannelType.voice

      from discord import ChannelType
      
      @bot.command(pass_context=True)
      async def voicechannels(ctx):
          channels = (c.name for c in ctx.message.server.channels if c.type==ChannelType.voice)
          await bot.say("\n".join(channels))
      

      【讨论】:

        猜你喜欢
        • 2019-09-18
        • 2021-08-05
        • 2020-12-06
        • 1970-01-01
        • 2021-08-26
        • 2021-01-07
        • 2021-12-11
        • 2021-04-15
        • 1970-01-01
        相关资源
        最近更新 更多