我尝试使用Visual Studio C#创建一个简单的twitchBot,但它不会显示在聊天中。我可以手动连接mIRC而不会出现问题。
我没有收到任何错误消息,因此我很难确定问题所在。 任何想法都表示赞赏。
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;
}
}
答案 0 :(得分:0)
您可以尝试在命令加入前添加字符“/”吗?
我记得当我使用Irc所有命令时,在命令之前使用“/”字符。
像这样。
outputStream.WriteLine("/JOIN #" + channel);
与我们分享结果。感谢。