TwitchLib / TwitchLib.Unity

TwitchLib repository representing all code belonging to the implementation of TwitchLib for Unity. Maintained primarily by LuckyNoS7evin.
164 stars 33 forks source link

Cannot connect to channel? #35

Closed glitchto closed 6 years ago

glitchto commented 6 years ago

"BadStateExeption: Must be connected to at least one channel." at event, even with provided client class, correct initialization, non capitalized channel names, double checked keys.

swiftyspiffy commented 6 years ago

Can you share your code?

glitchto commented 6 years ago

I first followed the tutorial by HonestDanGames you linked, after I used your class "Chat Client for Unity" which by the way has these variables missing "Args" from their name's end: TwitchLib.Client.Events.OnJoinedChannel TwitchLib.Client.Events.OnChatCommandReceived ... have passed correct params:

public class TwitchCL : MonoBehaviour
{
    private Client _client;
    private string channelName = "mychannel"; //privacy
    private string botName = "mychannelbot";
    void Start()
    {
        //Set to run in minimized mode
        Application.runInBackground = true;
        //Create Credentials instance
        ConnectionCredentials credentials = new ConnectionCredentials(botName, Secrets.botAccessToken);
        //Create new instance of Chat Client
        _client = new Client();
        _client.Initialize(credentials, channelName);
        _client.OnMessageReceived += _client_OnMessageReceived; ;
        _client.Connect();
    }

Edits: sorry, I'm not familiar with this code insert

swiftyspiffy commented 6 years ago

That code looks like it’d work in the normal (not unity) library. You might also try listening to OnConnected, OnJoinedChannel, and OnSendReceiveData events. The latter will fire every time a piece of data is received from Twitch, and is great for debugging problems.

Other than that, you’ll probably have to wait for Lucky to respond

RRickkert commented 6 years ago

Could you provide your Unity version? As of Unity 2018 the TwitchClient is no longer functional. See: https://fogbugz.unity3d.com/default.asp?1045497_7ifkb9kvjpn7113n This might also be the case for some later versions of Unity 2017. This bug report is specifically for WebSocket4Net, however, TwitchLib's client uses that in the background, so it won't work.

I created a Unity package which you an import into any empty unity project, press play, and it should show "opened" in the log. If it doesn't that means your Unity version won't work with TwitchLib's Client: https://cdn.discordapp.com/attachments/415976614954795018/458754439793213453/WebSocket4Net_Unity_TestPackage.unitypackage

glitchto commented 6 years ago

Hello, I do have the latest Unity installed, yes. Your package link is dead for me. Should I revert Unity and for what version? Or is there another way? Thank you.

RRickkert commented 6 years ago

I just noticed it didn't work, trying to fix it D:

RRickkert commented 6 years ago

Can you try to just copy paste the link instead? It works here. Github doesn't like links for whatever reason? If you indeed have the latest version, you'll have to revert to an older version sadly..

glitchto commented 6 years ago

What exact version would you recommend?

glitchto commented 6 years ago

Would you recommend other API that works without uninstalling Unity?

RRickkert commented 6 years ago

From the official releases, I can confirm working:

From the beta releases, I can confirm working:

From the official releases, I can confirm broken:

From the official releases, I can confirm broken:

So personally I would recommend the latest version of Unity 2017 for now, which has LTS (long term support).

I can also recommend installing the Unity Hub, to easily manage your Unity versions, so it makes it easier to have multiple versions installed, and switching between them is much easier.

As for any other API. the TwitchLib.API module should work just fine. It's just the TwitchLib.Client which is broken. For any other Twitch chat bot client, I don't know any.

glitchto commented 6 years ago

Thanks, I do have Unity Hub, see if 2017.4.6f1 (LTS) does it.

glitchto commented 6 years ago

Installed, works like charm. Thank you !

RRickkert commented 6 years ago

See issue #36 for more information

swiftyspiffy commented 6 years ago

Will go ahead and close this. Feel free to reopen as necessary.