dolfies / discord.py-self

A fork of the popular discord.py for user accounts.
https://discordpy-self.rtfd.io/en/latest/
MIT License
717 stars 163 forks source link

[BUG] Getting user info in a DM doesn't work #46

Closed ghost closed 3 years ago

ghost commented 3 years ago

Summary

A simple summary of the bug.

Whenever I try to get the avatar_url of a user in a DM it returns the default discord profile picture, and if I try to get the name of the user it returns 'None'

Reproduction Steps

How did you make it happen?
  1. Go into a DM
  2. Run:
  3. Try to get a user's name/avatar

Code

Relevant code that shows the bug.
@Client.command()
async def test(Context, User: discord.User):
    print(User.avatar_url)
    print(User.name)

Expected Results

What is supposed to happen?

Returns the user's correct tag and avatar

Actual Results

What is currently happening?

Returns 'None' as the user's name and the default discord profile picture as their avatar

System Info

Run python -m discord --version and paste the information below.
- Python v3.9.5-final
- discord.py v1.8.1-final
- aiohttp v3.7.4.post0
- system info: Windows 10 10.0.19041

Checklist

Let's make sure this issue is valid!

Additional Information

Put any extra context, weird configurations, or other important info here.
Ceres445 commented 3 years ago

How are you using the command? !test @user?

caiocinel commented 3 years ago

I also noticed this problem, but I managed to solve it by getting the context information.

*This is far from ideal, but it worked until the next release came out, which should probably fix the problem.

https://github.com/caiocinel/Selfium/blob/main/app/events/client/commands/avatar.py

ghost commented 3 years ago

How are you using the command? !test @user?

Yes

ghost commented 3 years ago

I also noticed this problem, but I managed to solve it by getting the context information.

*This is far from ideal, but it worked until the next release came out, which should probably fix the problem.

https://github.com/caiocinel/Selfium/blob/main/app/events/client/commands/avatar.py

OK, thanks, I'll try this out

ghost commented 3 years ago

I also noticed this problem, but I managed to solve it by getting the context information.

*This is far from ideal, but it worked until the next release came out, which should probably fix the problem.

https://github.com/caiocinel/Selfium/blob/main/app/events/client/commands/avatar.py

Your way still isn't working for me My command:

@Client.command()
async def test123(ctx):

    async def byMember(member):
        if hasattr(member, 'id'):
            targetId = int(member.id)
        else:
            targetId = member.author.id

        return await byID(targetId)

    async def byID(id):
        target = await Client.fetch_user(int(id))
        return target

    if(ctx.message.mentions):
        target = ctx.message.mentions
    else:
        target = ctx.args

    try:
        for t in range(len(target)):
            memberFetch = await byMember(target[t])
            embed = discord.Embed(colour=discord.Colour.green())
            embed.set_author(name=f"🖼️ Here's {memberFetch.display_name} profile picture", url=f"{memberFetch.avatar_url.BASE + memberFetch.avatar_url._url}")
            embed.set_image(url=memberFetch.avatar_url.BASE + memberFetch.avatar_url._url)
            await ctx.send(embed=embed)
    except:
        print('not found')

Hope it's not a stupid mistake on my part

caiocinel commented 3 years ago

Your code worked perfectly in my tests (although it might be better structured), set some breakpoints and see what happens.

image

ghost commented 3 years ago

Your code worked perfectly in my tests (although it might be better structured), set some breakpoints and see what happens.

image

Using the development version fixed it for me. Works using your method and the normal method. Thanks for the help