Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
需要C#Twitch机器人的帮助吗_C#_Chat_Bots_Twitch - Fatal编程技术网

需要C#Twitch机器人的帮助吗

需要C#Twitch机器人的帮助吗,c#,chat,bots,twitch,C#,Chat,Bots,Twitch,嘿,我想为Twitch创建一个聊天机器人,我是这方面的初学者,这是我目前的工作: 表格1.cs如下: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.

嘿,我想为Twitch创建一个聊天机器人,我是这方面的初学者,这是我目前的工作:

表格1.cs如下:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MyTwitchChat
{
    public partial class Form1 : Form
    {
        private string username;
        private string password;

        bool joined;

        IRCClient ircClient;
        public Form1()
        {
            InitializeComponent();

        }

        private void button1_Click(object sender, EventArgs e)
        {
            username = userNameTB.Text;
            password = TokenBox.Text;
            ircClient = new IRCClient("irc.chat.twitch.tv", 6667, username, password);
            ircClient.joinChannel("deadlycursed");

            timer1.Start();

        }

        private void timer1_Tick(object sender, EventArgs e)
        {


            if (ircClient.tcpClient.Available > 0 )
            {

                string message = ircClient.inputStream.ReadLine();

                ChatBox.Items.Add(message);
                if (message.Contains("!Hallo"))  
                        ircClient.sendChatMessage("Hi!");
            }
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.Net.Sockets;
using System.IO;

namespace MyTwitchChat
{
    class IRCClient
    {
        private string username;
        private string channel;
        private string nickname = "deadlycursed";
        public TcpClient tcpClient;
        public StreamReader inputStream;
        public 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 " + nickname);
            outputStream.WriteLine("USER " + username + " 0 * :" + nickname );
            outputStream.Flush();
        }

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

        }

        public void sendIRCMessage(string message)
        {
            outputStream.WriteLine(message);
            outputStream.Flush();
        }

        public void sendChatMessage(string message)
        {
            outputStream.WriteLine(":" + nickname + "!" + username + "@" + nickname + ".tmi.twitch.tv PRIVMSG #"
                + channel + ":" + message);
            outputStream.Flush();
        }

        public string getMessage()
        {
            string message = inputStream.ReadLine();
            return message;
        }
    }
}
IRCClient.cs如下:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MyTwitchChat
{
    public partial class Form1 : Form
    {
        private string username;
        private string password;

        bool joined;

        IRCClient ircClient;
        public Form1()
        {
            InitializeComponent();

        }

        private void button1_Click(object sender, EventArgs e)
        {
            username = userNameTB.Text;
            password = TokenBox.Text;
            ircClient = new IRCClient("irc.chat.twitch.tv", 6667, username, password);
            ircClient.joinChannel("deadlycursed");

            timer1.Start();

        }

        private void timer1_Tick(object sender, EventArgs e)
        {


            if (ircClient.tcpClient.Available > 0 )
            {

                string message = ircClient.inputStream.ReadLine();

                ChatBox.Items.Add(message);
                if (message.Contains("!Hallo"))  
                        ircClient.sendChatMessage("Hi!");
            }
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.Net.Sockets;
using System.IO;

namespace MyTwitchChat
{
    class IRCClient
    {
        private string username;
        private string channel;
        private string nickname = "deadlycursed";
        public TcpClient tcpClient;
        public StreamReader inputStream;
        public 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 " + nickname);
            outputStream.WriteLine("USER " + username + " 0 * :" + nickname );
            outputStream.Flush();
        }

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

        }

        public void sendIRCMessage(string message)
        {
            outputStream.WriteLine(message);
            outputStream.Flush();
        }

        public void sendChatMessage(string message)
        {
            outputStream.WriteLine(":" + nickname + "!" + username + "@" + nickname + ".tmi.twitch.tv PRIVMSG #"
                + channel + ":" + message);
            outputStream.Flush();
        }

        public string getMessage()
        {
            string message = inputStream.ReadLine();
            return message;
        }
    }
}
我想知道为什么我不能发送或接收信息?
有时阅读功能有效,有时无效,我无法用我的机器人向聊天室写信。有一些库可以帮助您完成这项工作,因此您可以查看它们是如何工作的,也可以直接使用它们

例如,NuGet上最受欢迎的似乎是:

TwitchLib-Twitch聊天和API C#库-