Nostrum.Api.Channel (nostrum v0.11.0-dev)

View Source

Functions for interacting with the Discord API's channel endpoints.

See: https://discord.com/developers/docs/resources/channel

Summary

Functions

Deletes multiple messages from a channel.

Creates a channel for a guild.

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

bulk_delete_messages(channel_id, messages, filter \\ true)

(since 0.10.1)
@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.

create(guild_id, options)

(since 0.10.1)

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 (See Nostrum.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 of Nostrum.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}}

delete(channel_id, reason \\ nil)

(since 0.10.1)

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}}

delete_permissions(channel_id, overwrite_id, reason \\ nil)

(since 0.10.1)

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.

edit_permissions(channel_id, overwrite_id, permission_info, reason \\ nil)

(since 0.10.1)
@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.

get(channel_id)

(since 0.10.1)

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}}

messages(channel_id, limit, locator \\ {})

(since 0.10.1)

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})

modify(channel_id, options, reason \\ nil)

(since 0.10.1)

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

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}}

pin_message(channel_id, message_id)

(since 0.10.1)

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)

pinned_messages(channel_id)

(since 0.10.1)
@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)

start_typing(channel_id)

(since 0.10.1)
@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.

unpin_message(channel_id, message_id)

(since 0.10.1)

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.

webhooks(channel_id)

(since 0.10.1)

Gets a list of webhooks for a channel.

Parameters

  • channel_id - Channel to get webhooks for.