Why is my IRC bot not connecting?

public static string SERVER = "irc.rizon.net"; private static int PORT = 6667; private static string USER = "Test C# Irc bot"; private static string NICK = "Testing"; private static string CHANNEL = "#Test0x40"; public static void Main(string[] args) { NetworkStream stream; TcpClient irc; StreamReader reader; StreamWriter writer; irc = new TcpClient(SERVER, PORT); stream = irc.GetStream(); reader = new StreamReader(stream); writer = new StreamWriter(stream); writer.WriteLine("NICK " + NICK); writer.Flush(); writer.WriteLine("JOIN " + CHANNEL); writer.Flush(); Console.ReadKey(true); } 

Why is my IRC bot not connecting?

+7
c # bots irc
source share
1 answer

IRC requires a CR / LF pair, while the default behavior for StreamWriter is only line channels. You should create your StreamWriter as follows:

 writer = new StreamWriter(stream) { NewLine = "\r\n", AutoFlush = true }; 

In addition, you should probably specify the username with the USER command before joining the channel, although I'm not sure if it is completely necessary:

 writer.WriteLine("USER username +mode * :Real Name"); 
+3
source share

All Articles