有什么办法可以制作一个可以提供角色的机器人

Is there any way I can make a bot that can give roles

就像标题一样,我需要制作一个可以按特定格式分配角色的机器人。我已经设置了机器人和所有东西,它可以执行基本命令。我想要它做的一个例子如下:

User: !!roles
Bot:  Who do you want to give roles to?
User: User1 User2 User3 User4     (etc...)
Bot: What role do you want to give them?
User: Admin               (Or rank1 rank2 etc...)

这是我创建的代码(一团糟):

@client.command(name="roles")
async def _roles(ctx):
  if ctx.message.author.server_permissions.administrator:
    global times_used
    times_used = times_used + 1
    await ctx.send(f"type who you want to give roles to, type cancel to cancel:")

    # This will make sure that the response will only be registered if the following
    # conditions are met:
    def check(msg):
      return msg.author == ctx.author and msg.channel == ctx.channel

    try:
      msg = await client.wait_for("message", check=check, timeout=120) # 120 seconds to reply

    except asyncio.TimeoutError:
      await ctx.send("Sorry, you didn't reply in time!")

    if(msg.content == "cancel"):
      return
    else:
      role = get(message.server.roles, name=role_to_give)
      content_split = msg.content.split()
      for user in content_split:
        await client.add_roles(user, role)

  else:
      msg = "You're an average joe {0.author.mention}".format(ctx.message)  
      await client.send_message(ctx.message.channel, msg)
      return

我正在使用 python 3.8.3,如有任何帮助,我们将不胜感激!

您需要 wait_for 的两个实例,一个读取用户列表,另一个读取角色列表。 add_role 也是在 Member/User 对象上完成的。 对于将 class 的多个实例作为参数,您会发现 Greedy 很有用。