Elixir v0.2.1 Nostrum.Consumer behaviour
Consumer process for gateway event handling.
Consuming Gateway Events
To handle events, Nostrum uses a GenStage implementation. GenStage is “new” with Elixir version 1.4, expanding on the old functionality of GenEvent.
Nostrum defines the producer
in the GenStage design. To consume the events you must
create at least one consumer
process. For
an example of this behaviour please see
here.
It is generally recommended that you spawn a consumer per core. To find this
number you can use System.schedulers_online/0
.
Summary
Types
Tuple describing the client of a call request
The state of the consumer process
The state of the websocket connection for the shard the event occured on
Callbacks
Callback used to handle events
Types
channel_update() :: {:CHANNEL_UPDATE, {old_channel :: Nostrum.Struct.Channel.t, new_channel :: Nostrum.Struct.Channel.t}, ws_state}
event :: channel_create | channel_delete | channel_update | channel_pins_ack | channel_pins_update | guild_ban_add | build_ban_remove | guild_create | guild_unavailable | guild_update | guild_delete | guild_emojis_update | guild_integrations_update | guild_member_add | guild_members_chunk | guild_member_remove | guild_member_update | guild_role_create | guild_role_delete | guild_role_update | message_create | message_delete | message_delete_bulk | message_update | message_reaction_add | message_reaction_remove | presence_update | ready | resumed | typing_start | user_settings_update | user_update | voice_state_update | voice_server_update
Tuple describing the client of a call request.
pid
is the PID of the caller and tag
is a unique term used to identify the
call.
guild_emojis_update() :: {:GUILD_EMOJIS_UPDATE, {old_emojis :: [Nostrum.Struct.Message.Emoji.t], new_emojis :: [Nostrum.Struct.Message.Emoji.t]}, ws_state}
guild_integrations_update() :: {:GUILD_INTEGERATIONS_UPDATE, {map}, ws_state}
guild_member_add() :: {:GUILD_MEMBER_ADD, {new_member :: Nostrum.Struct.Guild.Member.t}, ws_state}
guild_member_remove() :: {:GUILD_MEMBER_REMOVE, {old_member :: Nostrum.Struct.Guild.Member.t}, ws_state}
guild_member_update() :: {:GUILD_MEMBER_UPDATE, {old_member :: Nostrum.Struct.Guild.Member.t, new_member :: Nostrum.Struct.Guild.Member.t}, ws_state}
guild_role_create() :: {:GUILD_ROLE_CREATE, {new_role :: Nostrum.Struct.Guild.Role.t}, ws_state}
guild_role_delete() :: {:GUILD_ROLE_DELETE, {old_role :: Nostrum.Struct.Guild.Role.t}, ws_state}
guild_role_update() :: {:GUILD_ROLE_UPDATE, {old_role :: Nostrum.Struct.Guild.Role.t, new_role :: Nostrum.Struct.Guild.Role.t}, ws_state}
guild_update() :: {:GUILD_CREATE, {old_guild :: Nostrum.Struct.Guild.t, new_guild :: Nostrum.Struct.Guild.t}, ws_state}
message_create() :: {:MESSAGE_CREATE, {message :: Nostrum.Struct.Message.t}, ws_state}
message_delete() :: {:MESSAGE_DELETE, {message :: Nostrum.Struct.Message.t}, ws_state}
message_delete_bulk() :: {:MESSAGE_DELETE_BULK, {updated_messages :: [Nostrum.Struct.Message.t]}, ws_state}
message_update() :: {:MESSAGE_UPDATE, {updated_message :: Nostrum.Struct.Message.t}, ws_state}
user_update() :: {:USER_UPDATE, {old_user :: Nostrum.Struct.User.t, new_user :: Nostrum.Struct.User.t}, ws_state}
Functions
Callbacks
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)}, ws_state}
For example, a message create will look like this
{:MESSAGE_CREATE, {Nostrum.Struct.Message.t}, ws_state}
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.
{:CHANNEL_UPDATE, {old :: Nostrum.Struct.Channel.t, new :: Nostrum.Struct.Channel.t}, ws_state}
For a full listing of events, please see Nostrum.Consumer.event
.
Websocket State
ws_state
is the current state of
the websocket that the event was received on. For more information on this please
see Nostrum.Shard.Payload.state_map.t
.
State
state
is the internal state of your consumer.