Method: Discordrb::Bot#send_temporary_message

Defined in:
lib/discordrb/bot.rb

#send_temporary_message(channel, content, timeout, tts = false, embed = nil, attachments = nil, allowed_mentions = nil, message_reference = nil, components = nil) ⇒ Object

Sends a text message to a channel given its ID and the message's content, then deletes it after the specified timeout in seconds.

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

  • timeout (Float)

    The amount of time in seconds after which the message sent will be deleted.

  • 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.

  • attachments (Array<File>) (defaults to: nil)

    Files that can be referenced in embeds via attachment://file.png

  • 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.



410
411
412
413
414
415
416
417
418
419
420
# File 'lib/discordrb/bot.rb', line 410

def send_temporary_message(channel, content, timeout, tts = false, embed = nil, attachments = nil, allowed_mentions = nil, message_reference = nil, components = nil)
  Thread.new do
    Thread.current[:discordrb_name] = "#{@current_thread}-temp-msg"

    message = send_message(channel, content, tts, embed, attachments, allowed_mentions, message_reference, components)
    sleep(timeout)
    message.delete
  end

  nil
end