Nostrum v0.4.1 Nostrum.Consumer behaviour View Source

Consumer process for gateway event handling.

Consuming Gateway Events

To handle events, Nostrum uses a GenStage implementation.

Nostrum defines the producer and producer_consumer in the GenStage design. To consume the events you must create at least one consumer process. It is generally recommended that you spawn a consumer per core. To find this number you can use System.schedulers_online/0.

Nostrum uses a ConsumerSupervisor to dispatch events, meaning your handlers will each be ran in their own seperate task.

Example

An example consumer can be found here.

Link to this section Summary

Functions

Starts a consumer process.

Callbacks

Callback used to handle events.

Link to this section Types

Link to this type

channel_create() View Source
channel_create() ::
  {:CHANNEL_CREATE, Nostrum.Struct.Channel.t(), Nostrum.Struct.WSState.t()}

Link to this type

channel_delete() View Source
channel_delete() ::
  {:CHANNEL_DELETE, Nostrum.Struct.Channel.t(), Nostrum.Struct.WSState.t()}

Link to this type

channel_pins_ack() View Source
channel_pins_ack() :: {:CHANNEL_PINS_ACK, map(), Nostrum.Struct.WSState.t()}

Link to this type

channel_pins_update() View Source
channel_pins_update() ::
  {:CHANNEL_PINS_UPDATE, map(), Nostrum.Struct.WSState.t()}

Link to this type

channel_update() View Source
channel_update() ::
  {:CHANNEL_UPDATE,
   {old_channel :: Nostrum.Struct.Channel.t() | nil,
    new_channel :: Nostrum.Struct.Channel.t()}, Nostrum.Struct.WSState.t()}

Dispatched when a channel is updated.

old_channel will be nil when the pre-update channel could not be fetched from the cache.

Link to this type

guild_available() View Source
guild_available() ::
  {:GUILD_AVAILABLE, new_guild :: Nostrum.Struct.Guild.t(),
   Nostrum.Struct.WSState.t()}

Link to this type

guild_ban_add() View Source
guild_ban_add() ::
  {:GUILD_BAN_ADD, {guild_id :: integer(), Nostrum.Struct.User.t()},
   Nostrum.Struct.WSState.t()}

Link to this type

guild_ban_remove() View Source
guild_ban_remove() ::
  {:GUILD_BAN_REMOVE, {guild_id :: integer(), Nostrum.Struct.User.t()},
   Nostrum.Struct.WSState.t()}

Link to this type

guild_create() View Source
guild_create() ::
  {:GUILD_CREATE, new_guild :: Nostrum.Struct.Guild.t(),
   Nostrum.Struct.WSState.t()}

Link to this type

guild_delete() View Source
guild_delete() ::
  {:GUILD_DELETE,
   {old_guild :: Nostrum.Struct.Guild.t(), unavailable :: boolean()},
   Nostrum.Struct.WSState.t()}

Link to this type

guild_emojis_update() View Source
guild_emojis_update() ::
  {:GUILD_EMOJIS_UPDATE,
   {guild_id :: integer(), old_emojis :: [Nostrum.Struct.Message.Emoji.t()],
    new_emojis :: [Nostrum.Struct.Message.Emoji.t()]},
   Nostrum.Struct.WSState.t()}

Link to this type

guild_integrations_update() View Source
guild_integrations_update() ::
  {:GUILD_INTEGERATIONS_UPDATE, map(), Nostrum.Struct.WSState.t()}

Link to this type

guild_member_add() View Source
guild_member_add() ::
  {:GUILD_MEMBER_ADD,
   {guild_id :: integer(), new_member :: Nostrum.Struct.Guild.Member.t()},
   Nostrum.Struct.WSState.t()}

Link to this type

guild_member_remove() View Source
guild_member_remove() ::
  {:GUILD_MEMBER_REMOVE,
   {guild_id :: integer(), old_member :: Nostrum.Struct.Guild.Member.t()},
   Nostrum.Struct.WSState.t()}

Link to this type

guild_member_update() View Source
guild_member_update() ::
  {:GUILD_MEMBER_UPDATE,
   {guild_id :: integer(), old_member :: Nostrum.Struct.Guild.Member.t() | nil,
    new_member :: Nostrum.Struct.Guild.Member.t()}, Nostrum.Struct.WSState.t()}

Dispatched when a guild member is updated.

old_member will be nil when the pre-update member could not be fetched from the cache.

Link to this type

guild_members_chunk() View Source
guild_members_chunk() ::
  {:GUILD_MEMBERS_CHUNK, map(), Nostrum.Struct.WSState.t()}

Link to this type

guild_role_create() View Source
guild_role_create() ::
  {:GUILD_ROLE_CREATE,
   {guild_id :: integer(), new_role :: Nostrum.Struct.Guild.Role.t()},
   Nostrum.Struct.WSState.t()}

Link to this type

guild_role_delete() View Source
guild_role_delete() ::
  {:GUILD_ROLE_DELETE,
   {guild_id :: integer(), old_role :: Nostrum.Struct.Guild.Role.t()},
   Nostrum.Struct.WSState.t()}

Link to this type

guild_role_update() View Source
guild_role_update() ::
  {:GUILD_ROLE_UPDATE,
   {guild_id :: integer(), old_role :: Nostrum.Struct.Guild.Role.t() | nil,
    new_role :: Nostrum.Struct.Guild.Role.t()}, Nostrum.Struct.WSState.t()}

