兄弟,这是一个编程熟练问题,
你可以试试两个object instance, 从starter-bot.js:
假如有
const { Wechaty } = require('wechaty')
function onScan (qrcode, status) {...}
function onLogin (user) {...}
function onLogout(user) {...}
async function onMessage (msg) {...}
让后在bot后面写这个:
const bot = new Wechaty()
bot.on('scan', onScan)
bot.on('login', onLogin)
bot.on('logout', onLogout)
bot.on('message', onMessage)
bot.start()
.then(() => console.log('Starter Bot Started.'))
.catch(e => console.error(e))
//bot2
const bot2 = new Wechaty()
bot2.on('scan', onScan)
bot2.on('login', onLogin)
bot2.on('logout', onLogout)
bot2.on('message', onMessage)
bot2.start()
.then(() => console.log('Starter Bot2 Started.'))
.catch(e => console.error(e))
会有可能很难分别bot和bot2的console.log, 但也有些其它解决方法,慢慢一起学咯~
谢谢, 已经解决了,一用户名为键 存到了一个全局对象中,每个用户对应一个机器人
Most helpful comment
兄弟,这是一个编程熟练问题,
你可以试试两个object instance, 从starter-bot.js:
假如有
让后在bot后面写这个:
会有可能很难分别bot和bot2的console.log, 但也有些其它解决方法,慢慢一起学咯~