Message对象的mention和mentionSelf异步函数无效
Created by: BeanHsiang
操作步骤
- 克隆最新的项目,打开\examples\professional\tuling123-bot.js
- 在onMessage函数体的开头添加代码:
async function onMessage(msg) {
// reply from special room
const room = msg.room();
const topic = await room.topic();
if (room) {
// console.log(msg.room());
console.log('start onMessage');
// result = await msg.mentionSelf();
result = await msg.mention();
console.log(result);
}
// Skip message from self, or inside a room
if (msg.self() || msg.room() || msg.from().name() === '微信团队' || msg.type() !== Message.Type.Text) return
console.log('Bot', 'talk: %s', msg.text())
try {
const { text: reply } = await tuling.ask(msg.text(), { userid: msg.from() })
console.log('Tuling123', 'Talker reply:"%s" for "%s" ',
reply,
msg.text(),
)
await msg.say(reply)
} catch (e) {
console.error('Bot', 'on message tuling.ask() exception: %s', e && e.message || e)
}
}
- 执行代码,扫码登录一个bot,用另一个微信号在手机端登录,并在微信群中@前面登录的bot。
期望结果
在打印result时有非空的对象,换成mentionSelf时,期望打印true
实际打印结果
start onMessage
[]
换成mentionSelf时
start onMessage
false