Jamlandia
Jamlandia

Reputation: 5

How do I grab and send the profile picture of anyone on my server using a discord.py bot?

I've been working on a discord bot using discord.py for the past few days. Now i'm trying to implement a command that displays the profile picture of anyone you mention on the server.

The problem is I can only get it to give the profile picture of the person who sends the command. I can't get it to take in a second parameter without encountering errors or the bot ignoring it.

@client.command(aliases=['getprofilepic','getprofilepicture','pfp','profilepic','profilepicture','avatar'])
async def getpfp(ctx):
    await ctx.send(ctx.author.avatar_url)

The code above is a command to send the profile picture of the user who sends the command into the chat. It ignores any extra parameters and thus can not display the profile picture of anyone else except the sender.

Changing getpfp(ctx): to getpfp(ctx, usernamepfp): and ctx.send(ctx.author.avatar_url) to ctx.send(ctx.usernamepfp.avatar_url) didn't work.

I also tried ctx.send(usernamepfp.avatar_url).

How would I implement the command such that when one types .getpfp @username in the chat it would send the profile picture of @username and not the sender?

Upvotes: 0

Views: 6110

Answers (1)

InsertCheesyLine
InsertCheesyLine

Reputation: 1373

from discord import Member

@bot.command()
async def getpfp(ctx, member: Member = None):
 if not member:
  member = ctx.author
 await ctx.send(member.avatar_url)

You can use getpfp to display the avatar of user by passing 1) Mention/Tag 2) Display name/ Nick Name 3) Discord ID. eg .getpfp @Someone

Upvotes: 1

Related Questions