【发布时间】:2021-12-19 23:36:48
【问题描述】:
我尝试检查 twitch 聊天令牌的有效性并根据它返回 true 或 false。如果我要求一个不正确的令牌,它会起作用,但是一旦我要求一个有效的令牌,我就没有得到任何回报。我就是想不通我做错了什么
const tmi = require('tmi.js');
function checkToken(name, token, callback) {
var errLogs = '';
const client = new tmi.client({
identity: {
username: name,
password: token
},
channels: ['channel']
});
client.connect()
.catch(error => {
console.log(error)
if (error) {
console.log('FAILED')
errLogs = 'error';
//return false;
} else {
console.log('VALID')
errLogs = 'valid';
//return true;
}
callback(errLogs);
})
}
checkToken('username', 'oauth:XXXX...', function(res) {
if (res) {
console.log(res + ' TOKEN FAILED')
///... token is not Valid
} else {
console.log(res + ' TOKEN VALID')
///... token is Valid
}
})
【问题讨论】:
标签: javascript twitch