# How to get IRC chat user nickname

**URL:** <https://discuss.dev.twitch.com/t/how-to-get-irc-chat-user-nickname/13936>\
**Category:** API\
**Created:** [January 25, 2018, 1:18pm UTC](https://discuss.dev.twitch.com/t/how-to-get-irc-chat-user-nickname/13936 "2018-01-25T13:18:13Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![comcool](https://avatars.discourse-cdn.com/v4/letter/c/e9c0ed/32.png) [@comcool](https://discuss.dev.twitch.com/u/comcool)\
**Post date:** [January 25, 2018, 1:18pm UTC](https://discuss.dev.twitch.com/t/how-to-get-irc-chat-user-nickname/13936/1 "2018-01-25T13:18:13Z")

</div>

I am now using the IRC API.

The script was written in PHP.

The information I receive is : comcool! [comcool.sso.twitch.TV](http://comcool.sso.twitch.TV) PRIVG # \*\*\*\*\*:bot  
It is information that

How can I get a nickname from the user?

---

<div class="post-metadata">

**Author:** ![george](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/george/32/120_2.png) [@george](https://discuss.dev.twitch.com/u/george)\
**Post date:** [January 25, 2018, 2:26pm UTC](https://discuss.dev.twitch.com/t/how-to-get-irc-chat-user-nickname/13936/2 "2018-01-25T14:26:37Z")

</div>

Nick is the part part leading up to the exclamation point. In your example it’s “comcool”. Most IRC libraries will parse it out for you. If you are not using a library you’ll have to parse it manually.

---

<div class="post-metadata">

**Author:** ![comcool](https://avatars.discourse-cdn.com/v4/letter/c/e9c0ed/32.png) [@comcool](https://discuss.dev.twitch.com/u/comcool)\
**Post date:** [January 25, 2018, 2:45pm UTC](https://discuss.dev.twitch.com/t/how-to-get-irc-chat-user-nickname/13936/4 "2018-01-25T14:45:52Z")

</div>

comcool! [comcool.sso.twitch.tv](http://comcool.sso.twitch.tv)  
-\> comcool is my id TT

---

<div class="post-metadata">

**Author:** ![Six](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/six/32/2334_2.png) [@Six](https://discuss.dev.twitch.com/u/Six)\
**Post date:** [January 25, 2018, 3:51pm UTC](https://discuss.dev.twitch.com/t/how-to-get-irc-chat-user-nickname/13936/5 "2018-01-25T15:51:24Z")

</div>

Like @george pointed out, the `nick` of a user is the text leading up to the exclamation point. To give a little more detail on the structure, turn to the RFC 1459 [spec](https://tools.ietf.org/html/rfc1459.html#section-2.3.1).

The `nick` is located within the `prefix`, if one exists. The general structure being:

```auto
<server_or_nick>!<user>@<host>

```

When a prefix is present, the `<server_or_nick>`is always included, where as both the `<user>` and `<host>` are optional and may not be present. If `<user>` is included it will be prefixed by `!`, and if `<host>` is included it will be prefixed with `@`. In the case of Twitch and ingesting chat messages, I’ve always seen the full prefix included in the message.

On a side note, is the data you posted the _exact_ data that was ingested? Because the prefix, command, and parameters look malformed.

---

<div class="post-metadata">

**Author:** ![comcool](https://avatars.discourse-cdn.com/v4/letter/c/e9c0ed/32.png) [@comcool](https://discuss.dev.twitch.com/u/comcool)\
**Post date:** [January 25, 2018, 4:41pm UTC](https://discuss.dev.twitch.com/t/how-to-get-irc-chat-user-nickname/13936/6 "2018-01-25T16:41:26Z")

</div>

thanks. but my log is “:userId!userId@userID.tmi.twitch.tv PRIVMSG #channel : message”

i don’t know fix it…

---

<div class="post-metadata">

**Author:** ![comcool](https://avatars.discourse-cdn.com/v4/letter/c/e9c0ed/32.png) [@comcool](https://discuss.dev.twitch.com/u/comcool)\
**Post date:** [January 25, 2018, 4:46pm UTC](https://discuss.dev.twitch.com/t/how-to-get-irc-chat-user-nickname/13936/7 "2018-01-25T16:46:25Z")

</div>

i get log php script in fgets($this-\>socket).

---

<div class="post-metadata">

**Author:** ![Six](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/six/32/2334_2.png) [@Six](https://discuss.dev.twitch.com/u/Six)\
**Post date:** [January 25, 2018, 4:55pm UTC](https://discuss.dev.twitch.com/t/how-to-get-irc-chat-user-nickname/13936/8 "2018-01-25T16:55:55Z")

</div>

Hm, Twitch must have updated their prefix format. Regardless, the information you want is the data between the colon and the exclamation point.

---

<div class="post-metadata">

**Author:** ![comcool](https://avatars.discourse-cdn.com/v4/letter/c/e9c0ed/32.png) [@comcool](https://discuss.dev.twitch.com/u/comcool)\
**Post date:** [January 25, 2018, 6:57pm UTC](https://discuss.dev.twitch.com/t/how-to-get-irc-chat-user-nickname/13936/9 "2018-01-25T18:57:29Z")

</div>

omg… my mistake…  
I added this and the value comes in.

> CAP REQ :twitch.tv/tags twitch.iv/commands [Twitch](http://twitch.tv/memberships)

very very Thanks.  
Thanks ur reply

---

<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:** [February 24, 2018, 6:57pm UTC](https://discuss.dev.twitch.com/t/how-to-get-irc-chat-user-nickname/13936/10 "2018-02-24T18:57:45Z")

</div>

Closed on February 24, 2018, 6:57pm UTC

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