Nostrum.Api.Channel (nostrum v0.11.0-dev)
View SourceFunctions for interacting with the Discord API's channel endpoints.
Summary
Functions
Deletes multiple messages from a channel.
Creates a channel for a guild.
Deletes a channel.
Delete a channel permission for a user or role.
Edit the permission overwrites for a user or role.
Gets a channel.
Retrieves a channel's messages around a locator
up to a limit
.
Modifies a channel's settings.
Pins a message in a channel.
Retrieves all pinned messages from a channel.
Triggers the typing indicator.
Unpins a message in a channel.
Gets a list of webhooks for a channel.
Functions
@spec bulk_delete_messages( Nostrum.Struct.Channel.id(), [Nostrum.Struct.Message.id()], boolean() ) :: Nostrum.Api.error() | {:ok}
Deletes multiple messages from a channel.
messages
is a list of Nostrum.Struct.Message.id
that you wish to delete.
When given more than 100 messages, this function will chunk the given message
list into blocks of 100 and send them off to the API. It will stop deleting
on the first error that occurs. Keep in mind that deleting thousands of
messages will take a pretty long time and it may be proper to just delete
the channel you want to bulk delete in and recreate it.
This method can only delete messages sent within the last two weeks.
Filter
is an optional parameter that specifies whether messages sent over
two weeks ago should be filtered out; defaults to true
.
@spec create(Nostrum.Struct.Guild.id(), Nostrum.Api.options()) :: Nostrum.Api.error() | {:ok, Nostrum.Struct.Channel.guild_channel()}
Creates a channel for a guild.
This endpoint requires the MANAGE_CHANNELS
permission. It fires a
Nostrum.Consumer.channel_create/0
event.
If successful, returns {:ok, channel}
. Otherwise, returns a Nostrum.Api.error/0
.
Options
:name
(string) - channel name (2-100 characters):type
(integer) - the type of channel (SeeNostrum.Struct.Channel
):topic
(string) - channel topic (0-1024 characters):bitrate
(integer) - the bitrate (in bits) of the voice channel (voice only):user_limit
(integer) - the user limit of the voice channel (voice only):permission_overwrites
(list ofNostrum.Struct.Overwrite.t/0
or equivalent map) - the channel's permission overwrites:parent_id
(Nostrum.Struct.Channel.id/0
) - id of the parent category for a channel:nsfw
(boolean) - if the channel is nsfw
:name
is always required.
Examples
Nostrum.Api.Channel.create(81384788765712384, name: "elixir-nostrum", topic: "craig's domain")
{:ok, %Nostrum.Struct.Channel{guild_id: 81384788765712384}}
@spec delete(Nostrum.Struct.Channel.id(), Nostrum.Struct.Guild.AuditLogEntry.reason()) :: Nostrum.Api.error() | {:ok, Nostrum.Struct.Channel.t()}
Deletes a channel.
An optional reason
can be provided for the guild audit log.
If deleting a Nostrum.Struct.Channel.guild_channel/0
, this endpoint requires
the MANAGE_CHANNELS
permission. It fires a
Nostrum.Consumer.channel_delete/0
. If a Nostrum.Struct.Channel.guild_category_channel/0
is deleted, then a Nostrum.Consumer.channel_update/0
event will fire
for each channel under the category.
If successful, returns {:ok, channel}
. Otherwise, returns a Nostrum.Api.error/0
.
Examples
Nostrum.Api.Channel.delete(421533712753360896)
{:ok, %Nostrum.Struct.Channel{id: 421533712753360896}}
@spec delete_permissions( Nostrum.Struct.Channel.id(), integer(), Nostrum.Struct.Guild.AuditLogEntry.reason() ) :: Nostrum.Api.error() | {:ok}
Delete a channel permission for a user or role.
Role or user overwrite to delete is specified by channel_id
and overwrite_id
.
An optional reason
can be given for the audit log.
@spec edit_permissions( Nostrum.Struct.Channel.id(), integer(), %{ :type => String.t(), optional(:allow) => integer(), optional(:deny) => integer() }, Nostrum.Struct.Guild.AuditLogEntry.reason() ) :: Nostrum.Api.error() | {:ok}
Edit the permission overwrites for a user or role.
Role or user to overwrite is specified by overwrite_id
.
permission_info
is a map with the following keys:
type
- Required;member
if editing a user,role
if editing a role.allow
- Bitwise value of allowed permissions.deny
- Bitwise value of denied permissions.type
-member
if editing a user,role
if editing a role.
An optional reason
can be provided for the audit log.
allow
and deny
are defaulted to 0
, meaning that even if you don't
specify them, they will override their respective former values in an
existing overwrite.
@spec get(Nostrum.Struct.Channel.id()) :: Nostrum.Api.error() | {:ok, Nostrum.Struct.Channel.t()}
Gets a channel.
If successful, returns {:ok, channel}
. Otherwise, returns a Nostrum.Api.error/0
.
Examples
Nostrum.Api.Channel.get(381889573426429952)
{:ok, %Nostrum.Struct.Channel{id: 381889573426429952}}
@spec messages( Nostrum.Struct.Channel.id(), Nostrum.Api.limit(), Nostrum.Api.locator() ) :: Nostrum.Api.error() | {:ok, [Nostrum.Struct.Message.t()]}
Retrieves a channel's messages around a locator
up to a limit
.
This endpoint requires the 'VIEW_CHANNEL' permission. If the current user is missing the 'READ_MESSAGE_HISTORY' permission, then this function will return no messages.
If successful, returns {:ok, messages}
. Otherwise, returns a Nostrum.Api.error/0
.
Examples
Nostrum.Api.Channel.messages(43189401384091, 5, {:before, 130230401384})
@spec modify( Nostrum.Struct.Channel.id(), Nostrum.Api.options(), Nostrum.Struct.Guild.AuditLogEntry.reason() ) :: Nostrum.Api.error() | {:ok, Nostrum.Struct.Channel.t()}
Modifies a channel's settings.
An optional reason
can be given for the guild audit log.
If a Nostrum.Struct.Channel.guild_channel/0
is being modified, this
endpoint requires the MANAGE_CHANNEL
permission. It fires a
Nostrum.Consumer.channel_update/0
event. If a
Nostrum.Struct.Channel.guild_category_channel/0
is being modified, then this
endpoint fires multiple Nostrum.Consumer.channel_update/0
events.
If successful, returns {:ok, channel}
. Otherwise, returns a Nostrum.Api.error/0
.
Options
:name
(string) - 2-100 character channel name:position
(integer) - the position of the channel in the left-hand listing:topic
(string) (Nostrum.Struct.Channel.text_channel/0
only) - 0-1024 character channel topic:nsfw
(boolean) (Nostrum.Struct.Channel.text_channel/0
only) - if the channel is nsfw:bitrate
(integer) (Nostrum.Struct.Channel.voice_channel/0
only) - the bitrate (in bits) of the voice channel; 8000 to 96000 (128000 for VIP servers):user_limit
(integer) (Nostrum.Struct.Channel.voice_channel/0
only) - the user limit of the voice channel; 0 refers to no limit, 1 to 99 refers to a user limit:permission_overwrites
(list ofNostrum.Struct.Overwrite.t/0
or equivalent map) - channel or category-specific permissions:parent_id
(Nostrum.Struct.Channel.id/0
) (Nostrum.Struct.Channel.guild_channel/0
only) - id of the new parent category for a channel
Examples
Nostrum.Api.Channel.modify(41771983423143933, name: "elixir-nostrum", topic: "nostrum discussion")
{:ok, %Nostrum.Struct.Channel{id: 41771983423143933, name: "elixir-nostrum", topic: "nostrum discussion"}}
Nostrum.Api.Channel.modify(41771983423143933)
{:ok, %Nostrum.Struct.Channel{id: 41771983423143933}}
@spec pin_message(Nostrum.Struct.Channel.id(), Nostrum.Struct.Message.id()) :: Nostrum.Api.error() | {:ok}
Pins a message in a channel.
This endpoint requires the 'VIEW_CHANNEL', 'READ_MESSAGE_HISTORY', and
'MANAGE_MESSAGES' permissions. It fires the
Nostrum.Consumer.message_update/0
and
Nostrum.Consumer.channel_pins_update/0
events.
If successful, returns {:ok}
. Otherwise, returns a Nostrum.Api.error/0
.
Examples
Nostrum.Api.Channel.pin_message(43189401384091, 18743893102394)
@spec pinned_messages(Nostrum.Struct.Channel.id()) :: Nostrum.Api.error() | {:ok, [Nostrum.Struct.Message.t()]}
Retrieves all pinned messages from a channel.
This endpoint requires the 'VIEW_CHANNEL' and 'READ_MESSAGE_HISTORY' permissions.
If successful, returns {:ok, messages}
. Otherwise, returns a Nostrum.Api.error/0
.
Examples
Nostrum.Api.Channel.pinned_messages(43189401384091)
@spec start_typing(integer()) :: Nostrum.Api.error() | {:ok}
Triggers the typing indicator.
Triggers the typing indicator in the channel specified by channel_id
.
The typing indicator lasts for about 8 seconds and then automatically stops.
Returns {:ok}
if successful. error
otherwise.
@spec unpin_message(Nostrum.Struct.Channel.id(), Nostrum.Struct.Message.id()) :: Nostrum.Api.error() | {:ok}
Unpins a message in a channel.
This endpoint requires the 'VIEW_CHANNEL', 'READ_MESSAGE_HISTORY', and
'MANAGE_MESSAGES' permissions. It fires the
Nostrum.Consumer.message_update/0
and
Nostrum.Consumer.channel_pins_update/0
events.
Returns {:ok}
if successful. error
otherwise.
@spec webhooks(Nostrum.Struct.Channel.id()) :: Nostrum.Api.error() | {:ok, [Nostrum.Struct.Webhook.t()]}
Gets a list of webhooks for a channel.
Parameters
channel_id
- Channel to get webhooks for.