wechaty / puppet-wechat

Wechaty Puppet Provider for WeChat
https://www.npmjs.com/package/wechaty-puppet-wechat
Apache License 2.0
408 stars 68 forks source link

(node:4092) UnhandledPromiseRejectionWarning: ReferenceError: config is not defined #149

Open EthanGarrick opened 3 years ago

EthanGarrick commented 3 years ago

重磅:使用UOS微信桌面版协议登录,wechaty免费版web协议重放荣光

使用上面那篇文章的代码进行登录是报错,扫码后出现如下错误:

(node:4092) UnhandledPromiseRejectionWarning: ReferenceError: config is not defined
    at Wechaty.onLogin (D:\Learning\wxbot\wechaty\index.js:22:3)
    at Wechaty.emit (events.js:315:20)
    at Wechaty.EventEmitter.emit (domain.js:467:12)
    at PuppetWeChat.<anonymous> (D:\Learning\wxbot\wechaty\node_modules\_wechaty@0.68.1@wechaty\dist\src\wechaty.js:303:34)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:4092) 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(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:4092) [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.

使用的代码:

const { Wechaty } = require('wechaty');

const name = 'wechat-puppet-wechat';
let bot = '';
bot = new Wechaty({
  name, // generate xxxx.memory-card.json and save login data for the next login
});

//  二维码生成
function onScan(qrcode, status) {
  require('qrcode-terminal').generate(qrcode); // 在console端显示二维码
  const qrcodeImageUrl = [
    'https://wechaty.js.org/qrcode/',
    encodeURIComponent(qrcode),
  ].join('');
  console.log(qrcodeImageUrl);
}

// 登录
async function onLogin(user) {
  console.log(`贴心小助理${user}登录了`);
  if (config.AUTOREPLY) {
    console.log(`已开启机器人自动聊天模式`);
  }
  // 登陆后创建定时任务
  await initDay();
}

//登出
function onLogout(user) {
  console.log(`小助手${user} 已经登出`);
}

bot.on('scan', onScan);
bot.on('login', onLogin);
bot.on('logout', onLogout);
bot
  .start()
  .then(() => console.log('开始登陆微信'))
  .catch((e) => console.error(e));

这是怎么回事呢?请大佬们帮忙解答一下,谢谢!