# Syntax Explanation

**URL:** <https://discuss.dev.twitch.com/t/syntax-explanation/4618>\
**Category:** Chat and IRC\
**Created:** [February 1, 2016, 6:37pm UTC](https://discuss.dev.twitch.com/t/syntax-explanation/4618 "2016-02-01T18:37:13Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![ab5521](https://avatars.discourse-cdn.com/v4/letter/a/d07c76/32.png) [@ab5521](https://discuss.dev.twitch.com/u/ab5521)\
**Post date:** [February 1, 2016, 6:37pm UTC](https://discuss.dev.twitch.com/t/syntax-explanation/4618/1 "2016-02-01T18:37:13Z")

</div>

Currently I am creating a bot in python I am a little bit confused on the the syntax of the github page ([https://github.com/justintv/Twitch-API/blob/master/IRC.md](https://github.com/justintv/Twitch-API/blob/master/IRC.md)) in relation to the language. I have the majority of the bot done (it connects and reads messages from chat) but I do not fully understand how this is done. My main focus is how do I read or find the names of the people in stream real time (so NAMES) and when a (new) viewer enters the channel (JOIN). If anyone can please explain these “capabilities,” as they are called in the github page, in terms of python? Thank you!!

---

<div class="post-metadata">

**Author:** ![3ventic](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/3ventic/32/298_2.png) [@3ventic](https://discuss.dev.twitch.com/u/3ventic)\
**Post date:** [February 1, 2016, 6:53pm UTC](https://discuss.dev.twitch.com/t/syntax-explanation/4618/2 "2016-02-01T18:53:46Z")

</div>

To get the JOIN/PART/NAMES, send `CAP REQ :twitch.tv/membership\r\n` on the connection before sending your `JOIN #channel`s. [More on capabilities in the IRCv3 specs](http://ircv3.net/specs/core/capability-negotiation-3.2.html).

---

<div class="post-metadata">

**Author:** ![ab5521](https://avatars.discourse-cdn.com/v4/letter/a/d07c76/32.png) [@ab5521](https://discuss.dev.twitch.com/u/ab5521)\
**Post date:** [February 1, 2016, 8:58pm UTC](https://discuss.dev.twitch.com/t/syntax-explanation/4618/3 "2016-02-01T20:58:35Z")

</div>

My code reads:  
self.socket = socket.socket()  
self.socket.connect((self.host, self.port))  
self.socket.send(“PASS {}\r\n”.format(self.passwrd).encode(“utf-8”))  
self.socket.send(“NICK {}\r\n”.format(self.nick).encode(“utf-8”))  
self.socket.send(“JOIN {}\r\n”.format(self.chan).encode(“utf-8”))  
So you are saying add:  
self.socket.send(“CAP REQ :twitch.tv/membership\r\n”.format().encode(“utf-8”))  
before JOIN? and is there anything more to it?  
Thank you for the reply!!

---

<div class="post-metadata">

**Author:** ![3ventic](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/3ventic/32/298_2.png) [@3ventic](https://discuss.dev.twitch.com/u/3ventic)\
**Post date:** [February 1, 2016, 9:16pm UTC](https://discuss.dev.twitch.com/t/syntax-explanation/4618/4 "2016-02-01T21:16:52Z")

</div>

Correct.

---

<div class="post-metadata">

**Author:** ![ab5521](https://avatars.discourse-cdn.com/v4/letter/a/d07c76/32.png) [@ab5521](https://discuss.dev.twitch.com/u/ab5521)\
**Post date:** [February 1, 2016, 9:25pm UTC](https://discuss.dev.twitch.com/t/syntax-explanation/4618/5 "2016-02-01T21:25:28Z")

</div>

Okay I see what its saying now but how do I call the NAME to get he names of the people in the chat, do i do it like:  
self.socket.send(“NAMES {}\r\n”.format(self.chan).encode(“utf-8”))?  
I think after this I can figure out the rest on my own so thank you very much for the help!

---

<div class="post-metadata">

**Author:** ![3ventic](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/3ventic/32/298_2.png) [@3ventic](https://discuss.dev.twitch.com/u/3ventic)\
**Post date:** [February 1, 2016, 9:27pm UTC](https://discuss.dev.twitch.com/t/syntax-explanation/4618/6 "2016-02-01T21:27:08Z")

</div>

You cannot explicitly request NAMES. The list is sent to you when you first join the channel, after that you need to listen to JOIN/PART to stay up to date.

---

<div class="post-metadata">

**Author:** ![ab5521](https://avatars.discourse-cdn.com/v4/letter/a/d07c76/32.png) [@ab5521](https://discuss.dev.twitch.com/u/ab5521)\
**Post date:** [February 1, 2016, 9:46pm UTC](https://discuss.dev.twitch.com/t/syntax-explanation/4618/7 "2016-02-01T21:46:09Z")

</div>

So if I am understanding you right the server will tell me when a person joins? It seems like that is the case in the example but I want to make sure.

---

<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:** [February 1, 2016, 10:51pm UTC](https://discuss.dev.twitch.com/t/syntax-explanation/4618/8 "2016-02-01T22:51:58Z")

</div>

Yes, **HOWEVER** join/parts are batched up into chunks and delivered every 10/15 seconds or so and additionally, only works for channels/chat rooms under 1000 chatters (or so)

---

<div class="post-metadata">

**Author:** ![ab5521](https://avatars.discourse-cdn.com/v4/letter/a/d07c76/32.png) [@ab5521](https://discuss.dev.twitch.com/u/ab5521)\
**Post date:** [February 1, 2016, 10:54pm UTC](https://discuss.dev.twitch.com/t/syntax-explanation/4618/9 "2016-02-01T22:54:46Z")

</div>

Chunks meaning it will list a lot of names right? and the number of people doesnt really matter for right now since its for me and a friend and we just started streaming.

---

<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:** [February 2, 2016, 9:12pm UTC](https://discuss.dev.twitch.com/t/syntax-explanation/4618/10 "2016-02-02T21:12:29Z")

</div>

Yeah sorta.

Everyone 10 seconds (or so) JTV will send all the join/parts together.

So join/parts are not in real time.

---

<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:** [March 3, 2016, 9:12pm UTC](https://discuss.dev.twitch.com/t/syntax-explanation/4618/11 "2016-03-03T21:12:45Z")

</div>

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