当我运行我的代码时,控制台中会出现垃圾邮件。
Module - whatsapp-web.js
代码
const { Client } = require('whatsapp-web.js');
const client = new Client();
client.on('qr', (qr) => {
// Generate and scan this code with your phone
console.log('QR RECEIVED', qr);
});
client.on('message', async(msg) => {
const mentions = await msg.getMentions();
for (let contact of mentions) {
console.log(`${contact.pushname} was mentioned`);
}
});
client.initialize();
如何使用此模块连接到whatsapp网络?
控制台
QR received
1@wCO3HYi6B1wat+cAyHe3+tlzfbjiWNxCTP30fEY16YNgmaBuknL/bBDpMNzA2SgfFPfCgQ==,yycd40PiAgEvrk961s+wiBLoMlsFb/eqVpRTN9Ec3FE=,E37yNJ5fmhoX3G/A==
类似上面的内容出现在控制台中。
这应该可以解决问题
$ npm i qrcode-terminal
然后
const qrcode = require('qrcode-terminal');
const { Client } = require('whatsapp-web.js');
const client = new Client();
client.on('qr', qr => {
qrcode.generate(qr, {small: true});
});
client.on('ready', () => {
console.log('Client is ready!');
});
client.initialize();
client.on('准备好', () => { console.log('客户端已准备好!');
登录后代码不起作用,扫描二维码后没有任何反应
运行代码后按照上面的答案,一些二维码图像将在您的控制台上生成。接下来,您转到您的 Whatsapp,从右上角的三个点图标下选择“链接的设备”。这里您应该扫描控制台生成的二维码图像。现在它已准备好发送和接收消息