tiny-essentials
Version:
Collection of small, essential scripts designed to be used across various projects. These simple utilities are crafted for speed, ease of use, and versatility.
28 lines • 1.42 kB
text/typescript
/**
* Retrieves user information from the Discord API.
*
* This function is typically used to fetch the authenticated user's information
* (`@me`) or a specific user's data by their user ID.
*
* @param {string} access_token - The access token used for authentication (typically obtained via OAuth2).
* @param {string} [type='Bearer'] - The token type (usually 'Bearer' for OAuth2 or 'Bot' for bot tokens).
* @param {string} [user='@me'] - The user ID to fetch. Use '@me' to get the authenticated user's profile.
* @param {string} [version=''] - Optional API version prefix (e.g., 'v10/') if needed by your API setup.
*
* @returns {Promise<Record<string, any>>} Resolves with the user's profile data returned by Discord.
*
* @throws {Record<string, any>} If the request fails, rejects with an error object containing `code` and `message`.
*
* @example
* getUser('access_token_here')
* .then(user => console.log('Logged in as:', user.username))
* .catch(err => console.error('User fetch failed:', err));
*
* @example
* // Using a bot token to fetch another user
* getUser('bot_token', 'Bot', '123456789012345678')
* .then(user => console.log('User info:', user))
* .catch(err => console.error('Error:', err));
*/
export default function getUser(access_token: string, type?: string, user?: string, version?: string): Promise<Record<string, any>>;
//# sourceMappingURL=getUser.d.mts.map