Good morning ! Did you know how to make my bot respond to the person who used the command?
Twitch Chat is IRC
So just parse out the username from the incoming chat message and include that in your message that you send to chat.
oh ! thx but I’m a debutant , how to do it ?
Depends on what code you have currently.
I don’t know what lib you are using to parse chat or even if using a lib at all.
lab ? How i add it ? Thank you so much !
lib*
Suggests you already have a working bot that requires modiciation
Can’t answer this without seeing your code
const tmi = require('tmi.js');
const client = new tmi.Client({
options: { debug: true },
identity: {
username: 'beebot_v1',
password:
},
channels: [ 'smobee_' ]
});
// Register our event handlers (defined below)
client.on('message', onMessageHandler);
client.on('connected', onConnectedHandler);
client.connect();
client.on('connected', (address, port) => {
client.action('smobee_', 'BeeBot est connecté ! VoHiYo');
});
function onMessageHandler (target, context, msg, self) {
if (self) { return; } // Ignore messages from the bot
const commandName = msg.trim();
if (commandName === '!hnum') {
const num = rollDice();
client.say(target, `ID USER as tiré un ${num} !`);
console.log(`* Executed ${commandName} command`);
} else {
console.log(`* Commande inconnue ${commandName}`);
}
}
function rollDice () {
const sides = 6;
return Math.floor(Math.random() * sides) + 1;
}
function onConnectedHandler (addr, port) {
console.log(`* Connecté à ${addr}:${port}`);
}
ID USER it’s for id the user who used the command
I have revoked your leaked access token
NEVER post your oAuth token publically.
For TMI.js please refer to the TMI.js documentation
Which provides the following example
client.on('message', (channel, tags, message, self) => {
// "Alca: Hello, World!"
console.log(`${tags['display-name']}: ${message}`);
});
Use either
tags.username
or
tags['display-name']}
as needed
thank you so much ! I don’t think to suppr the oAuth
ReferenceError: tags is not defined
When i start the bot and I use the command my console show it
Can you help me ?
You use context
in yours isntead of tags
So
function onMessageHandler (target, context, msg, self) {
if (self) { return; } // Ignore messages from the bot
const commandName = msg.trim();
if (commandName === '!hnum') {
const num = rollDice();
client.say(target, `ID USER as tiré un ${num} !`);
console.log(`* Executed ${commandName} command`);
} else {
console.log(`* Commande inconnue ${commandName}`);
}
}
Change
function onMessageHandler (target, context, msg, self) {
to
function onMessageHandler (target, tags, msg, self) {
Thank you so much ! It’s work !
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.