【问题标题】:guild.text_channels only returns 1 channel instead of all channelsguild.text_channels 只返回 1 个频道而不是所有频道
【发布时间】:2020-02-28 05:54:45
【问题描述】:

当我使用 ctx.guild.text_channels 并打印我分配给它的变量时,它只显示不和谐服务器中的第一个文本通道

如果我必须使用某种循环但找不到任何循环,我已经尝试查看不和谐重写的文档。所以我相信我做错了什么。

只是为了告诉你们我有会员:discord.Member,因为我稍后会使用它。

Discord 公会频道列表:http://prntscr.com/prdcaa

@bot.command(pass_contect=True)
async def check_client_channel(ctx, member: discord.Member):
    channels = discord.utils.get(ctx.guild.text_channels)
    print(channels)
    channel_name = member.display_name + "-" + member.discriminator

我执行函数时的结果:

test2

预期结果:(类似于)

["test2", "general", "test", "testing-2611"]

【问题讨论】:

  • 来自文档 - A helper that returns the first element in the iterable that meets all the traits passed in attrs。这意味着utils.get 只会返回一个值。 ctx.guild.text_channels 已经是一个包含文本通道的可迭代对象,因此您无需使用 .get

标签: python discord discord.py-rewrite


【解决方案1】:

试试channels = [discord.utils.get(ctx.guild.text_channels)]pass_contect=True 也有一个错字(或 idk python)。我觉得应该是pass_context=True

【讨论】:

    【解决方案2】:

    这个是rewrite/master版本

    
    @bot.command()
    async def on(msg):
        chans=msg.guild.text_channels
        print([i.name for i in chans])
    
    

    【讨论】:

      猜你喜欢
      • 2020-10-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-02
      • 2019-07-11
      • 2019-11-10
      • 2021-12-06
      • 2022-01-12
      相关资源
      最近更新 更多