Dispatched when a role on a guild is updated.

old_role will be nil when the pre-update role could not be fetched from the cache.

Link to this type

guild_unavailable() View Source
guild_unavailable() ::
  {:GUILD_UNAVAILABLE,
   unavailable_guild :: Nostrum.Struct.Guild.UnavailableGuild.t(),
   Nostrum.Struct.WSState.t()}

Link to this type

guild_update() View Source
guild_update() ::
  {:GUILD_CREATE,
   {old_guild :: Nostrum.Struct.Guild.t(),
    new_guild :: Nostrum.Struct.Guild.t()}, Nostrum.Struct.WSState.t()}

Link to this type

message_ack() View Source
message_ack() :: {:MESSAGE_ACK, map(), Nostrum.Struct.WSState.t()}

Link to this type

message_create() View Source
message_create() ::
  {:MESSAGE_CREATE, message :: Nostrum.Struct.Message.t(),
   Nostrum.Struct.WSState.t()}

Link to this type

message_delete() View Source
message_delete() ::
  {:MESSAGE_DELETE, Nostrum.Struct.Event.MessageDelete.t(),
   Nostrum.Struct.WSState.t()}

Link to this type

message_delete_bulk() View Source
message_delete_bulk() ::
  {:MESSAGE_DELETE_BULK, Nostrum.Struct.Event.MessageDeleteBulk.t(),
   Nostrum.Struct.WSState.t()}

Link to this type

message_reaction_add() View Source
message_reaction_add() ::
  {:MESSAGE_REACTION_ADD, map(), Nostrum.Struct.WSState.t()}

Link to this type

message_reaction_remove() View Source
message_reaction_remove() ::
  {:MESSAGE_REACTION_REMOVE, map(), Nostrum.Struct.WSState.t()}

Link to this type

message_reaction_remove_all() View Source
message_reaction_remove_all() ::
  {:MESSAGE_REACTION_REMOVE_ALL, map(), Nostrum.Struct.WSState.t()}

Link to this type

message_update() View Source
message_update() ::
  {:MESSAGE_UPDATE, updated_message :: Nostrum.Struct.Message.t(),
   Nostrum.Struct.WSState.t()}

Link to this type

option() View Source
option() ::
  {:registry, atom()}
  | {:name, Supervisor.name()}
  | {:max_restarts, non_neg_integer()}
  | {:max_seconds, non_neg_integer()}
  | {:subscribe_to, [GenStage.stage() | {GenStage.stage(), keyword()}]}

General process options.

The subscribe_to option should only be set if you want to use your own producer or producer consumer.

Link to this type

options() View Source
options() :: [option()] | []

Link to this type

presence_update() View Source
presence_update() ::
  {:PRESENCE_UPDATE,
   {guild_id :: integer(), old_presence :: map() | nil,
    new_presence :: map()}, Nostrum.Struct.WSState.t()}

Dispatched when a user's presence is updated.

old_presence will be nil when the pre-update presence could not be fetched from the cache.

Link to this type

resumed() View Source
resumed() :: {:RESUMED, map(), Nostrum.Struct.WSState.t()}

Link to this type

typing_start() View Source
typing_start() :: {:TYPING_START, map(), Nostrum.Struct.WSState.t()}

Link to this type

user_settings_update() View Source
user_settings_update() :: no_return()

Link to this type

user_update() View Source
user_update() ::
  {:USER_UPDATE,
   {old_user :: Nostrum.Struct.User.t() | nil,
    new_user :: Nostrum.Struct.User.t()}, Nostrum.Struct.WSState.t()}

Dispatched when a user is updated.

old_user will be nil when the pre-update user could not be fetched from the cache.

Link to this type

voice_server_update() View Source
voice_server_update() ::
  {:VOICE_SERVER_UPDATE, map(), Nostrum.Struct.WSState.t()}

Link to this type

voice_state_update() View Source
voice_state_update() ::
  {:VOICE_STATE_UPDATE, map(), Nostrum.Struct.WSState.t()}

Link to this type

webhooks_update() View Source
webhooks_update() :: {:WEBHOOKS_UPDATE, map(), Nostrum.Struct.WSState.t()}

Link to this section Functions

Link to this function

start_link(mod, options \\ []) View Source
start_link(module(), options()) :: Supervisor.on_start()

Starts a consumer process.

mod is the name of the module where you define your event callbacks, which should probably be the current module which you can get with __MODULE__.

options is a list of general process options. See Nostrum.Consumer.options/0 for more info.

Link to this section Callbacks

Link to this callback

handle_event(event) View Source
handle_event(event()) :: any()

Callback used to handle events.

Event

event is a tuple describing the event. The tuple will include information in the following format:

{event_name, {event_payload(s)}, WSState.t}

For example, a message create will look like this

{:MESSAGE_CREATE, {Nostrum.Struct.Message.t}, WSState.t}

In some cases there will be multiple payloads when something is updated, so as to include the new and the old versions. In the event of there being two payloads, the old payload will always be first, followed by the new payload.

{:USER_UPDATE, {old_user :: Nostrum.Struct.User.t, new_user :: Nostrum.Struct.User.t}, WSState.t()}

For a full listing of events, please see Nostrum.Consumer.event/0.