title: How to create bot command that give role to mentioned user | Discord.py
body: <p>I want to create a Discord bot command.</p>
  <p>For example, I would like to create a warning command. So the admin would enter the following command:</p>
  <pre><code>?Warn @user &quot;&lt;A warning message&gt;&quot;
  </code></pre>
  <p>The command will then check if the targeted user (<code>@user</code>) has certain roles (for example, &quot;A&quot;, &quot;B&quot;, &quot;C&quot; and &quot;D&quot;). If he doesn't have the &quot;A&quot; role he will get it, if he has A, he gets B and so on.</p>
  <p>The admin must have the &quot;Staff Team&quot; role to use the command.</p>
  <p>I tried this but it didn't work:</p>
  <pre><code>#Warning
  @bot.command(name=&quot;Warn&quot;, pass_context=True)
  @commands.has_role(&quot;Staff Team&quot;)
  async def addrole(ctx,arg):
      user = arg
      if user.role.name != &quot;Warning 1&quot; or &quot;Warning 2&quot; or &quot;Warning 3&quot;:
          role = get(user.server.roles, name=&quot;Warning 1&quot;)
          await bot.add_roles(user, role)
      elif user.role.name == &quot;Warning 1&quot;:
          role = get(user.server.roles, name=&quot;Warning 2&quot;)
          role_last = get(user.server.roles, name=&quot;Warning 1&quot;)
          await bot.add_roles(user, role)
          await bot.remove_roles(user,role_last)
      elif user.role.name == &quot;Warning 2&quot;:
          role = get(user.server.roles, name=&quot;Warning 3&quot;)
          role_last = get(user.server.roles, name=&quot;Warning 2&quot;)
          await bot.add_roles(user, role)
          await bot.remove_roles(user,role_last)
  </code></pre>
  <p>Then the bot DMs the user with text and then the message.</p>