nonebot-plugin-uninfo

March 11, 2026 · View on GitHub

nonebot

nonebot-plugin-uninfo

Nonebot2 多平台的会话信息(用户、群组、频道)获取插件 ✨

license Python NoneBot pypi

本插件提供了多个模型,可以从不同适配器的 BotEvent 中提取与会话相关的属性

安装

  • 使用 nb-cli
nb plugin install nonebot-plugin-uninfo
  • 使用 pip
pip install nonebot-plugin-uninfo

使用

获取 Session

from nonebot_plugin_uninfo import get_session

@matcher.handle()
async def handle(bot: Bot, event: Event):
    session = await get_session(bot, event)

或使用依赖注入的形式:

from nonebot_plugin_uninfo import Uninfo, UniSession, Session

@matcher.handle()
async def handle(session: Session = UniSession()):
    ...

@matcher.handle()
async def handle1(session: Uninfo):
    ...

拉取用户/群组/频道列表:

from nonebot_plugin_uninfo import SceneType, QryItrface

@matcher.handle()
async def handle(interface: QryItrface):
    users = await interface.get_users()
    groups = await interface.get_scenes(SceneType.GROUP)
    members = await interface.get_members(groups[0].type, groups[0].id)

使用内建的 Permission:

from nonebot import on_command
from nonebot_plugin_uninfo import ADMIN

matcher = on_command("inspect", permission=ADMIN())

模型定义

User

属性类型含义备注
idstr用户 id
namestr | None用户名称
nickstr | None用户昵称好友备注
avatarstr | None用户头像
genderstr用户性别

Scene

属性类型含义备注
idstr场景 id
typeSceneType场景类型可分为 Private, Group, GuildChannel_XXX
namestr | None场景名称
avatarstr | None场景图标
parentScene | None父级场景适用于频道的二级群组场景, 或针对临时会话的来源群组

Member

属性类型含义备注
userUser成员的用户信息
nickstr | None成员昵称
rolestr | None成员角色组当可能存在多个角色组时,此处会使用 level 最高的那个
muteMuteInfo | None成员禁言信息
joined_atdatetime | None成员加入时间

Session

属性类型含义备注
self_idstr机器人 id
adapterstr适配器名称
scopestr适配器范围相比 adapter 更指向实际平台
sceneScene事件场景
userUser用户信息
memberMember | None成员信息仅适用于群组,频道场景
operatorMember | None操作者信息仅适用于群组,频道场景

示例

from nonebot_plugin_uninfo import Uninfo
from nonebot import on_command

matcher = on_command("inspect", aliases={"查看"}, priority=1)


@matcher.handle()
async def inspect(session: Uninfo):
    texts = [
        f"平台名: {session.adapter} | {session.scope}",
        f"用户ID: {session.user.name + ' | ' if session.user.name else ''}{session.user.id}",
        f"自身ID: {session.self_id}",
        f"事件场景: {session.scene.type.name}",
        f"频道 ID: {session.scene.name + ' | ' if session.scene.name else ''}{session.scene.id}"
    ]
    if session.scene.parent:
        texts.append(f"群组 ID: {session.scene.parent.name + ' | ' if session.scene.parent.name else ''}{session.scene.parent.id}")
    if session.member:
        texts.append(f"成员 ID: {session.member.nick + ' | ' if session.member.nick else ''}{session.member.id}")
    await matcher.send("\n".join(texts))

支持的 adapter

  • OneBot v11
  • OneBot v12
  • Console
  • Kook (Kaiheila)
  • Github
  • Telegram
  • Feishu
  • Discord
  • QQ
  • Satori
  • DoDo
  • Kritor
  • Mirai
  • Tailchat
  • Mail
  • WXMP
  • heybox
  • Milky
  • EFChat
  • Yuhun
  • Bililive

相关插件

  • nonebot-plugin-alconna 强大的 Nonebot2 命令匹配拓展,支持富文本/多媒体解析,跨平台消息收发

鸣谢