Baileys: [BUG] Failure to Connect After Scanning QR Code

Bug: I M using this WhiskeySockets library for a long time without encountering this error, but it occurred unexpectedly today.

Sample Code Of Qr:

import makeWASocket, { DisconnectReason, BufferJSON, useMultiFileAuthState } from '@whiskeysockets/baileys'
import { Boom } from '@hapi/boom'

async function connectToWhatsApp () {
    const { state, saveCreds } = await useMultiFileAuthState('auth_info_baileys')

    const sock = makeWASocket({
        auth: state,
        printQRInTerminal: true, 
    });

    sock.ev.on('creds.update', saveCreds)

    sock.ev.on('connection.update', (update) => {
        const { connection, lastDisconnect } = update
        if (connection === 'close') {
            const shouldReconnect = (lastDisconnect?.error as Boom)?.output?.statusCode !== DisconnectReason.loggedOut
            console.log('Connection closed due to', lastDisconnect?.error, ', reconnecting', shouldReconnect)
            if (shouldReconnect) {
                connectToWhatsApp() // Reconnect if necessary
            }
        } else if (connection === 'open') {
            console.log('Opened connection')
        }
    });

    sock.ev.on('messages.upsert', m => {
        console.log("Message Received: " + m.messages[0].key.remoteJid);
    });

}

connectToWhatsApp()

To Reproduce:

  1. Create a new connection.
  2. Scan the QR code.
  3. Observe the connection failure.

Expected Behavior: After scanning the QR code, the connection should be established successfully, allowing communication with WhatsApp.

Environment:

  • Running on a local machine.
  • connectOptions:
    • makeWASocket({ auth: state, printQRInTerminal: true, });
  • No multiple clients on the same IP.
  • Not using a proxy.

Additional Context:

  • The issue occurs consistently, leading to a failure to establish a connection with WhatsApp.
  • The behavior was observed while attempting to connect to WhatsApp using the Baileys library.
  • The code logic is correct, but the connection fails after scanning the QR code.

About this issue

  • Original URL
  • State: closed
  • Created 3 months ago
  • Reactions: 18
  • Comments: 96 (6 by maintainers)

Commits related to this issue

Most upvoted comments

Till it gets merged you can try using this branch -> https://github.com/WhiskeySockets/Baileys/tree/fix-516

Temporary solution: downgrade to Baileys v5.0.0

Procedure to downgrade if you are using Arrocy Whatsapp Gateway:

  1. download https://registry.npmjs.org/@adiwajshing/baileys/-/baileys-5.0.0.tgz
  2. upload to Arrocy Whatsapp Gateway node server root, extract, you will get a new folder “package”
  3. rename original “Baileys” folder to “Baileys-v6.6.0” (just for back up if you want to change back)
  4. rename “package” folder to “Baileys”
  5. restart nodejs
  6. Done!

Hello team, my full support to you

yes i have 45 previously connected +91 numbers without No issue, Issue with new number connectivity.

I see this issue only in baileys library other library working 100% perfectly i tested on 3 other scripts not using baileys. So no whatsapp server side filter or country restriction or planning to stop unofficial whatsapp etc. Let’s wait for baileys master mind to resolve this.

Yah bro i fix inrl ban issue today but, this issue ☕

Yaa am also faceing this issue in new connection…!!

Ok, I tested with +254 number (@V-E-N-O-X brought up having the same issue with them) that has not been used before on few different servers and had no problems. I still cannot reproduce this unfortunately. I’ll try to find a number from India that I can use to test.

demo

yes you are correct its working fine. Please answer a couple of doubts:- a:- are you using any proxy in baileys ? b:- which file you changed from old Baileys 5.0.0

Thanks

a. yes, using proxyscrape.com b. no change, direct replacement. Baileys-v6 folder -> replace with ->Baileys-v5 folder

Thanknyou for the quick response. Can i have your proxy connection method. And is it working your side without using proxy too ?

const { ProxyAgent } = require('proxy-agent');
let agent, proxyUrls, proxyUrl, proxyLength, rand;

