How to retrieve proper username capitalization and user privileges in Twitch chat integration

I’m working on a Unity project that connects to Twitch IRC chat using a custom class. Everything works fine for basic chat functionality, but I’m running into two specific problems that I can’t find good documentation for.

First problem is that all usernames come through in lowercase only, even when the actual Twitch username has mixed case letters. I need to get the proper capitalization for display purposes.

Second issue is that I can’t figure out how to detect user roles like moderators, subscribers, or VIPs from the IRC messages. The role detection isn’t super urgent but the username capitalization is really important for my project.

Has anyone dealt with this before? Is there a way to get properly formatted usernames through IRC or do I need to use a different approach?

using System;
using System.IO;
using System.Net.Sockets;
using UnityEngine;

public class TwitchIrcClient : MonoBehaviour
{
    public TwitchCredentials credentials = new();
    
    public event Action<string, string> OnMessageReceived;
    public event Action<string> OnConnected;
    public event Action OnDisconnected;
    
    private TcpClient client;
    private StreamReader streamReader;
    private StreamWriter streamWriter;
    
    private const string SERVER = "irc.chat.twitch.tv";
    private const int PORT = 6667;
    
    public void EstablishConnection()
    {
        client = new TcpClient(SERVER, PORT);
        streamReader = new StreamReader(client.GetStream());
        streamWriter = new StreamWriter(client.GetStream());
        
        streamWriter.WriteLine("PASS " + credentials.Token);
        streamWriter.WriteLine("NICK " + credentials.Username.ToLower());
        streamWriter.WriteLine("JOIN #" + credentials.ChannelName.ToLower());
        streamWriter.Flush();
    }
    
    private void Update()
    {
        if (client?.Available > 0)
        {
            string rawMessage = streamReader.ReadLine();
            
            if (rawMessage.Contains("PRIVMSG"))
            {
                int userEnd = rawMessage.IndexOf("!");
                string username = rawMessage.Substring(1, userEnd - 1);
                
                int messageStart = rawMessage.IndexOf(":", 1);
                string chatMessage = rawMessage.Substring(messageStart + 1);
                
                OnMessageReceived?.Invoke(username, chatMessage);
            }
        }
    }
}

I encountered the same issue while developing my Twitch integration. Utilizing IRC tags is essential for getting the correct username capitalization. However, it’s important to request both twitch.tv/tags and twitch.tv/commands capabilities after initial connection. This way, when you join a channel, you’ll receive valuable information in the raw messages, including @display-name=FormattedName;badges=. Always check the display-name first for correct capitalization, and if it’s not available, default to the username from the message. This method has worked effectively for me.

Yeah, the IRC capabilities approach others mentioned works great, but here’s another tip. When requesting capabilities, watch out for the tags parsing - it’s trickier than it looks. The display-name tag often comes back empty, especially for users without custom names. You’ll need to capitalize the username’s first letter yourself as a fallback. For badges, check the badges tag - it’s comma-separated key/value pairs like ‘moderator/1,subscriber/12’. I built a simple parser that splits on semicolons first, then equals signs to create a dictionary of all tags. Way cleaner than doing string manipulation every single time you need display-name or badges.

you gotta enable Twitch IRC tags by sending CAP REQ :twitch.tv/tags right after connecting. this gives you the display-name tag for proper capitalization and all badge info for mods/subs. just parse the tags section before the username part.