Search code examples
c#irc

C# TwitchBot won't connect to chat


I tried to create a simple twitchBot using Visual Studio C#, but it won't show up in chat. I could connect with mIRC manually without problems.

I don't recieve any error messages, so it's hard for me to pinpoint the problem. Any ideas are appreciated.

class Program
{
    static void Main(string[] args)
    {
        IrcClient irc = new IrcClient("irc.chat.twitch.tv", 6667, "gruhlumbot", "oauth:g49tpwj1czs200RETAINED");

        irc.joinRoom("gruhlumbot");
        while(true)
        {
            string message = irc.readMessage();
            if (message.Contains("!test"))
            {
                irc.sentChatMessage("response");
            }
        }
    }
}

class IrcClient
{
    private string userName;
    private string channel;

    private TcpClient tcpClient;
    private StreamReader inputStream;
    private StreamWriter outputStream;

    public IrcClient(string ip, int port, string userName, string password)
    {
        this.userName = userName;

        tcpClient = new TcpClient(ip, port);
        inputStream = new StreamReader(tcpClient.GetStream());
        outputStream = new StreamWriter(tcpClient.GetStream());

        outputStream.WriteLine("PASS " + password);
        outputStream.WriteLine("NICK " + userName);
        outputStream.WriteLine("USER " + userName + " 8 * :" + userName);
        outputStream.Flush();
    }

    public void joinRoom(string channel)
    {
        this.channel = channel;
        outputStream.WriteLine("JOIN #" + channel);
        outputStream.Flush();
    }

    public void sentChatMessage(string message)
    {
        sendIrcMessage(":" + userName + "!" + userName + "@" + userName + ".tmi.twitch.tv PRIVMSG #" + channel + " :" + message);
    }

    public string readMessage()
    {
        string message = inputStream.ReadLine();
        return message;
    }

}

Solution

  • Can you try adding the character "/" before the command join?

    As I remember when I was using Irc all commands where using the "/" character before the command.

    Something like this.

    outputStream.WriteLine("/JOIN #" + channel);
    

    Share with us the results. Thanks.