Pycord-Development / pycord

Pycord is a modern, easy to use, feature-rich, and async ready API wrapper for Discord written in Python
https://docs.pycord.dev
MIT License
2.74k stars 461 forks source link

User status affects banner retrieval #244

Closed TjMatBTW closed 3 years ago

TjMatBTW commented 3 years ago

Summary

If the user is offline, the banner retrieval is impossible

Reproduction Steps

I coded a simple banner retrieval code, similar to the avatar command. I made a check to check if the user had actually a banner and it works. However, if the desired user is offline, it will display as user that doesn't have a banner.

Minimal Reproducible Code

@commands.command(aliases=['ba'])
async def banner(self, ctx, user:discord.User = None):

        if user is None:
            user = ctx.author

        if user.banner:
            em = discord.Embed(title=user, timestamp=ctx.message.created_at)
            em.set_image(url=user.banner.url)
            em.set_footer(text=f'Requested by {ctx.author}', icon_url=ctx.author.avatar.url)
            await ctx.send(embed=em)
        else:
            await ctx.send('That user does not have a banner.')

# Note: Somehow Indents broke, but they're good in my code

Expected Results

I expected it to always send the banner image if the desired user had one, and if the user didn't, it would send That user does not have a banner.

Actual Results

If the user is offline, it would always display the error That user does not have a banner.

Intents

Presence & Server Members.

System Information

Traceback (most recent call last): File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 197, in _run_module_as_main return _run_code(code, main_globals, None, File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 87, in _run_code exec(code, run_globals) File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\discord__main.py", line 300, in main() File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\discord__main.py", line 297, in main args.func(parser, args) File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\discord__main__.py", line 52, in core show_version() File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\discord__main.py", line 41, in show_version pkg = pkg_resources.get_distribution('pycord') File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\pkg_resources\init__.py", line 466, in get_distribution dist = get_provider(dist) File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\pkg_resources\init__.py", line 342, in get_provider return working_set.find(moduleOrReq) or require(str(moduleOrReq))[0] File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\pkg_resources\init.py", line 886, in require needed = self.resolve(parse_requirements(requirements)) File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\pkg_resources\init__.py", line 772, in resolve raise DistributionNotFound(req, requirers) pkg_resources.DistributionNotFound: The 'pycord' distribution was not found and is required by the application

Checklist

Additional Context

No response

Dorukyum commented 3 years ago

As stated in the docs, banners are only available via bot.fetch_user.

TjMatBTW commented 3 years ago

Will that be changed in the future?

BobDotCom commented 3 years ago

That's likely a discord limitation so no.

BobDotCom commented 3 years ago

Just use fetch_user as a fallback if the user doesnt have a banner the first time.

TjMatBTW commented 3 years ago

Just use fetch_user as a fallback if the user doesnt have a banner the first time.

I did that, it's actually the only way to circunvent this issue.