bot.Room.create 创建群聊报错
Closed this issue · 7 comments
问题
调用 bot.Room.create 创建群聊报错
环境
node version: 11.0.0
wechaty version: 0.23.18
wechaty-puppet-padchat version: 0.17.21
版本1,通过 name find 联系人后建群
const topic = '测试群5'
const names = ['薛定谔的猫', '张晓明']
let contacts = []
for (let name of names) {
let contract = await bot.Contact.find({ name: name })
contacts.push(contract)
}
const room = await bot.Room.create(contacts, topic)
await room.topic(topic + ' - created')
await room.say(topic + ' - created')
版本2,通过 id load 联系人后建群
const topic = '测试群6'
const ids = ['yaosixxxxx', 'zxm1xxxx']
let contacts = []
for (let id of ids) {
let contract = bot.Contact.load(id)
contacts.push(contract)
}
const room = await bot.Room.create(contacts, topic)
await room.topic(topic + ' - created')
await room.say(topic + ' - created')
补充一下,版本1,曾经成功过1次。但是会报错
12:40:11 WARN Room topic() room not ready
(node:73645) UnhandledPromiseRejectionWarning: Error: not ready
at AnotherOriginalClass.<anonymous> (/Users/likai/dev/work/unibot/node_modules/wechaty/dist/src/user/room.js:598:23)
at Generator.next (<anonymous>)
at /Users/likai/dev/work/unibot/node_modules/wechaty/dist/src/user/room.js:7:71
at new Promise (<anonymous>)
at __awaiter (/Users/likai/dev/work/unibot/node_modules/wechaty/dist/src/user/room.js:3:12)
at AnotherOriginalClass.topic (/Users/likai/dev/work/unibot/node_modules/wechaty/dist/src/user/room.js:594:16)
at Timeout._onTimeout (/Users/likai/dev/work/unibot/src/add_friend.js:78:18)
at listOnTimeout (timers.js:324:15)
at processTimers (timers.js:268:5)
(node:73645) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:73645) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
You could try to do a sync()
before create the room, like below.
const topic = '测试群6'
const ids = ['yaosixxxxx', 'zxm1xxxx']
let contacts = []
for (let id of ids) {
let contact = bot.Contact.load(id)
await contact.sync()
contacts.push(contact)
}
const room = await bot.Room.create(contacts, topic)
await room.topic(topic + ' - created')
await room.say(topic + ' - created')
And we recommend to use id
to do most of the operations, since id
is much more reliable than name
.
@windmemory 好的,这个方法看起来能解决我第二个问题,但是第一个问题还是会存在的样子。
建议debug的时候开一个log,然后贴一下详细log过来
用环境变量开启log,如下所示
BROLOG_LEVEL=silly node bot.js
开了log之后注意一下WXCreateChatRoom
的接口调用,应该能看到一些报错信息
然后目前已知的两种情况,一个是返回的status
是-2
,这个目前还不太清楚原因,如果是这样的情况,先更换一个微信号,再测试。另外一个是返回的status
是-34
,这个是因为每日每个账号有建群上限,质量不好的账号每日甚至可能只能建一个群,这种情况下,如果需要测试的话,也是需要更换账号,或者等待第二天再做测试。
@windmemory 用 id 然后通过 bot.Contract.load 并且 调用 sync() 方法,这次返回了下面的错误
13:52:36 VERB Room create(Contact<薛定谔的猫>,Contact<张晓明>, 交流群11)
13:52:36 VERB PuppetPadchat roomCreate(yaosiwen003,zxm115464, 交流群11)
13:52:36 SILL PadchatRpc rpcCall(WXCreateChatRoom, ["[\"yaosiwen003\",\"zxm115464\"]"])
13:52:36 SILL PadchatRpc initWebSocket() ws.on(message): {"apiName":"WXCreateChatRoom","data":"%7B%22message%22%3A%22%5Cn%5Cu0014MemberList+are+wrong%22%2C%2
13:52:36 SILL PadchatRpc WXCreateChatRoom(userList.length=2) = "{"message":"\n\u0014MemberList are wrong","status":0,"user_name":""}"
13:52:36 VERB Puppet roomPayload()
13:52:36 ERR Room create() exception: Error: no id
at PuppetPadchat.<anonymous> (/Users/likai/dev/work/unibot/node_modules/wechaty-puppet/dist/src/puppet.js:688:23)
at Generator.next (<anonymous>)
at /Users/likai/dev/work/unibot/node_modules/wechaty-puppet/dist/src/puppet.js:25:71
at new Promise (<anonymous>)
at __awaiter (/Users/likai/dev/work/unibot/node_modules/wechaty-puppet/dist/src/puppet.js:21:12)
at PuppetPadchat.roomPayload (/Users/likai/dev/work/unibot/node_modules/wechaty-puppet/dist/src/puppet.js:685:16)
at PuppetPadchat.<anonymous> (/Users/likai/dev/work/unibot/node_modules/wechaty-puppet-padchat/dist/src/puppet-padchat.js:1055:24)
at Generator.next (<anonymous>)
at fulfilled (/Users/likai/dev/work/unibot/node_modules/wechaty-puppet-padchat/dist/src/puppet-padchat.js:22:58)
at process.internalTickCallback (internal/process/next_tick.js:77:7)
Error: no id
at PuppetPadchat.<anonymous> (/Users/likai/dev/work/unibot/node_modules/wechaty-puppet/dist/src/puppet.js:688:23)
at Generator.next (<anonymous>)
at /Users/likai/dev/work/unibot/node_modules/wechaty-puppet/dist/src/puppet.js:25:71
at new Promise (<anonymous>)
at __awaiter (/Users/likai/dev/work/unibot/node_modules/wechaty-puppet/dist/src/puppet.js:21:12)
at PuppetPadchat.roomPayload (/Users/likai/dev/work/unibot/node_modules/wechaty-puppet/dist/src/puppet.js:685:16)
at PuppetPadchat.<anonymous> (/Users/likai/dev/work/unibot/node_modules/wechaty-puppet-padchat/dist/src/puppet-padchat.js:1055:24)
at Generator.next (<anonymous>)
at fulfilled (/Users/likai/dev/work/unibot/node_modules/wechaty-puppet-padchat/dist/src/puppet-padchat.js:22:58)
同样的代码再次运行脚本,还是报错,不过这次是提示创建频率过快了
对于这种错误能否将这个错误信息直接返回呢
13:55:36 VERB Room create(Contact<薛定谔的猫>,Contact<张晓明>, 交流群12)
13:55:36 VERB PuppetPadchat roomCreate(yaosiwen003,zxm115464, 交流群12)
13:55:36 SILL PadchatRpc rpcCall(WXCreateChatRoom, ["[\"yaosiwen003\",\"zxm115464\"]"])
13:55:37 SILL PadchatRpc initWebSocket() ws.on(message): {"apiName":"WXCreateChatRoom","data":"%7B%22message%22%3A%22%5Cn%EF%BF%BD%5Cu0002%3Ce%3E%5Cn%3CShowT
13:55:37 SILL PadchatRpc WXCreateChatRoom(userList.length=2) = "{"message":"\n�\u0002<e>\n<ShowType>1</ShowType>\n<Content><![CDATA[创建群聊的频率过快,请明日再试。]]></Content>\n<Url><![CDATA[]]></Url>\n<DispSec>30</DispSec>\n<Title><![CDATA[]]></Title>\n<Action>4</Action>\n<DelayConnSec>0</DelayConnSec>\n<Countdown>0</Countdown>\n<Ok><![CDATA[]]></Ok>\n<Cancel><![CDATA[]]></Cancel>\n</e>\n","status":-34,"user_name":""}"
13:55:37 ERR Room create() exception: Error: WXCreateChatRoom , stranger,error! canot get result from websocket server
at PadchatManager.<anonymous> (/Users/likai/dev/work/unibot/node_modules/wechaty-puppet-padchat/dist/src/padchat-rpc.js:1148:23)
at Generator.next (<anonymous>)
at fulfilled (/Users/likai/dev/work/unibot/node_modules/wechaty-puppet-padchat/dist/src/padchat-rpc.js:4:58)
at process.internalTickCallback (internal/process/next_tick.js:77:7)
Error: WXCreateChatRoom , stranger,error! canot get result from websocket server
at PadchatManager.<anonymous> (/Users/likai/dev/work/unibot/node_modules/wechaty-puppet-padchat/dist/src/padchat-rpc.js:1148:23)
at Generator.next (<anonymous>)
at fulfilled (/Users/likai/dev/work/unibot/node_modules/wechaty-puppet-padchat/dist/src/padchat-rpc.js:4:58)
at process.internalTickCallback (internal/process/next_tick.js:77:7)
嗯,我们这边确实应该在抛出异常部分处理的更具体一些