const fetchProxyScrape = async () => {
  try {
    const proxyScrape = await fetch('https://api.proxyscrape.com/v2/?request=displayproxies&protocol=http&timeout=10000&country=in&ssl=no&anonymity=all');
    const proxyText = await proxyScrape.text();
    proxyUrls = proxyText.split('\r\n').filter(Boolean);
    proxyLength = proxyUrls.length;
  } catch (error) {
    console.log('FREE PROXYSCRAPE ERROR', error);
  }
};
fetchProxyScrape();

const startSock = async() => {
  if (proxyLength > 0) {
    rand = Math.floor(Math.random() * Math.floor(proxyLength));
    proxyUrl = 'http://' + proxyUrls[rand];
    agent = new ProxyAgent(proxyUrl);
  }
  const { state, saveCreds } = await useMultiFileAuthState('baileys_auth_info')
	const { version, isLatest } = await fetchLatestBaileysVersion()
	console.log(`using WA v${version.join('.')}, isLatest: ${isLatest}`)

	const sock = makeWASocket({
                agent,
		version,
		logger,
		printQRInTerminal: !usePairingCode,
		mobile: useMobile,
		auth: {
			creds: state.creds,
			keys: makeCacheableSignalKeyStore(state.keys, logger),
		},
		msgRetryCounterCache,
		generateHighQualityLinkPreview: true,
		getMessage,
	})

	store?.bind(sock.ev)

  // the rest of the codes here
}
startSock();

demo

yes you are correct its working fine. Please answer a couple of doubts:- a:- are you using any proxy in baileys ? b:- which file you changed from old Baileys 5.0.0

Thanks

a. yes, using proxyscrape.com b. no change, direct replacement. Baileys-v6 folder -> replace with ->Baileys-v5 folder

Thanknyou for the quick response. Can i have your proxy connection method. And is it working your side without using proxy too ?

Yes without proxy working and all old devices will be stay connected

demo

yes you are correct its working fine. Please answer a couple of doubts:- a:- are you using any proxy in baileys ? b:- which file you changed from old Baileys 5.0.0

Thanks

a. yes, using proxyscrape.com b. no change, direct replacement. Baileys-v6 folder -> replace with ->Baileys-v5 folder

It’s a issue related login to foreign country yesterday I checked with my pair when I try to login with that hosted on koyeb it’s disconnected my device and when I’m try after turn on in Termux it’s connected successfully

https://pastebin.com/ETS58vQJ check here package.json file uses

Thank you. This is i know what it should be let me try and get back to you here. You may now remove the link 😃

I dont know more about which library they are using but i can provide script link so you can check

Thank you for quick reply please mention the link. i know one other script but that uses RAM a lot like 700-800MB ram per instance. Still please mention the script link

I think only Indian numbers/accounts are facing this issue rn. Tested on other regions, no issues! Seems strange 😕

Yes true, just tested it after your message. Indian numbers not working. Other country’s numbers working fine.

I do not have access to an Indian number at the moment so I cannot test myself. I asked around from few people and they did not have any problems with Indian numbers? Have you tested another host and are you using official wa on device that is not unlocked etc?

It works in other PC, also it works in browser from that PC too. Only baileys doesn’t work. Tried official android Whatsapp normal beta and iphone whatsapp business.

Tested yesterday logging in multiple times on both ios and android (normal & business) with no issue. Region related / specific host platform or just outdated software as mentioned on here?

Hey, after testing with multiple devices i found that the issue seems with the ip address when anyone uses Indian number with a new ip it works fine. As you mentioned that you dont have Indian number access i can help you to have one to test it and solve the problem for the world. I had one more question i used the proxy url in order to connect baileys however i was not getting the connection done using proxy i wonder why.

yah! i tested on my accs its working but in other country like +91,+254 having this error, looks what dumb me thinking my scanner got outdated 🤣

It’s Also Working For Me feeling Sad For +91

I think only Indian numbers/accounts are facing this issue rn. Tested on other regions, no issues! Seems strange 😕

Yes true, just tested it after your message. Indian numbers not working. Other country’s numbers working fine.

Meta has started to fight against unofficial libraries I guess. The starting may be from India as there are a major no. of Indian users. Edit: It’s just my assumption, I’m not a piro!

I think only Indian numbers/accounts are facing this issue rn. Tested on other regions, no issues! Seems strange 😕