I tried using the following code but it didn’t work.
JavaScript
x
5
1
@bot.command()
2
async def avatar(ctx,*, avamember):
3
user = bot.get_user(avamember)
4
await ctx.send(f"{user.avatar_url}")
5
Edit: For anyone that had a similar problem, while not mentioned in the docs, discord.Member can take user ids aside from @username so there isn’t any need for a complicated way.
Advertisement
Answer
I’m presuming you’re Tagging the user with @UserNameHere in discord. It’s much easier to take that input as a member Object :)
You also don’t need to wrap the url in quotes.
This code is if it is in a cog:
JavaScript
1
5
1
@commands.command()
2
async def avatar(self, ctx, *, avamember : discord.Member=None):
3
userAvatarUrl = avamember.avatar_url
4
await ctx.send(userAvatarUrl)
5
This code is if it is in the main bot.py file:
JavaScript
1
5
1
@bot.command()
2
async def avatar(ctx, *, avamember : discord.Member=None):
3
userAvatarUrl = avamember.avatar_url
4
await ctx.send(userAvatarUrl)
5