hi everyone,
it’s been a while since I coded a bot on twitch that only read the messages of a channel
I would like to improve it and insert commands
I don’t think I specified the right scopes during my authentication
it seemed to me that the chat:read
and chat:edit
scopes were
here is my oauth code formatted:
https://id.twitch.tv/oauth2/authorize?
response_type=code
&client_id=<client_id>
&redirect_uri=http://localhost:3300
&scope=chat:edit+chat:read+user:edit+<other_scopes>
I have retrieved the links from this page : Getting OAuth Access Tokens | Twitch Developers
and scopes from this page : Twitch Access Token Scopes | Twitch Developers
with this authentication, i always manage to connect but my bot can’t talk
Here is my code, if the error came from this one :
const { Client } = require('tmi.js');
const oauth = {
options: {
debug: true,
clientId: clientId
},
identity: identity,
channels: channels,
connection: {
reconnect: true,
secure : true,
}
};
class Bot {
constructor() {
this.mbClient = new Client(oauth);
};
connect() {
this.mbClient.connect();
this.mbClient.on('connected', this.onConnectedHandler);
this.mbClient.on('message', this.onMessageListen);
};
onMessageListen(channel, tags, message, self) {
if (self || !message.startsWith('!')) return;
let msg = message.trim().toLowerCase(),
args = msg.slice(1).split(' '),
command = args.shift().toLowerCase();
switch (command) {
case 'ping':
this.mbClient.say(channel, 'pong')
.then(channel => console.log(channel))
.catch(e => console.log(e));
break;
};
};
};
thank you in advance for any help
[EDIT]
So it’s not a scope error or anything, it was an hour of code, no need to reply to this topic, thanks anyway
For the record, my error is in my function call :
const { Client } = require('tmi.js');
const oauth = {
options: {
debug: true,
clientId: clientId
},
identity: identity,
channels: channels,
connection: {
reconnect: true,
secure : true,
}
};
class Bot {
constructor() {
this.mbClient = new Client(oauth);
};
connect() {
this.mbClient.connect();
this.mbClient.on('connected', this.onConnectedHandler);
this.onMessageListen();
};
onMessageListen() {
this.mbClient.on('message', (channel, userstate, message, self) => {
if (self || userstate['username'] === 'mobbot' || !message.startsWith('!')) return;
let msg = message.trim().toLowerCase(),
args = msg.slice(1).split(' '),
command = args.shift().toLowerCase();
switch (command) {
case 'ping':
this.mbClient.say(channel, 'pong')
.then(channel => console.log(channel))
.catch(e => console.log(e));
break;
};
});
};
};