ERR Wechaty start() exception: The "listener" argument must be of type function. Received undefined
shark2shark opened this issue · 2 comments
shark2shark commented
main.ts:
import { Contact, log, Message, ScanStatus, Wechaty } from "wechaty";
const bot = new Wechaty({
name: "TestBot",
puppet: "wechaty-puppet-padlocal",
puppetOptions: {
token:"TOKEN"
}
})
.on("scan", (qrcode: string, status: ScanStatus) => {
if (status === ScanStatus.Waiting && qrcode) {
const qrcodeImageUrl = [
'https://wechaty.js.org/qrcode/',
encodeURIComponent(qrcode),
].join('')
log.info("TestBot", `onScan: ${ScanStatus[status]}(${status}) - ${qrcodeImageUrl}`);
require('qrcode-terminal').generate(qrcode, { small: true }) // show qrcode on console
} else {
log.info("TestBot", `onScan: ${ScanStatus[status]}(${status})`);
}
})
.on("login", (user: Contact) => {
log.info("TestBot", `${user} login`);
})
.on("logout", (user: Contact, reason: string) => {
log.info("TestBot", `${user} logout, reason: ${reason}`);
})
.on("message", async (message: Message) => {
log.info("TestBot", `on message: ${message.toString()}`);
// ding-dong bot
if (message.to()?.self() && message.text().indexOf("ding") !== -1) {
await message.talker().say(message.text().replace("ding", "dong"));
}
})
.on("error", (error) => {
log.error("TestBot", 'on error: ', error.stack);
})
bot.start().then(() => {
log.info("TestBot", "started.");
});
package.json -> dependencies:
"dependencies": {
"qrcode-terminal": "^0.12.0",
"wechaty": "^0.73.8",
"wechaty-puppet-padlocal": "^0.4.2"
}
run: npm run demo
console:
> wechaty-puppet-padlocal-demo@0.1.2 demo
> ./node_modules/.bin/ts-node main.ts
TypeError: The "listener" argument must be of type function. Received undefined
at checkListener (node:events:128:3)
at _addListener (node:events:423:3)
at StateSwitch.addListener (node:events:487:10)
at PuppetPadlocal._startClient (/Users/original/Workspace/mine/robot/wechaty-puppet-padlocal-demo/node_modules/wechaty-puppet-padlocal/src/puppet-padlocal.ts:145:20)
at PuppetPadlocal.start (/Users/original/Workspace/mine/robot/wechaty-puppet-padlocal-demo/node_modules/wechaty-puppet-padlocal/src/puppet-padlocal.ts:141:16)
at Wechaty.start (/Users/original/Workspace/mine/robot/wechaty-puppet-padlocal-demo/node_modules/wechaty/src/wechaty.ts:730:25)
at processTicksAndRejections (node:internal/process/task_queues:96:5) {
code: 'ERR_INVALID_ARG_TYPE'
}
15:28:48 ERR Wechaty start() exception: The "listener" argument must be of type function. Received undefined
15:28:48 ERR TestBot on error:
15:28:48 WARN Wechaty stop() puppet.stop() exception: The "listener" argument must be of type function. Received undefined
15:28:48 INFO TestBot started.
superaitaotao commented
@13193310336 node版本一定要是14.n的,然后重新安装一遍依赖就好了。
xmsz commented
puppetOptions: { token:"TOKEN" }
16.n的可以吗 我也遇到这个问题
我觉得应该是版本问题 wechaty已经是1.x 这个项目还是0.x