【问题标题】:Discord channel members only returns one member?Discord 频道会员只返回一名会员?
【发布时间】:2021-01-27 12:53:48
【问题描述】:

我正在测试服务器上运行机器人。当前频道中有 3 个成员(member_count 为 3),但它只返回一个成员。该成员是 Bot。

代码:


import discord
from discord.ext import commands

TOKEN = "<Token>"
CHANNEL_ID = 1234

@client.event
async def on_ready():
    channel = client.get_channel(CHANNEL_ID)
    print(channel.members)

client.run(TOKEN)

输出:

[<Member id=<> name='Bot_name' discriminator='Bot_discriminator' bot=True nick=None guild=<Guild id=<> name="Server_name" shard_id=None chunked=False member_count=3>>]

【问题讨论】:

标签: python discord.py


【解决方案1】:

尝试循环遍历channel.members
例如:

for i in channel.members:
 print(i.id)

【讨论】:

  • 嗨!这也只会返回我的机器人的 ID。
【解决方案2】:

您可以将其制成一个命令,该命令将获取该命令使用的频道中的成员数。

文档:

@bot.command()
async def count(ctx):
    print(len(ctx.channel.members)) # to show how many are there
    for member in ctx.channel.members:
        print(member.name)

【讨论】:

    【解决方案3】:

    Discord 最近更改了他们的机器人 api,这可能是您所看到的原因。

    好消息是修复相当简单,您只需在机器人的管理页面中启用“服务器成员意图”。关注the instructions here

    【讨论】:

      猜你喜欢
      • 2021-01-22
      • 2018-12-03
      • 2021-09-04
      • 1970-01-01
      • 2022-09-25
      • 2021-02-27
      • 2021-03-05
      • 1970-01-01
      • 2021-06-06
      相关资源
      最近更新 更多