Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
OCaml IRC client library
branch: master
Failed to load latest commit information.
doc Add docs generation
examples Open Lwt rather than Io in the example code
lib Minor code simplification in connect_by_name
lwt Implement send_notice.
test Add parser tests
unix Add send_notice to irc_client_unix.mli
.gitignore Update .gitignore
.merlin Update .merlin
.ocamlinit .ocamlinit file Add docs build to travis script
ChangeLog Update ChangeLog
LICENSE Add MIT license
Makefile Build examples as part of default make target Update
_oasis Example 1 depends on Lwt
_tags Update to OASIS 0.4.4 Update to OASIS 0.4.4 Example 1 depends on Lwt

IRC client library, supporting Lwt and Unix blocking IO.

Build status

Build dependencies

The latest tagged version is available via opam: opam install irc-client


Simple bot which connects to a channel, sends a message, and then logs all messages in that channel to stdout:

open Lwt
module C = Irc_client_lwt.Client

let host = "localhost"
let port = 6667
let realname = "Demo IRC bot"
let nick = "demoirc"
let username = nick
let channel = "#demo_irc"
let message = "Hello, world!  This is a test from ocaml-irc-client"

let string_opt_to_string = function
  | None -> "None"
  | Some s -> Printf.sprintf "Some %s" s

let string_list_to_string string_list =
  Printf.sprintf "[%s]" (String.concat "; " string_list)

let callback ~connection ~result =
  let open Irc_message in
  match result with
  | Message {prefix=prefix; command=command; params=params; trail=trail} ->
    Lwt_io.printf "Got message: prefix=%s; command=%s; params=%s; trail=%s\n"
      (string_opt_to_string prefix)
      (string_list_to_string params)
      (string_opt_to_string trail)
  | Parse_error (raw, error) ->
    Lwt_io.printf "Failed to parse \"%s\" because: %s" raw error

let lwt_main =
  Lwt_unix.gethostbyname host
  >>= fun he -> C.connect ~addr:(he.Lwt_unix.h_addr_list.(0))
                  ~port ~username ~mode:0 ~realname ~nick ()
  >>= fun connection -> Lwt_io.printl "Connected"
  >>= fun () -> C.send_join ~connection ~channel
  >>= fun () -> C.send_privmsg ~connection ~target:channel ~message
  >>= fun () -> C.listen ~connection ~callback
  >>= fun () -> C.send_quit ~connection

let _ = lwt_main

Compile the above with:

ocamlfind ocamlopt -package irc-client.lwt -linkpkg

Alternatively, you can find it under the examples/ directory as; enable its compilation during config time with --enable-examples.

Something went wrong with that request. Please try again.