Method: Discordrb::Message#edit

Defined in:
lib/discordrb/data/message.rb

#edit(new_content, new_embeds = nil, new_components = nil) ⇒ Message

Edits this message to have the specified content instead. You can only edit your own messages.

Parameters:

  • new_content (String)

    the new content the message should have.

  • new_embeds (Hash, Discordrb::Webhooks::Embed, Array<Hash>, Array<Discordrb::Webhooks::Embed>, nil) (defaults to: nil)

    The new embeds the message should have. If nil the message will be changed to have no embeds.

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

    The new components the message should have. If nil the message will be changed to have no components.

Returns:

  • (Message)

    the resulting message.



199
200
201
202
203
204
205
# File 'lib/discordrb/data/message.rb', line 199

def edit(new_content, new_embeds = nil, new_components = nil)
  new_embeds = (new_embeds.instance_of?(Array) ? new_embeds.map(&:to_hash) : [new_embeds&.to_hash]).compact
  new_components = new_components&.to_a || []

  response = API::Channel.edit_message(@bot.token, @channel.id, @id, new_content, [], new_embeds, new_components)
  Message.new(JSON.parse(response), @bot)
end