# Respond to the person who used the command (Js)

**URL:** <https://discuss.dev.twitch.com/t/respond-to-the-person-who-used-the-command-js/32958>\
**Category:** Chat and IRC\
**Created:** [August 4, 2021, 9:37pm UTC](https://discuss.dev.twitch.com/t/respond-to-the-person-who-used-the-command-js/32958 "2021-08-04T21:37:00Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Uharuke\_tv](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/uharuke_tv/32/13066_2.png) [@Uharuke\_tv](https://discuss.dev.twitch.com/u/Uharuke_tv)\
**Post date:** [August 4, 2021, 9:37pm UTC](https://discuss.dev.twitch.com/t/respond-to-the-person-who-used-the-command-js/32958/1 "2021-08-04T21:37:00Z")

</div>

Good morning ! Did you know how to make my bot respond to the person who used the command?

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [August 4, 2021, 9:37pm UTC](https://discuss.dev.twitch.com/t/respond-to-the-person-who-used-the-command-js/32958/2 "2021-08-04T21:37:34Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Uharuke\_tv](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/uharuke_tv/32/13066_2.png) [@Uharuke\_tv](https://discuss.dev.twitch.com/u/Uharuke_tv)\
**Post date:** [August 4, 2021, 9:38pm UTC](https://discuss.dev.twitch.com/t/respond-to-the-person-who-used-the-command-js/32958/3 "2021-08-04T21:38:37Z")

</div>

oh ! thx but I’m a debutant , how to do it ?

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [August 4, 2021, 9:39pm UTC](https://discuss.dev.twitch.com/t/respond-to-the-person-who-used-the-command-js/32958/4 "2021-08-04T21:39:56Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Uharuke\_tv](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/uharuke_tv/32/13066_2.png) [@Uharuke\_tv](https://discuss.dev.twitch.com/u/Uharuke_tv)\
**Post date:** [August 4, 2021, 9:41pm UTC](https://discuss.dev.twitch.com/t/respond-to-the-person-who-used-the-command-js/32958/5 "2021-08-04T21:41:21Z")

</div>

lab ? How i add it ? Thank you so much !

---

<div class="post-metadata">

**Author:** ![Uharuke\_tv](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/uharuke_tv/32/13066_2.png) [@Uharuke\_tv](https://discuss.dev.twitch.com/u/Uharuke_tv)\
**Post date:** [August 4, 2021, 9:42pm UTC](https://discuss.dev.twitch.com/t/respond-to-the-person-who-used-the-command-js/32958/6 "2021-08-04T21:42:09Z")

</div>

lib\*

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [August 4, 2021, 9:42pm UTC](https://discuss.dev.twitch.com/t/respond-to-the-person-who-used-the-command-js/32958/7 "2021-08-04T21:42:15Z")

</div>

> [@Uharuke\_tv](#):
>
> Did you know how to make my bot

Suggests you already have a working bot that requires modiciation

> [@Uharuke\_tv](#):
>
> how to make my bot respond to the person who used the command?

Can’t answer this without seeing your code

---

<div class="post-metadata">

**Author:** ![Uharuke\_tv](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/uharuke_tv/32/13066_2.png) [@Uharuke\_tv](https://discuss.dev.twitch.com/u/Uharuke_tv)\
**Post date:** [August 4, 2021, 9:45pm UTC](https://discuss.dev.twitch.com/t/respond-to-the-person-who-used-the-command-js/32958/8 "2021-08-04T21:45:39Z")

</div>

```javascript
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

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [August 4, 2021, 9:48pm UTC](https://discuss.dev.twitch.com/t/respond-to-the-person-who-used-the-command-js/32958/9 "2021-08-04T21:48:09Z")

</div>

I have revoked your leaked access token

**NEVER** post your oAuth token publically.

For TMI.js please refer to the TMI.js documentation

[https://tmijs.com/](https://tmijs.com/)

Which provides the following example

```auto

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

---

<div class="post-metadata">

**Author:** ![Uharuke\_tv](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/uharuke_tv/32/13066_2.png) [@Uharuke\_tv](https://discuss.dev.twitch.com/u/Uharuke_tv)\
**Post date:** [August 4, 2021, 9:50pm UTC](https://discuss.dev.twitch.com/t/respond-to-the-person-who-used-the-command-js/32958/10 "2021-08-04T21:50:07Z")

</div>

thank you so much ! I don’t think to suppr the oAuth

---

<div class="post-metadata">

**Author:** ![Uharuke\_tv](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/uharuke_tv/32/13066_2.png) [@Uharuke\_tv](https://discuss.dev.twitch.com/u/Uharuke_tv)\
**Post date:** [August 4, 2021, 10:08pm UTC](https://discuss.dev.twitch.com/t/respond-to-the-person-who-used-the-command-js/32958/11 "2021-08-04T22:08:53Z")

</div>

ReferenceError: tags is not defined

When i start the bot and I use the command my console show it  
Can you help me ?

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [August 4, 2021, 10:10pm UTC](https://discuss.dev.twitch.com/t/respond-to-the-person-who-used-the-command-js/32958/12 "2021-08-04T22:10:04Z")

</div>

You use `context` in yours isntead of `tags`

So

```auto
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

```auto
function onMessageHandler (target, context, msg, self) {

```

to

```auto
function onMessageHandler (target, tags, msg, self) {

```

---

<div class="post-metadata">

**Author:** ![Uharuke\_tv](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/uharuke_tv/32/13066_2.png) [@Uharuke\_tv](https://discuss.dev.twitch.com/u/Uharuke_tv)\
**Post date:** [August 4, 2021, 10:11pm UTC](https://discuss.dev.twitch.com/t/respond-to-the-person-who-used-the-command-js/32958/13 "2021-08-04T22:11:40Z")

</div>

Thank you so much ! It’s work !

---

<div class="post-metadata">

**Author:** ![system](https://d2opxh93rbxzdn.cloudfront.net/original/2X/0/05909729875cce3b53e59d5561c4d23bb14948fc.png) [@system](https://discuss.dev.twitch.com/u/system)\
**Post date:** [September 3, 2021, 10:12pm UTC](https://discuss.dev.twitch.com/t/respond-to-the-person-who-used-the-command-js/32958/14 "2021-09-03T22:12:30Z")

</div>

Closed on September 3, 2021, 10:12pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
