Nostrum.Api.create_message

You're seeing just the function create_message, go back to Nostrum.Api module for more information.
Link to this function

create_message(channel_id, options)

View Source

Specs

Posts a message to a guild text or DM channel.

This endpoint requires the VIEW_CHANNEL and SEND_MESSAGES permissions. It may situationally need the SEND_MESSAGES_TTS permission. It fires the Nostrum.Consumer.message_create/0 event.

If options is a string, options will be used as the message's content.

If successful, returns {:ok, message}. Otherwise, returns a Nostrum.Api.error/0.

Options

  • :content (string) - the message contents (up to 2000 characters)
  • :nonce (Nostrum.Snowflake.t/0) - a nonce that can be used for optimistic message sending
  • :tts (boolean) - true if this is a TTS message
  • :file (Path.t/0 | map) - the path of the file being sent, or a map with the following keys if sending a binary from memory
    • :name (string) - the name of the file
    • :body (string) - binary you wish to send
  • :embed (Nostrum.Struct.Embed.t/0) - embedded rich content
  • :allowed_mentions - See "Allowed mentions" below
  • :message_reference (map) - See "Message references" below

At least one of the following is required: :content, :file, :embed.

Allowed mentions

With this option you can control when content from a message should trigger a ping. Consider using this option when you are going to display user_generated content.

Allowed values

  • :all (default) - Ping everything as usual
  • :none - Nobody will be pinged
  • :everyone - Allows to ping @here and @everone
  • :user - Allows to ping users
  • :roles - Allows to ping roles
  • {:user, list} - Allows to ping list of users. Can contain up to 100 ids of users.
  • {:role, list} - Allows to ping list of roles. Can contain up to 100 ids of roles.
  • list - a list containing the values above.

Message reference

You can create a reply to another message on guilds using this option, given that you have the VIEW_MESSAGE_HISTORY permission. To do so, include the message_reference field in your call. The complete structure documentation can be found on the Discord Developer Portal, but simply passing message_id will suffice:

def my_command(msg) do
  # Reply to the author - ``msg`` is a ``Nostrum.Struct.Message``
  Nostrum.Api.create_message(
    msg.channel_id,
    content: "Hello",
    message_reference: %{message_id: msg.id}
  )
end

Passing a list will merge the settings provided

Examples

Nostrum.Api.create_message(43189401384091, content: "hello world!")

Nostrum.Api.create_message(43189401384091, "hello world!")

import Nostrum.Struct.Embed
embed =
  %Nostrum.Struct.Embed{}
  |> put_title("embed")
  |> put_description("new desc")
Nostrum.Api.create_message(43189401384091, embed: embed)

Nostrum.Api.create_message(43189401384091, file: "/path/to/file.txt")

Nostrum.Api.create_message(43189401384091, content: "hello world!", embed: embed, file: "/path/to/file.txt")

Nostrum.Api.create_message(43189401384091, content: "Hello @everyone", allowed_mentions: :none)