No error, no exception, code doesn't work though

Hi,

I’m working on a C# bot with the 1.2.5 version of TwitchLib. (No, I can’t use a newer one.) So far all I’m trying to do is connect to a channel.
Here’s my code:

	static TwitchClient client;

	static void TwitchConnect()
		{
		ConnectionCredentials credentials = new ConnectionCredentials("<name>", "<authentication token here>");
		Console.WriteLine(0);
		client = new TwitchClient(credentials, "zoliking");
		Console.WriteLine(1);

		client.OnConnected += sayHi;

		client.Connect();
		Console.WriteLine(3);
		}

	private static void sayHi(object sender, TwitchClient.OnConnectedArgs e)
		{
		Console.WriteLine(2);
		}

This runs, but apparently Connect() is just not happening. There is no error message, no exception thrown, the code just runs past it. The Twitch user for the bot doesn’t show in the list of users in Twitch chat, sayHi is never called, etc. Any advice on how to debug this?

Thanks a million :slight_smile: ,
zoliking

I tried replacing the authentication token with random nonsense to see what kind of an error would pop up if I did that, but the software behaved the same as with the actual token. This leads me to think that the older version of the API might require a different token? Thoughts?

Hi! Version 1.2.5 is like 5 years old. Is there a specific reason you can’t use something newer? If you have a reason, we might be able to figure something out.

For your code, it’d be something like:

static TwitchClient client;

static void TwitchConnect() {
    ConnectionCredentials credentials = new ConnectionCredentials("<name>", "<authentication token here>");
    client = new TwitchClient(credentials, "zoliking");
    client.OnJoinedChannel += sayHi;
    client.OnConnected += onConnected;
    client.Connect();
}

private static void onConnected(object sender, TwitchClient.OnConnectedArgs e) {
    Console.WriteLine("Connected!");
}

private static void sayHi(object sender, TwitchClient.OnJoinedChannelArgs e) {
    client.SendMessage("zoliking", "Hey there!");
}

This code is probably wrong because I barely remember the structure of the library in 2016.

Yeah, starting with 1.2.6 TwitchLib uses websockets, which won’t run on my machine. It’s a huge bummer. And yeah, I understand that it’s probably not easy to recall what things were like forever ago even if you worked with it. Thanks for the response though :slight_smile:

Huh, interesting.

Have you tried setting the protocol when instantiating the client to use TCP instead of websockets (the default behavior is websockets)? Using 3.2.0:

    class Program
    {
        private static TwitchLib.Client.TwitchClient client;
        static void Main(string[] args)
        {
            client = new TwitchLib.Client.TwitchClient(protocol: TwitchLib.Client.Enums.ClientProtocol.TCP);
            client.Initialize(new TwitchLib.Client.Models.ConnectionCredentials("swiftyspiffy", "<auth token>"), "swiftyspiffy");
            client.OnConnected += Client_OnConnected;
            client.OnJoinedChannel += Client_OnJoinedChannel;
            client.OnLog += Client_OnLog;
            client.Connect();
            Console.ReadLine();
        }

        private static void Client_OnLog(object sender, TwitchLib.Client.Events.OnLogArgs e)
        {
            Console.WriteLine($"[LOG] {e.Data}");
        }

        private static void Client_OnJoinedChannel(object sender, TwitchLib.Client.Events.OnJoinedChannelArgs e)
        {
            Console.WriteLine($"Joined channel {e.Channel}");
        }

        private static void Client_OnConnected(object sender, TwitchLib.Client.Events.OnConnectedArgs e)
        {
            Console.WriteLine($"Connected!");
        }

    }
1 Like

I didn’t realize that was a possibility :open_mouth: (when I asked in another thread the best advice I got was to downconvert to an older version :D) Sounds awesome, I’ll try it right now. Thank you so much. If this works I’ll owe you a big one!

Alright, you did save me big time there, but the issue persists. Either I’m doing the wrong thing to obtain the token, or the IRC through TCP thing that’s already going on is interfering. At least I have some ideas where to go from here. Thank you so much again!
Oh, and btw, the blind dumbass I am, I just noticed that you’re the same guy who made the TwitchLib library in the first place, thank you for that too. It’s great stuff, I just need to learn to use it. <3 If you ever need anything let me know.

EDIT: I generated a new token and now it works! I’m so happy!!! Thank you so much!

1 Like

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