diff --git a/lib/nostrum/api.ex b/lib/nostrum/api.ex index d7e727647..bf35ea946 100644 --- a/lib/nostrum/api.ex +++ b/lib/nostrum/api.ex @@ -1865,7 +1865,16 @@ defmodule Nostrum.Api do end @doc """ - Gets a list of users banend from a guild. + Gets a ban object for the given user from a guild. + """ + @spec get_guild_ban(integer, integer) :: error | {:ok, Guild.Ban.t()} + def get_guild_ban(guild_id, user_id) do + request(:get, Constants.guild_ban(guild_id, user_id)) + |> handle_request_with_decode({:struct, Guild.Ban}) + end + + @doc """ + Gets a list of users banned from a guild. Guild to get bans for is specified by `guild_id`. """ diff --git a/lib/nostrum/struct/guild/ban.ex b/lib/nostrum/struct/guild/ban.ex new file mode 100644 index 000000000..994e71612 --- /dev/null +++ b/lib/nostrum/struct/guild/ban.ex @@ -0,0 +1,34 @@ +defmodule Nostrum.Struct.Guild.Ban do + @moduledoc """ + Represents a guild ban. + """ + + alias Nostrum.Struct.User + alias Nostrum.Util + + defstruct [ + :reason, + :user + ] + + @typedoc "The reason for the ban" + @type reason :: String.t() | nil + + @typedoc "The banned user" + @type user :: User.t() + + @type t :: %__MODULE__{ + reason: reason, + user: user + } + + @doc false + def to_struct(map) do + new = + map + |> Map.new(fn {k, v} -> {Util.maybe_to_atom(k), v} end) + |> Map.update(:user, nil, &Util.cast(&1, {:struct, User})) + + struct(__MODULE__, new) + end +end