Install
openclaw skills install bilibili-messagerSend Bilibili DMs, reply to messages, read chat history via browser automation. | 通过浏览器自动化发送 B 站私信、回复消息、读私信、看聊天记录。
openclaw skills install bilibili-messager本技能通过已登录的 Bilibili 浏览器会话读写私信。
限制:
openclaw profile(不混用其他账号)| 条件 | 说明 |
|---|---|
| Browser profile | 必须使用 openclaw profile(已通过 browser 工具启动并登录 Bilibili) |
| 登录状态 | Bilibili 账号已在 openclaw profile 中保持登录态 |
| 账号确认 | 发送操作前,技能会要求用户明确确认目标账号和消息内容 |
本技能通过在 Bilibili 私信页面执行 DOM JavaScript(querySelector、innerText、click 等)实现消息读取和发送。这些操作需要浏览器环境持有有效的 Bilibili 登录会话。
openclaw profile 由 OpenClaw 启动和管理,独立于 Morois 的日常浏览器 profilemessage.bilibili.com)域内执行 DOM 操作,无法访问其他网站读取本 SKILL.md 后,先确认当前任务属于哪种模式,再跳转对应章节执行。
| 模式 | 说明 |
|---|---|
| send | 发送新私信(必须两步验证) |
| reply | 回复现有会话中的消息(必须两步验证) |
| read | 读取聊天记录(只读,不写入任何内容) |
openclaw profile(已登录 Bilibili)browser action=open targetUrl=https://message.bilibili.com/#/whisper
检查页面是否跳转到登录页。若跳转到登录页,停下来让用户完成登录。
在左侧会话列表中找到目标联系人。可以通过文字搜索或滚动列表。
browser action=act evaluate 配合 DOM 查询找到目标会话mid 参数或页面标题显示对方名字)向用户汇报以下全部内容,确认前不得写入或发送:
| 汇报项 | 内容 |
|---|---|
| 目标账号 | 会话对方的名字 |
| 消息内容 | 将要发送的完整内容 |
| 字数 | 是否在 500 字以内 |
确认标志:用户明确回复「好」「确认」「发」「发吧」「发送」等。
使用 innerText 方式写入(经验证有效):
() => {
var editor = document.querySelector('.content-input, [contenteditable="true"]');
if (!editor) return 'editor not found';
editor.focus();
editor.innerText = '消息内容';
editor.dispatchEvent(new Event('input', {bubbles: true}));
return 'typed';
}
() => {
var btns = document.querySelectorAll('button, [class*="btn"]');
for (var btn of btns) {
if ((btn.textContent || '').includes('发送')) {
btn.click();
return 'sent';
}
}
return 'send button not found';
}
注意:
navigator.clipboard.writeText() + execCommand('paste') — 对B站无效innerText + 触发 input 事件 — 成功回复与发送流程基本相同,区别在于:
browser action=open targetUrl=https://message.bilibili.com/#/whisper
在左侧会话列表中找到目标联系人,点击进入。
⚠️ 核心原则:判断发送方归属,100% 依赖 DOM class 名称,不靠语义内容猜测。
B站私信页面上,每条消息是一个 HTML 元素,该元素的 class 属性包含判断归属的关键信息。
class 名称的格式一(我发的消息):
class="_Msg_o7f0t_1 _MsgIsMe_o7f0t_9"
_Msg_o7f0t_1:消息容器(固定前缀 _Msg_ + 会话ID o7f0t + 数字 1)_MsgIsMe_o7f0t_9:附加标记,表示"这条消息是当前登录用户发的"class 名称的格式二(对方发的消息):
class="_Msg_o7f0t_1"
_Msg_ 开头的容器 class,没有 _MsgIsMe_ 标记关于会话ID(上面例子里的 o7f0t):
[a-z0-9]+ 匹配(ID只包含小写字母和数字)找到所有顶级消息容器:
[class*="_Msg_"] 找到所有包含 _Msg_ 的元素_Msg_[a-z0-9]+_\d+ 过滤,只保留顶级容器
_Msg_o7f0t_1、_Msg_abc123_42、_Msg_x_99判断发送方归属:
_MsgIsMe_,则这是一条我发的消息(Morois / 当前登录用户)_MsgIsMe_,则这是一条对方发的消息❌ 禁止用左右位置判断:
_MsgIsMe_ 有没有出现来判断| class 名称 | 含义 |
|---|---|
_Msg_o7f0t_1 | 消息容器,会话ID是 o7f0t,序号1 |
_Msg_o7f0t_1 _MsgIsMe_o7f0t_9 | 我发的消息(morois发的),有 _MsgIsMe_ 标记 |
_Msg_abc123_42 | 消息容器,会话ID是 abc123,序号42,对方发的 |
_Msg_x_7 | 消息容器,会话ID是 x,序号7,对方发的 |
_MsgIsMe_x_15 | 我发的消息(morois发的),会话ID是 x,序号15 |
() => {
const containers = Array.from(document.querySelectorAll('[class*="_Msg_"]'))
.filter(el => el.className.match(/_Msg_[a-z0-9]+_\d+ /));
const results = [];
for (const el of containers) {
const cls = el.className + '';
// 关键判断:有 _MsgIsMe_ → 我发的;没有 → 对方发的
const isMe = cls.includes('_MsgIsMe_');
const sender = isMe ? '【我方/Morois】' : '【对方】';
// 提取时间
const timeEl = el.querySelector('[class*="_Msg__Time_"]');
const time = timeEl ? timeEl.textContent.trim() : '';
// 提取消息内容(可能有多个 Content class,取非重复内容)
const contentEls = el.querySelectorAll('[class*="_Msg__Content_"]');
const texts = [];
for (const c of contentEls) {
const t = (c.textContent || '').trim().replace(/\s+/g, ' ');
// 排除时间格式的内容(如"2026年3月28日 18:00")
if (t && !t.match(/^\d{4}年/)) texts.push(t.slice(0, 200));
}
const uniqueTexts = [...new Set(texts)];
const text = uniqueTexts.join(' | ');
if (text) results.push({ sender, time, text });
}
return results;
}
B站私信页面的编辑器可能出现在不同位置。尝试:
() => {
const selectors = [
'.content-input',
'[contenteditable="true"]',
'[class*="editor"]',
'[class*="input"]'
];
for (const sel of selectors) {
const el = document.querySelector(sel);
if (el) return sel + ' found: ' + el.className;
}
return 'no editor found';
}
发送按钮可能没有稳定的 class 或 ref。查找包含"发送"文字的按钮:
() => {
const btns = document.querySelectorAll('button, [class*="btn"], [class*="send"]');
for (const btn of btns) {
if ((btn.textContent || '').includes('发送')) {
return 'found: ' + btn.className;
}
}
return 'send button not found';
}
如果脚本返回空结果或找不到元素,按以下顺序诊断:
browser action=snapshot 获取当前页面完整 DOM_Msg_ 或 messagecontenteditable、input、editor发送 文字或 button诊断脚本:
() => {
return {
msgs: Array.from(document.querySelectorAll('[class*="Msg"]')).slice(0,3).map(el=>el.className),
editor: document.querySelector('[contenteditable="true"]') ? 'found' : 'not found',
btns: Array.from(document.querySelectorAll('button')).map(b=>b.textContent.trim()).filter(t=>t)
};
}
本技能依赖已登录的 Bilibili 浏览器会话作为账户凭据。使用前请确认:
openclaw profile,不与日常浏览器混用openclaw profile 的浏览器标签页即可message.bilibili.com)内执行,不访问其他网站