getUserProfileAudios
Returns: UserProfileAudiosOfficial docs ↗
Use this method to get a list of profile audios for a user. Returns a UserProfileAudios object.
Parameters
user_idIntegerRequiredUnique identifier of the target user
offsetIntegerOptionalSequential number of the first audio to be returned. By default, all audios are returned.
limitIntegerOptional Default: 100min 1max 100Limits the number of audios to be retrieved. Values between 1-100 are accepted. Defaults to 100.
Returns
On success, the UserProfileAudios object is returned.
GramIO Usage
ts
// Get all profile audios for a user:
const result = await bot.api.getUserProfileAudios({
user_id: 12345678,
});
console.log(`User has ${result.total_count} profile audio(s)`);ts
// Check if a user has set a profile audio in a message handler:
bot.command("audio", async (ctx) => {
if (!ctx.from) return;
const result = await bot.api.getUserProfileAudios({
user_id: ctx.from.id,
limit: 1,
});
if (result.total_count === 0) {
return ctx.send("You haven't set a profile audio yet.");
}
await ctx.send(`You have ${result.total_count} profile audio(s).`);
});ts
// Paginate through profile audios in batches of 10:
const page1 = await bot.api.getUserProfileAudios({
user_id: 12345678,
offset: 0,
limit: 10,
});
// Fetch next page if more audios exist:
if (page1.total_count > 10) {
const page2 = await bot.api.getUserProfileAudios({
user_id: 12345678,
offset: 10,
limit: 10,
});
console.log("Second page audio count:", page2.audios.length);
}Errors
| Code | Error | Cause |
|---|---|---|
| 400 | Bad Request: user not found | The user_id doesn't correspond to a known Telegram user |
| 400 | Bad Request: chat not found | User is inaccessible (never interacted with the bot and no shared chat) |
| 429 | Too Many Requests: retry after N | Rate limit hit — check retry_after and back off |
TIP
Use GramIO's auto-retry plugin to handle 429 errors automatically.
Tips & Gotchas
- Not all users have profile audios. Profile audio is a Telegram Premium feature —
total_countwill be0for users who haven't set one. Always check before processing. offsetis an integer (sequential position). UnlikegetUserGifts, pagination here uses a numeric offset — pass0for the first audio,10for the eleventh, etc.total_countreflects all available audios, not just the current page. Use it to calculate whether more pages exist (total_count > offset + limit).- Requires the user to have interacted with the bot or share a mutual chat — otherwise Telegram may return a "user not found" error.
- Added as part of the profile audio feature. This method mirrors
getUserProfilePhotosin structure but for audio files set as profile backgrounds.
See Also
- UserProfileAudios — return type with
total_countandaudiosarray - getUserProfilePhotos — analogous method for profile photos