【问题标题】:Counting members with certain roles in discord.py在 discord.py 中计算具有特定角色的成员
【发布时间】:2021-03-17 03:29:02
【问题描述】:

所以我正在尝试创建一个命令来显示使用某个角色的成员的数量(该角色应该由消息定义(所以我不必为 1 个角色制作脚本,使用 roleid) ) 但它似乎根本不起作用,所以也许有一些建议?我是编程新手,使用 API 并没有给我太多好处 :) 理想的设置是有一个系统,它可以显示有关所有角色的信息,或者只显示 1 个角色,您可以通过消息定义。

所以我尝试的是:

async def rolescount(ctx):
  def check(message):
    return message.author == ctx.author and message.channel == ctx.channel
    
  await ctx.send('Waiting for role')
  
  message = await bot.wait_for('message', check=check)
  role = ctx.get_role_name(message.content)
  role = ctx.guild.get_role(role.content)
  await ctx.send(len(role.members))

但是好像不行,当bot在等待消息的时候,他没有任何回应,只是坐在那里,我做错了什么?

也试过找类似的案例,真的没什么,先谢谢了!

【问题讨论】:

    标签: discord.py


    【解决方案1】:

    试试这个:

    
    @bot.command()
    async def rolescount(ctx, role: discord.Role):
        await ctx.send(len(role.members))
    

    现在你可以像这样使用这个命令了:<PREXIX>rolescount @ROLE 如果您想打印所有具有此角色的成员,请执行以下操作:

    @bot.command()
    async def rolescount(ctx, role: discord.Role):
        for member in role.members:
            print(f"{member.name}#{member.discriminator}")
    

    【讨论】:

      猜你喜欢
      • 2021-06-29
      • 2021-02-17
      • 2021-07-01
      • 2020-12-05
      • 1970-01-01
      • 1970-01-01
      • 2021-10-16
      • 2020-07-08
      • 2020-12-19
      相关资源
      最近更新 更多