dolfies / discord.py-self

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

'HTTPClient' object has no attribute 'user_agent' #135

Closed V3ntus closed 2 years ago

V3ntus commented 2 years ago

Summary

When running "fetch_user", I get an AttributeError exception

Reproduction Steps

Code

import selfcord as discord
from selfcord.ext import commands

client = commands.Bot(command_prefix=",",
                      case_insensitive=True,
                      user_bot=True,
                      guild_subscription_options=discord.GuildSubscriptionOptions.default())
selfcordClient = discord.Client()

client.run(TOKEN)
member.id = "(MEMBER_ID_HERE)"
userobj = await selfcordClient.fetch_user(member.id) # exception

Expected Results

fetch_user returns a discord.User object

Actual Results

Ignoring exception in on_ready
Traceback (most recent call last):
  File "/Users/ventus/GitRepos/darvester/env/lib/python3.9/site-packages/selfcord/client.py", line 301, in _run_event
    await coro(*args, **kwargs)
  File "/Users/ventus/GitRepos/darvester/run.py", line 79, in on_ready
    userobj = await selfcordClient.fetch_user(member.id)
  File "/Users/ventus/GitRepos/darvester/env/lib/python3.9/site-packages/selfcord/client.py", line 1362, in fetch_user
    data = await self.http.get_user(user_id)
  File "/Users/ventus/GitRepos/darvester/env/lib/python3.9/site-packages/selfcord/http.py", line 194, in request
    'User-Agent': self.user_agent,
AttributeError: 'HTTPClient' object has no attribute 'user_agent'

System Information

❯ python -m discord -v

- Python v3.9.8-final
- discord.py v1.7.3-final
- aiohttp v3.7.4.post0
- system info: Darwin 19.6.0 Darwin Kernel Version 19.6.0: Thu Nov 11 20:02:32 PST 2021; root:xnu-6153.141.49~1/RELEASE_X86_64

Checklist

Additional Information

No response

dolfies commented 2 years ago
  1. You don't need both a Client and a Bot. Bot is a subclass of Client.

  2. You haven't logged in...

V3ntus commented 2 years ago
  1. You don't need both a Client and a Bot. Bot is a subclass of Client.

There's a reason I was testing it this way. I'm trying to use the method connected_accounts on the User object, yet it was either returning None or module has no attribute but I realize my error now. Looking at the API doc, I should be using fetch_user_profile which returns type Profile instead of User.

But from your response, I altered my code and it's working as desired:

client = commands.Bot(...)

profileobj = await client.fetch_user_profile(member.id)
print(profileobj.connected_accounts) # returns desired output

  1. You haven't logged in...

I was/am, I just omitted it from my code by mistake


Thank you nonetheless. Facepalm on my part

dolfies commented 2 years ago

Ah, that makes more sense. We've all been there lol.