Make A Twitch Chatbot In Rust

Installs

Code
cargo init
cargo add tokio --features "full"
cargo add twitch_irc
src/main.rs
use twitch_irc::login::StaticLoginCredentials;
use twitch_irc::ClientConfig;
use twitch_irc::SecureTCPTransport;
use twitch_irc::TwitchIRCClient;

#[tokio::main]
pub async fn main() {
    let config = ClientConfig::default();
    let (mut incoming_messages, client) =
        TwitchIRCClient::<SecureTCPTransport, StaticLoginCredentials>::new(config);
    let join_handle = tokio::spawn(async move {
        while let Some(message) = incoming_messages.recv().await {
            match message {
                twitch_irc::message::ServerMessage::Privmsg(payload) => {
                    println!("{}\n{}\n", payload.sender.name, payload.message_text);
                }
                _ => {}
            }
        }
    });
    client.join("theidofalan".to_owned()).unwrap();
    join_handle.await.unwrap();
}
Notes
  • This is anonymous so no login is required

  • This is currently just for displaying messages in the terminal

Reference

twitch_irc a rust client library to interface with Twitch chat

Reference

tokio::runtime an asynchronous runtime for rust