title: discord.py how add role to member
body: <p>I cannot solve the problem. How to add a role to the user who called the !role command.
  Please, help.</p>
  <pre class="lang-py prettyprint-override"><code>import discord
  from discord.ext import commands
  from apex_legends import ApexLegends
  </code></pre>
  <pre class="lang-py prettyprint-override"><code>intents = discord.Intents.default()
  intents.members = True
  client = commands.Bot(command_prefix='!', intents = intents)
  
  @client.command()
  async def rank(ctx, user_name,):
      rank = get_apex_rank(user_name) #return str role name
      await ctx.send(f&quot;{rank}&quot;)# successfully receiving a response from the bot 
      member = ctx.author
      role = discord.utils.get(member.guild.roles, name=rank)
      await member.add_roles(role)
  </code></pre>
  <pre><code>discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'User' object has no attribute 'guild'
  </code></pre>
  <pre class="lang-py prettyprint-override"><code>def get_apex_rank(name):
      try:
          player = apex.player(name)
          a = player.__dict__
          return a['_data']['metadata'][&quot;rankName&quot;]
      except:
          return &quot;Wrong name&quot;
  </code></pre>