!roster command for outputting the list of current updaters in Libcord
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

45 行
1.4 KiB

  1. from redbot.core import commands
  2. from redbot.core.bot import Red
  3. from redbot.core.utils.chat_formatting import pagify
  4. import discord
  5. async def has_update_command_role(ctx):
  6. """
  7. Checks if the user has the update command role.
  8. """
  9. if ctx.guild is None:
  10. return False
  11. uc_role = discord.utils.get(ctx.guild.roles, name="Update Command")
  12. reporter_role = discord.utils.get(ctx.guild.roles, name="Reporter")
  13. if uc_role is None:
  14. return False
  15. return (uc_role in ctx.author.roles) or (reporter_role in ctx.author.roles)
  16. class LibcordRoster(commands.Cog):
  17. def __init__(self, bot: Red, *args, **kwargs):
  18. super().__init__(*args, **kwargs)
  19. self.bot = bot
  20. def cog_unload(self):
  21. pass
  22. @commands.command()
  23. @commands.check(has_update_command_role)
  24. async def roster(self, ctx: commands.Context):
  25. """Get the names of all users with the Updating role"""
  26. guild = ctx.guild
  27. role = discord.utils.get(guild.roles, name="Updating")
  28. members = [member for member in guild.members if role in member.roles]
  29. out = ""
  30. for member in members:
  31. if member.nick:
  32. out += f"{member.nick}\n"
  33. elif member.name:
  34. out += f"{member.name}\n"
  35. out = '\n'.join(sorted(out.splitlines(), key=str.lower))
  36. for page in pagify(out):
  37. await ctx.send("```\n" + page + "```")