Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

room-join 事件下,无法通过contact.id 方法获取contact_id #54

Closed
lijiarui opened this issue Oct 20, 2016 · 1 comment
Closed
Labels

Comments

@lijiarui
Copy link
Member

Please run npm run doctor and paste the output here

Wechaty Doctor

  1. Wechaty version: #git[fe60b3c code clean]
  2. Darwin x64 version 15.6.0 memory 4 GB
  3. Docker: false

Expected behavior

触发room-join event 时,获取当前机器人的contact.id

代码如下:

.on('room-join', (room, invitee, inviter) => {
  const user = bot.user()
  console.log(user.id)
})

Actual behavior

运行报错:

orangiss/testfun.ts(31,15): Object is possibly 'null'. (2531)

处理办法:

检查发现,虽然console.log(user.id)会运行报错,但是console.log(user)可以正常显示user内容。
user类型为Contact,理论上Contact.id 是可以成功获取到id的,但是在room-join事件触发时不可以。

进一步将代码修改为:

console.log((user as any).id)

可以成功的运行并获取到user.id

希望可以修复此bug。

@huan huan closed this as completed in dda941b Oct 20, 2016
@huan huan added the bug label Oct 20, 2016
@lijiarui
Copy link
Member Author

当我使用在room中使用 Room.topic() 时, 遇见了同样的bug

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants