Method: Discordrb::Bot#send_message

Defined in:
lib/discordrb/bot.rb

#send_message(channel, content, tts = false, embed = nil, attachments = nil, allowed_mentions = nil, message_reference = nil, components = nil) ⇒ Message

Sends a text message to a channel given its ID and the message's content.

Parameters:

  • channel (Channel, String, Integer)

    The channel, or its ID, to send something to.

  • content (String)

    The text that should be sent as a message. It is limited to 2000 characters (Discord imposed).

  • tts (true, false) (defaults to: false)

    Whether or not this message should be sent using Discord text-to-speech.

  • embed (Hash, Discordrb::Webhooks::Embed, nil) (defaults to: nil)

    The rich embed to append to this message.

  • allowed_mentions (Hash, Discordrb::AllowedMentions, false, nil) (defaults to: nil)

    Mentions that are allowed to ping on this message. false disables all pings

  • message_reference (Message, String, Integer, nil) (defaults to: nil)

    The message, or message ID, to reply to if any.

  • components (View, Array<Hash>) (defaults to: nil)

    Interaction components to associate with this message.

Returns:

  • (Message)

    The message that was sent.



389
390
391
392
393
394
395
396
397
# File 'lib/discordrb/bot.rb', line 389

def send_message(channel, content, tts = false, embed = nil, attachments = nil, allowed_mentions = nil, message_reference = nil, components = nil)
  channel = channel.resolve_id
  debug("Sending message to #{channel} with content '#{content}'")
  allowed_mentions = { parse: [] } if allowed_mentions == false
  message_reference = { message_id: message_reference.id } if message_reference.respond_to?(:id)

  response = API::Channel.create_message(token, channel, content, tts, embed&.to_hash, nil, attachments, allowed_mentions&.to_hash, message_reference, components)
  Message.new(JSON.parse(response), self)
end