Skip to content

Commit e8d74f7

Browse files
committed
Add singular fetch_user
1 parent 8a750c8 commit e8d74f7

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

twitchio/client.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1633,6 +1633,59 @@ async def fetch_users(
16331633
data = await self._http.get_users(ids=ids, logins=logins, token_for=token_for)
16341634
return [User(d, http=self._http) for d in data["data"]]
16351635

1636+
async def fetch_user(
1637+
self,
1638+
*,
1639+
id: str | int | None = None,
1640+
login: str | None = None,
1641+
token_for: str | PartialUser | None = None,
1642+
) -> User | None:
1643+
"""|coro|
1644+
1645+
Fetch information about one user.
1646+
1647+
.. note::
1648+
1649+
You may look up a specific user using their user ID or login name.
1650+
1651+
For example, you may specify `50` IDs and `50` names or `100` IDs or names,
1652+
but you cannot specify `100` IDs and `100` names.
1653+
1654+
If you don't specify an ID or login name but provide the `token_for` parameter,
1655+
the request returns information about the user associated with the access token.
1656+
1657+
To include the user's verified email address in the response,
1658+
you must have a user access token that includes the `user:read:email` scope.
1659+
1660+
Parameters
1661+
----------
1662+
id: str | int | None
1663+
The id of the user to fetch information about.
1664+
login: str | None
1665+
The login name of the user to fetch information about.
1666+
token_for: str | PartialUser | None
1667+
|token_for|
1668+
1669+
If this parameter is provided, the token must have the `user:read:email` scope
1670+
in order to request the user's verified email address.
1671+
1672+
Returns
1673+
-------
1674+
:class:`twitchio.User`
1675+
A :class:`twitchio.User` object.
1676+
1677+
Raises
1678+
------
1679+
ValueError
1680+
The combined number of 'ids' and 'logins' must not exceed `100` elements.
1681+
"""
1682+
1683+
if id is not None and login is not None:
1684+
raise ValueError("Please provide only one of `id` or `login`.")
1685+
1686+
data = await self._http.get_users(ids=id, logins=login, token_for=token_for)
1687+
return User(data["data"][0], http=self._http) if data["data"] else None
1688+
16361689
def search_categories(
16371690
self,
16381691
query: str,

0 commit comments

Comments
 (0)