Closed rekyuu closed 7 years ago
I also tried working backwards with the Rest API and got
iex(6)> {:ok, rest} = DiscordEx.RestClient.start_link(%{token: token})
{:ok, #PID<0.272.0>}
iex(7)> DiscordEx.RestClient.Resources.User.current(rest)
%{"code" => 0, "message" => "401: Unauthorized"}
Looking through the most recent commit it seems there is code that was not installed with Hex, likely a version bump and Hex update issue. Regardless I tried the fix of adding Bot
to the beginning of token and I still get the same error as I did in the first comment. It does however work for the Rest client when I do the new token with the same code as I did in post 2. If I remove the following and start iex and run Client.start_link
manually it also works, so it seems to be an issue with genserver and hackney while it's compiling. While running it manually I sent my bot a message and got the following:
03:11:46.803 [error] ** Websocket client DiscordEx.Client terminating in :websocket_handle/3
for the reason :error:%Protocol.UndefinedError{description: "", protocol: String.Chars,
value: %{data: %{"attachments" => [],
"author" => %{"avatar" => "b5290cf391d4482364d1c7b1f0050031",
"discriminator" => "4390", "id" => 107977662680571904,
"username" => "rekyuu"}, "channel_id" => 234550087345373184,
"content" => "test", "edited_timestamp" => nil, "embeds" => [],
"id" => 234603808578076673, "mention_everyone" => false,
"mention_roles" => [], "mentions" => [], "nonce" => "234603808586465280",
"pinned" => false, "timestamp" => "2016-10-09T09:11:46.693000+00:00",
"tts" => false, "type" => 0}, event_name: :MESSAGE_CREATE, op: :dispatch,
seq_num: 4}}
** Websocket message was {:binary,
<<131, 116, 0, 0, 0, 4, 100, 0, 1, 100, 116, 0, 0, 0, 15, 109, 0, 0, 0, 11, 97,
116, 116, 97, 99, 104, 109, 101, 110, 116, 115, 106, 109, 0, 0, 0, 6, 97,
117, 116, 104, 111, 114, 116, 0, 0, 0, 4, 109, ...>>}
** Handler state was %{agent_seq_num: #PID<0.252.0>, client_id: 234548552053817345,
client_pid: #PID<0.251.0>,
guilds: [%{guild_id: 214268737887404042, voice_states: []}],
handler: DiscordKuma.Module, rest_client: #PID<0.244.0>,
session_id: "a46e7dd2563c69570bf076ffbce9d6e7",
token: "Bot nopelol"}
** Stacktrace: [{String.Chars, :impl_for!, 1, [file: 'lib/string/chars.ex', line: 3]},
{String.Chars, :to_string, 1, [file: 'lib/string/chars.ex', line: 17]},
{DiscordKuma.Module, :handle_event, 2,
[file: 'lib/discord_kuma/module.ex', line: 3]},
{:websocket_client, :handle_websocket_frame, 2,
[file: 'c:/Users/bowan/dev/elixir/discord_kuma/deps/websocket_client/src/websocket_client.erl',
line: 448]}, {:gen_fsm, :handle_msg, 7, [file: 'gen_fsm.erl', line: 451]},
{:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 247]}]
iex(4)> ** (EXIT from #PID<0.241.0>) %Protocol.UndefinedError{description: "", protocol: String.Chars, value: %{data: %{"attachments" => [], "author" => %{"avatar" => "b5290cf391d4482364d1c7b1f0050031", "discriminator" => "4390", "id" => 107977662680571904, "username" => "rekyuu"}, "channel_id" => 234550087345373184, "content" => "test", "edited_timestamp" => nil, "embeds" => [], "id" => 234603808578076673, "mention_everyone" => false, "mention_roles" => [], "mentions" => [], "nonce" => "234603808586465280", "pinned" => false, "timestamp" => "2016-10-09T09:11:46.693000+00:00", "tts" => false, "type" => 0}, event_name: :MESSAGE_CREATE, op: :dispatch, seq_num: 4}}
iex(4)>
iex(4)>
03:11:46.825 [error] ** State machine #PID<0.251.0> terminating
** Last message in was {:ssl,
{:sslsocket, {:gen_tcp, #Port<0.11321>, :tls_connection, :undefined},
#PID<0.254.0>},
<<130, 126, 1, 239, 131, 116, 0, 0, 0, 4, 100, 0, 1, 100, 116, 0, 0, 0, 15,
109, 0, 0, 0, 11, 97, 116, 116, 97, 99, 104, 109, 101, 110, 116, 115, 106,
109, 0, 0, 0, 6, 97, 117, 116, 104, 111, 114, 116, ...>>}
** When State == :connected
** Data == {:context,
{:websocket_req, :wss, 'gateway.discord.gg', 443, '/?v=4&encoding=etf',
:infinity, :undefined, 1,
{:sslsocket, {:gen_tcp, #Port<0.11321>, :tls_connection, :undefined},
#PID<0.254.0>},
{:transport, :ssl, :ssl, :ssl_closed, :ssl_error,
[mode: :binary, active: true, verify: :verify_none, packet: 0]},
"yNmspc/KzpHBNGidgxSuwg==", :undefined, 1, 2, :undefined, :undefined},
{:transport, :ssl, :ssl, :ssl_closed, :ssl_error,
[mode: :binary, active: true, verify: :verify_none, packet: 0]}, [],
{:wss, 'gateway.discord.gg', 443, '/?v=4&encoding=etf'},
{DiscordEx.Client,
%{agent_seq_num: #PID<0.252.0>, client_id: 234548552053817345,
client_pid: #PID<0.251.0>,
guilds: [%{guild_id: 214268737887404042, voice_states: []}],
handler: DiscordKuma.Module, rest_client: #PID<0.244.0>,
session_id: "a46e7dd2563c69570bf076ffbce9d6e7",
token: "Bot nopelol"}},
"", false, 0}
** Reason for termination =
** %Protocol.UndefinedError{description: "", protocol: String.Chars,
value: %{data: %{"attachments" => [],
"author" => %{"avatar" => "b5290cf391d4482364d1c7b1f0050031",
"discriminator" => "4390", "id" => 107977662680571904,
"username" => "rekyuu"}, "channel_id" => 234550087345373184,
"content" => "test", "edited_timestamp" => nil, "embeds" => [],
"id" => 234603808578076673, "mention_everyone" => false,
"mention_roles" => [], "mentions" => [], "nonce" => "234603808586465280",
"pinned" => false, "timestamp" => "2016-10-09T09:11:46.693000+00:00",
"tts" => false, "type" => 0}, event_name: :MESSAGE_CREATE, op: :dispatch,
seq_num: 4}}
Dunno how I managed to completely destroy this library but I hope I've given enough info to see what's going on. lol
Got it working, turns out HTTPoison wasn't starting in application
for whatever reason so I manually invoked it:
defmodule DiscordKuma do
require Logger
def start(_type, _args) do
Logger.debug "Starting HTTPoison..."
HTTPoison.start
Logger.debug "Starting bot..."
DiscordEx.Client.start_link(%{
token: Application.get_env(:discord_kuma, :discord_token),
handler: DiscordKuma.Module
})
end
end
Thanks!
Hiya, I'm pretty sure I'm just screwed up somewhere but I wanted a second pair of eyes to see why this isn't starting. I don't have anything crazy in the bot, just having it start with a supervisor and then have it parse events.
My repo is at https://github.com/KumaKaiNi/discord-kuma. The error I'm getting is as follows:
The code I'm using to start the bot:
Thanks for the help.