Lingo.Api.Message (Lingo v0.4.2)

Copy Markdown View Source

Messages: sending, forwarding, editing, deleting, bulk deletion and search.

Every function returns {:ok, result}, :ok when Discord sends no body, or {:error, %Lingo.Error{}}. Calls go to the current bot (see Lingo.with_bot/2).

Summary

Types

A page of search results. messages nests each match in a list of its own, as Discord sends them; threads are the threads they're in, and members the bot's membership in those it has joined.

Functions

Deletes many messages at once, in chunks of 100. Messages older than two weeks can't be bulk deleted.

Sends a message. Pass a string, or a map or keyword list of message fields, including :files as {name, binary} tuples.

Publishes a message in an announcement channel to its followers.

Forwards a message into channel_id. The bot must be able to read the message's content (Discord answers code 160014 otherwise).

Fetches a message.

Lists a channel's messages, newest first. Takes limit:, before:, after: and around:.

Searches a guild's messages with Discord's search options (content:, author_id:, channel_id:, has:, limit:, offset:...); options that take several values take lists. Retries while Discord is still indexing the guild: :search_index_retries times (3), waiting what Discord asks or :search_index_short_delay ms (1000).

Edits a message the bot sent.

Types

search_result()

@type search_result() :: %{
  doing_deep_historical_index: boolean(),
  documents_indexed: non_neg_integer() | nil,
  total_results: non_neg_integer(),
  messages: [[Lingo.Type.Message.t()]],
  threads: [Lingo.Type.Channel.t()],
  members: [Lingo.Type.ThreadMember.t()]
}

A page of search results. messages nests each match in a list of its own, as Discord sends them; threads are the threads they're in, and members the bot's membership in those it has joined.

Functions

bulk_delete(channel_id, message_ids, opts \\ [])

@spec bulk_delete(Lingo.Api.id(), [Lingo.Api.id()], keyword()) :: Lingo.Api.result()

Deletes many messages at once, in chunks of 100. Messages older than two weeks can't be bulk deleted.

create(channel_id, content)

Sends a message. Pass a string, or a map or keyword list of message fields, including :files as {name, binary} tuples.

crosspost(channel_id, message_id)

Publishes a message in an announcement channel to its followers.

delete(channel_id, message_id, opts \\ [])

@spec delete(Lingo.Api.id(), Lingo.Api.id(), keyword()) :: Lingo.Api.result()

Deletes a message.

forward(channel_id, from_channel_id, message_id)

Forwards a message into channel_id. The bot must be able to read the message's content (Discord answers code 160014 otherwise).

get(channel_id, message_id)

Fetches a message.

list(channel_id, opts \\ [])

Lists a channel's messages, newest first. Takes limit:, before:, after: and around:.

search(guild_id, opts \\ [])

@spec search(
  Lingo.Api.id(),
  keyword()
) :: Lingo.Api.result(search_result())

Searches a guild's messages with Discord's search options (content:, author_id:, channel_id:, has:, limit:, offset:...); options that take several values take lists. Retries while Discord is still indexing the guild: :search_index_retries times (3), waiting what Discord asks or :search_index_short_delay ms (1000).

update(channel_id, message_id, params)

Edits a message the bot sent.

:attachments lists every attachment to keep, by :id, and may change their :description or mark them is_spoiler: true; new :files are added to them.