Overview
The NTQQUserApi class provides methods for retrieving user information, managing profiles, handling conversions between UID/UIN, and accessing user-related services.
getUserDetailInfo
Get detailed information about a user.
async getUserDetailInfo(
uid: string,
no_cache: boolean = false
): Promise<User>
Whether to fetch from server instead of cache
User object with detailed information
Example:
const user = await core.apis.UserApi.getUserDetailInfo('u_abc123');
console.log('Nickname:', user.nick);
console.log('QQ Level:', user.qqLevel);
console.log('Age:', user.age);
fetchUserDetailInfo
Fetch user detail from specific source.
async fetchUserDetailInfo(
uid: string,
mode: UserDetailSource = UserDetailSource.KDB
)
mode
UserDetailSource
default:"UserDetailSource.KDB"
Data source: KDB (cache) or KSERVER (server)
Detailed user profile information
getCoreAndBaseInfo
Get core and basic information for multiple users.
async getCoreAndBaseInfo(
uids: string[]
): Promise<Map<string, UserInfo>>
Map of UID to user information
Example:
const users = await core.apis.UserApi.getCoreAndBaseInfo([
'u_user1',
'u_user2',
'u_user3'
]);
users.forEach((info, uid) => {
console.log(`${uid}: ${info.nick}`);
});
UID/UIN Conversion
getUidByUinV2
Convert UIN to UID.
async getUidByUinV2(uin: string): Promise<string>
User UID, or empty string if not found
Example:
const uid = await core.apis.UserApi.getUidByUinV2('123456789');
if (uid) {
console.log('UID:', uid);
}
getUinByUidV2
Convert UID to UIN.
async getUinByUidV2(uid: string): Promise<string>
User UIN (QQ number), or ‘0’ if not found
Example:
const uin = await core.apis.UserApi.getUinByUidV2('u_abc123');
if (uin !== '0') {
console.log('QQ:', uin);
}
Profile Management
modifySelfProfile
Modify bot’s own profile.
async modifySelfProfile(param: ModifyProfileParams)
param
ModifyProfileParams
required
Object containing profile fields to modify
Example:
await core.apis.UserApi.modifySelfProfile({
nick: 'My Bot',
longNick: 'This is my bot description',
// ... other profile fields
});
setLongNick
Set bot’s signature/personal description.
async setLongNick(longNick: string)
Example:
await core.apis.UserApi.setLongNick('I am a helpful QQ bot!');
setQQAvatar
Set bot’s QQ avatar.
async setQQAvatar(
filePath: string
): Promise<{ result: number, errMsg: string }>
return
{ result: number, errMsg: string }
Result code and error message
Example:
const result = await core.apis.UserApi.setQQAvatar('/path/to/avatar.png');
if (result.result === 0) {
console.log('Avatar updated successfully');
} else {
console.error('Failed:', result.errMsg);
}
Online Status
setSelfOnlineStatus
Set bot’s online status.
async setSelfOnlineStatus(
status: number,
extStatus: number,
batteryStatus: number
)
Status code (online, away, busy, etc.)
Example:
// Set to online
await core.apis.UserApi.setSelfOnlineStatus(1, 0, 0);
setDiySelfOnlineStatus
Set custom online status with emoji and text.
async setDiySelfOnlineStatus(
faceId: string,
wording: string,
faceType: string
)
Example:
await core.apis.UserApi.setDiySelfOnlineStatus(
'123',
'Working on something awesome',
'1'
);
Profile Likes
like
Send like(s) to a user’s profile.
async like(
uid: string,
count: number = 1
): Promise<{ result: number, errMsg: string, succCounts: number }>
Number of likes to send (1-20)
return
{ result: number, errMsg: string, succCounts: number }
Result with success count
Example:
const result = await core.apis.UserApi.like('u_abc123', 10);
console.log(`Sent ${result.succCounts} likes`);
getProfileLike
Get profile like information.
async getProfileLike(
uid: string,
start: number,
count: number,
type: number = 2
)
Number of records to fetch
Type: 2 for self, 1 for others
Cookies & Authentication
getCookies
Get cookies for a specific domain.
async getCookies(domain: string): Promise<{ [key: string]: string }>
Domain name (e.g., ‘qun.qq.com’)
return
{ [key: string]: string }
Object containing cookies
Example:
const cookies = await core.apis.UserApi.getCookies('qun.qq.com');
console.log('p_skey:', cookies.p_skey);
getPSkey
Get PSkey for domains.
async getPSkey(domainList: string[])
return
{ domainPskeyMap: Map<string, string> }
Map of domain to PSkey
Example:
const result = await core.apis.UserApi.getPSkey(['qun.qq.com', 'ti.qq.com']);
const pskey = result.domainPskeyMap.get('qun.qq.com');
getSKey
Get SKey for authentication.
async getSKey(): Promise<string | undefined>
SKey string if successful
getQzoneCookies
Get cookies specifically for Qzone.
async getQzoneCookies(): Promise<{ [key: string]: string }>
return
{ [key: string]: string }
Qzone cookies
forceFetchClientKey
Force fetch client key.
async forceFetchClientKey()
return
{ result: number, clientKey: string, keyIndex: string }
Client key information
Get list of recent contacts.
async getRecentContactList()
Array of recent contact objects
Get snapshot of recent contacts.
async getRecentContactListSnapShot(count: number)
Number of contacts to retrieve
Get synced recent contact list.
async getRecentContactListSync()
Get synced recent contacts with limit.
async getRecentContactListSyncLimit(count: number)
Maximum number of contacts
Utility Methods
getUserDetailInfoByUin
Get user detail by UIN directly.
async getUserDetailInfoByUin(Uin: string)
Get friend recommendation card in Ark JSON format.
async getBuddyRecommendContactArkJson(
uin: string,
sencenID: string = ''
)
getRobotUinRange
Get robot UIN range information.
async getRobotUinRange(): Promise<Array<unknown>>
Array of robot UIN range data
Complete Example
import { NapCatCore } from '@/napcat-core';
async function manageUserProfile(core: NapCatCore) {
// Get user info by UID
const user = await core.apis.UserApi.getUserDetailInfo('u_abc123', true);
console.log(`User: ${user.nick}`);
console.log(`Level: ${user.qqLevel}`);
// Convert between UID and UIN
const uin = await core.apis.UserApi.getUinByUidV2('u_abc123');
const uid = await core.apis.UserApi.getUidByUinV2('123456789');
// Update bot profile
await core.apis.UserApi.setLongNick('I am a helpful bot!');
await core.apis.UserApi.setQQAvatar('/path/to/avatar.png');
// Set online status
await core.apis.UserApi.setSelfOnlineStatus(1, 0, 0);
// Send likes to user
await core.apis.UserApi.like('u_abc123', 10);
// Get recent contacts
const recent = await core.apis.UserApi.getRecentContactList();
console.log(`${recent.length} recent contacts`);
}