# Not recieving a Viewerlist from Twitch

**URL:** <https://discuss.dev.twitch.com/t/not-recieving-a-viewerlist-from-twitch/9013>\
**Category:** API\
**Created:** [January 24, 2017, 11:01pm UTC](https://discuss.dev.twitch.com/t/not-recieving-a-viewerlist-from-twitch/9013 "2017-01-24T23:01:48Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gabriel\_Dickert](https://avatars.discourse-cdn.com/v4/letter/g/b5ac83/32.png) [@Gabriel\_Dickert](https://discuss.dev.twitch.com/u/Gabriel_Dickert)\
**Post date:** [January 24, 2017, 11:01pm UTC](https://discuss.dev.twitch.com/t/not-recieving-a-viewerlist-from-twitch/9013/1 "2017-01-24T23:01:48Z")

</div>

Hello people,  
First of all i want to point out that I am fairly new to Java and programming so I am not really experiended with these kind of projects.  
Anyway,latley I have been playing around with creating an Twitch IRC Bot made with Java and the PircBot Libaray.  
I can sucessfully connect to the chatroom in my channel and also send message if someone for example types commands like “!time.” in the chat.  
I want to improve the bot with adding a Point System for the viewers.The Problem I have is, i cant get a correct Viewerlist from my channel. I using a testaccount and my twitchbot so i should get back a String array of 1 in theory but my array is always empty.

This is my code to recieve the viewerlist:

public String[] getUsersAsStringArray(String channel) {  
User[] userArray = getUsers(channel);  
int mLength = userArray.length;  
String[] users = new String[mLength];  
for (int i = 0; i \< mLength; i++) {  
users[i] = userArray[i].getPrefix() + userArray[i].getNick();  
users[i]=users[i]+userArray[i].getNick();  
System.out.println(users[i]);  
}  
System.out.println(mLength+" length of array");

```
    return users;
}

```

I cant figure out what I am doing wrong maybe you can help me would be very nice:)

---

<div class="post-metadata">

**Author:** ![Larklen](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/larklen/32/2138_2.png) [@Larklen](https://discuss.dev.twitch.com/u/Larklen)\
**Post date:** [January 24, 2017, 11:24pm UTC](https://discuss.dev.twitch.com/t/not-recieving-a-viewerlist-from-twitch/9013/2 "2017-01-24T23:24:19Z")

</div>

You would need to post the `getUsers()` function block before someone could attempt to help, as that function appears to be filling the userArray with the users in the first place.

---

<div class="post-metadata">

**Author:** ![matt\_thomas](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/matt_thomas/32/710_2.png) [@matt\_thomas](https://discuss.dev.twitch.com/u/matt_thomas)\
**Post date:** [January 24, 2017, 11:26pm UTC](https://discuss.dev.twitch.com/t/not-recieving-a-viewerlist-from-twitch/9013/3 "2017-01-24T23:26:45Z")

</div>

On IRC clients the viewer list is populated from /NAMES and JOIN/PART messages. TMI does JOIN/PART messages in a batch every 30 seconds or so.

To get membership state event (NAMES, JOIN, PART, or MODE) functionality. You need to execute:

> CAP REQ :twitch.tv/membership

upon connect.

/NAMES is only executed on your join to the channel, but will not list everyone if the channel is large(1000+) in which case it will only populate the moderators and streamer.

You could try polling the unofficial/unsupported TMI API, [https://tmi.twitch.tv/group/user/:CHANNEL:/chatters](https://tmi.twitch.tv/group/user/:CHANNEL:/chatters) to get the information you need.

Also, you may want to look at: [Pircbot, problems with retrieving a full userList. Java - #2 by 3ventic](https://discuss.dev.twitch.com/t/pircbot-problems-with-retrieving-a-full-userlist-java/6202/2)

---

<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, 2017, 12:48am UTC](https://discuss.dev.twitch.com/t/not-recieving-a-viewerlist-from-twitch/9013/4 "2017-01-25T00:48:42Z")

</div>

Like @matt_thomas said, we would need to see ` GetUsers()` to see exactly how you are attempting to get the users.

Also, the official API does not natively support a way to get a viewer list through an endpoint. You get a list of all current viewers when you join a channel and `membership` is requested on login. However, this only happens one time. Furthermore, when a channel has over 1000 viewers it will only return a list of viewers who have `op` status.

Another way would be to monitor `JOIN` and `PART` with `membership` requested at login. However, this is also unreliable because at random times it will say a person has left a chat room when they actually didn’t leave, only to be added back after a few minutes. These notices are also only sent once every few minutes in general, so you could be awarding/not awarding points to the correct people.

The only other option would be to use third party API’s like @matt_thomas said. However since these are third party, it would be up to the independent developer to maintain the API and could stop working at any point in time.

---

<div class="post-metadata">

**Author:** ![Gabriel\_Dickert](https://avatars.discourse-cdn.com/v4/letter/g/b5ac83/32.png) [@Gabriel\_Dickert](https://discuss.dev.twitch.com/u/Gabriel_Dickert)\
**Post date:** [January 25, 2017, 6:15pm UTC](https://discuss.dev.twitch.com/t/not-recieving-a-viewerlist-from-twitch/9013/5 "2017-01-25T18:15:54Z")

</div>

First of all thank you all for your help I really appreciate it.

Well, I am obviously using the GetUsers method from the Pircbot library:

> public final User getUsers(String channel) {  
> channel = channel.toLowerCase();  
> User userArray = new User[0];  
> synchronized (\_channels) {  
> Hashtable users = (Hashtable) \_channels.get(channel);  
> if (users != null) {  
> userArray = new User[users.size()];  
> Enumeration enumeration = users.elements();  
> for (int i = 0; i \< userArray.length; i++) {  
> User user = (User) enumeration.nextElement();  
> userArray[i] = user;  
> }  
> }  
> }  
> return userArray;  
> }

---

<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, 2017, 6:16pm UTC](https://discuss.dev.twitch.com/t/not-recieving-a-viewerlist-from-twitch/9013/6 "2017-02-24T18:16:04Z")

</div>

Closed on February 24, 2017, 6:16pm UTC

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