Elixir 启动ExIrc supervisor失败

Elixir 启动ExIrc supervisor失败,elixir,irc,Elixir,Irc,我正在修补ExIrc以制作一个简单的机器人,但我无法让它工作 我得到了这个错误: ** (Mix) Could not start application streamingutils: TwitchSniper.start(:normal, []) returned an error: shutdown: failed to start child: TwitchSniper.Bot ** (EXIT) an exception was raised: ** (Arg

我正在修补ExIrc以制作一个简单的机器人,但我无法让它工作

我得到了这个错误:

** (Mix) Could not start application streamingutils: TwitchSniper.start(:normal,
 []) returned an error: shutdown: failed to start child: TwitchSniper.Bot
    ** (EXIT) an exception was raised:
        ** (ArgumentError) argument error
            :erlang.apply([%TwitchSniper.Bot.State{client: nil, handlers: [], host: "irc.chat.twitch.tv", name: "Paul Schoenfelder", nick: "hajtosek", pass: "my password", port: 6667, user: "hajtosek"}], :host, [])
            (streamingutils) TwitchSniper.Bot.init/1
            (stdlib) gen_server.erl:328: :gen_server.init_it/6
            (stdlib) proc_lib.erl:239: :proc_lib.init_p_do_apply/3
我试图使用ExIrc库:

我只是从自述文件中复制了大部分代码,只是交换了数据

代码:


这似乎是自述文件中的输入错误。init的
state
参数始终是一个列表(它接收提供给
GenServer.start\u链接的列表)。所以问题是,您试图像结构一样使用状态,而它不是一个。只需将
init
的函数头改为
[state]
,而不是
state
,就可以开始了


<>编辑:也值得注意的是,你应该在Github上的示例文件夹中查看使用ExRLC的完整应用程序,它们是更现实的例子。

非常感谢,必须向LIB作者报告。我是LIB的作者,所以请考虑它的报告;
defmodule State do
    defstruct host: "irc.chat.twitch.tv",
              port: 6667,
              pass: "password",
              nick: "hajtosek",
              user: "hajtosek",
              name: "Paul Schoenfelder",
              client: nil,
              handlers: []
end

def start_link(_) do
    GenServer.start_link(__MODULE__, [%State{}])
end

def init(state) do
    # Start the client and handler processes, the ExIrc supervisor is automatically started when your app runs
    {:ok, client}  = ExIrc.start_client!()
    #{:ok, handler} = ExampleHandler.start_link(nil)

    # Register the event handler with ExIrc
    ExIrc.Client.add_handler client, self

    # Connect and logon to a server, join a channel and send a simple message
    ExIrc.Client.connect!   client, state.host, state.port
    ExIrc.Client.logon      client, state.pass, state.nick, state.user, state.name
    ExIrc.Client.join       client, "#channel"
    ExIrc.Client.msg        client, :privmsg, "#channel", "Hello world!"
    ExIrc.Client.msg        client, :ctcp, "#channel", "Hello world!"

    IO.inspect "IRC activated"

    {:ok, %{state | :client => client, :handlers => [self]}}
end

def terminate(_, state) do
    # Quit the channel and close the underlying client connection when the process is terminating
    ExIrc.Client.quit state.client, "Goodbye, cruel world."
    ExIrc.Client.stop! state.client
    :ok
end