Class: Discordrb::Message
- Inherits:
-
Object
- Object
- Discordrb::Message
- Includes:
- IDObject
- Defined in:
- lib/discordrb/data.rb
Overview
A message on Discord that was sent to a text channel
Constant Summary collapse
- ZERO_DISCRIM =
The discriminator that webhook user accounts have.
'0000'.freeze
Instance Attribute Summary collapse
-
#attachments ⇒ Array<Attachment>
readonly
The files attached to this message.
-
#author ⇒ Member
(also: #user, #writer)
readonly
The user that sent this message.
-
#channel ⇒ Channel
readonly
The channel in which this message was sent.
-
#content ⇒ String
(also: #text, #to_s)
readonly
The content of this message.
-
#edited ⇒ true, false
(also: #edited?)
readonly
Whether the message was edited or not.
-
#edited_timestamp ⇒ Time
(also: #edit_timestamp)
readonly
The timestamp at which this message was edited.
-
#embeds ⇒ Array<Embed>
readonly
The embed objects contained in this message.
-
#mention_everyone ⇒ true, false
(also: #mention_everyone?, #mentions_everyone?)
readonly
Whether the message mentioned everyone or not.
-
#mentions ⇒ Array<User>
readonly
The users that were mentioned in this message.
-
#nonce ⇒ String
readonly
Used for validating a message was sent.
-
#pinned ⇒ true, false
(also: #pinned?)
readonly
Whether the message is pinned or not.
-
#role_mentions ⇒ Array<Role>
readonly
The roles that were mentioned in this message.
-
#timestamp ⇒ Time
readonly
The timestamp at which this message was sent.
-
#tts ⇒ true, false
(also: #tts?)
readonly
Whether the message used Text-To-Speech (TTS) or not.
-
#webhook_id ⇒ Integer?
readonly
The webhook ID that sent this message, or nil if it wasn't sent through a webhook.
Attributes included from IDObject
Instance Method Summary collapse
-
#await(key, attributes = {}, &block) ⇒ Object
Add an Await for a message with the same user and channel.
-
#delete ⇒ Object
Deletes this message.
-
#edit(new_content) ⇒ Message
Edits this message to have the specified content instead.
-
#emoji ⇒ Array<Emoji>
The emotes that were used/mentioned in this message (Only returns Emoji the bot has access to, else nil).
-
#emoji? ⇒ true, false
Check if any emoji got used in this message.
-
#from_bot? ⇒ true, false
Whether this message was sent by the current Bot.
-
#inspect ⇒ Object
The inspect method is overwritten to give more useful output.
-
#pin ⇒ Object
Pins this message.
-
#reply(content) ⇒ Object
Replies to this message with the specified content.
-
#unpin ⇒ Object
Unpins this message.
-
#webhook? ⇒ true, false
Whether this message has been sent over a webhook.
Methods included from IDObject
Instance Attribute Details
#attachments ⇒ Array<Attachment> (readonly)
Returns the files attached to this message.
1622 1623 1624 |
# File 'lib/discordrb/data.rb', line 1622 def @attachments end |
#author ⇒ Member (readonly) Also known as: user, writer
Returns the user that sent this message.
1601 1602 1603 |
# File 'lib/discordrb/data.rb', line 1601 def @author end |
#channel ⇒ Channel (readonly)
Returns the channel in which this message was sent.
1606 1607 1608 |
# File 'lib/discordrb/data.rb', line 1606 def channel @channel end |
#content ⇒ String (readonly) Also known as: text, to_s
Returns the content of this message.
1596 1597 1598 |
# File 'lib/discordrb/data.rb', line 1596 def content @content end |
#edited ⇒ true, false (readonly) Also known as: edited?
Returns whether the message was edited or not.
1635 1636 1637 |
# File 'lib/discordrb/data.rb', line 1635 def edited @edited end |
#edited_timestamp ⇒ Time (readonly) Also known as: edit_timestamp
Returns the timestamp at which this message was edited. nil
if the message was never edited.
1612 1613 1614 |
# File 'lib/discordrb/data.rb', line 1612 def @edited_timestamp end |
#embeds ⇒ Array<Embed> (readonly)
Returns the embed objects contained in this message.
1625 1626 1627 |
# File 'lib/discordrb/data.rb', line 1625 def @embeds end |
#mention_everyone ⇒ true, false (readonly) Also known as: mention_everyone?, mentions_everyone?
Returns whether the message mentioned everyone or not.
1639 1640 1641 |
# File 'lib/discordrb/data.rb', line 1639 def mention_everyone @mention_everyone end |
#mentions ⇒ Array<User> (readonly)
Returns the users that were mentioned in this message.
1616 1617 1618 |
# File 'lib/discordrb/data.rb', line 1616 def mentions @mentions end |
#nonce ⇒ String (readonly)
Returns used for validating a message was sent.
1632 1633 1634 |
# File 'lib/discordrb/data.rb', line 1632 def nonce @nonce end |
#pinned ⇒ true, false (readonly) Also known as: pinned?
Returns whether the message is pinned or not.
1644 1645 1646 |
# File 'lib/discordrb/data.rb', line 1644 def pinned @pinned end |
#role_mentions ⇒ Array<Role> (readonly)
Returns the roles that were mentioned in this message.
1619 1620 1621 |
# File 'lib/discordrb/data.rb', line 1619 def role_mentions @role_mentions end |
#timestamp ⇒ Time (readonly)
Returns the timestamp at which this message was sent.
1609 1610 1611 |
# File 'lib/discordrb/data.rb', line 1609 def @timestamp end |
#tts ⇒ true, false (readonly) Also known as: tts?
Returns whether the message used Text-To-Speech (TTS) or not.
1628 1629 1630 |
# File 'lib/discordrb/data.rb', line 1628 def tts @tts end |
#webhook_id ⇒ Integer? (readonly)
Returns the webhook ID that sent this message, or nil if it wasn't sent through a webhook.
1648 1649 1650 |
# File 'lib/discordrb/data.rb', line 1648 def webhook_id @webhook_id end |
Instance Method Details
#await(key, attributes = {}, &block) ⇒ Object
Add an Await for a message with the same user and channel.
1748 1749 1750 |
# File 'lib/discordrb/data.rb', line 1748 def await(key, attributes = {}, &block) @bot.add_await(key, Discordrb::Events::MessageEvent, { from: @author.id, in: @channel.id }.merge(attributes), &block) end |
#delete ⇒ Object
Deletes this message.
1727 1728 1729 1730 |
# File 'lib/discordrb/data.rb', line 1727 def delete API::Channel.(@bot.token, @channel.id, @id) nil end |
#edit(new_content) ⇒ Message
Edits this message to have the specified content instead. You can only edit your own messages.
1721 1722 1723 1724 |
# File 'lib/discordrb/data.rb', line 1721 def edit(new_content) response = API::Channel.(@bot.token, @channel.id, @id, new_content) Message.new(JSON.parse(response), @bot) end |
#emoji ⇒ Array<Emoji>
Returns the emotes that were used/mentioned in this message (Only returns Emoji the bot has access to, else nil).
1771 1772 1773 1774 1775 1776 1777 1778 1779 |
# File 'lib/discordrb/data.rb', line 1771 def emoji return if @content.nil? emoji = scan_for_emoji emoji.each do |element| @emoji << @bot.parse_mention(element) end @emoji end |
#emoji? ⇒ true, false
Check if any emoji got used in this message
1783 1784 1785 1786 |
# File 'lib/discordrb/data.rb', line 1783 def emoji? emoji = scan_for_emoji return true unless emoji.empty? end |
#from_bot? ⇒ true, false
Returns whether this message was sent by the current Bot.
1753 1754 1755 |
# File 'lib/discordrb/data.rb', line 1753 def from_bot? @author && @author.current_bot? end |
#inspect ⇒ Object
The inspect method is overwritten to give more useful output
1789 1790 1791 |
# File 'lib/discordrb/data.rb', line 1789 def inspect "<Message content=\"#{@content}\" id=#{@id} timestamp=#{@timestamp} author=#{@author} channel=#{@channel}>" end |
#pin ⇒ Object
Pins this message
1733 1734 1735 1736 1737 |
# File 'lib/discordrb/data.rb', line 1733 def pin API::Channel.(@bot.token, @channel.id, @id) @pinned = true nil end |
#reply(content) ⇒ Object
Replies to this message with the specified content.
1713 1714 1715 |
# File 'lib/discordrb/data.rb', line 1713 def reply(content) @channel.(content) end |
#unpin ⇒ Object
Unpins this message
1740 1741 1742 1743 1744 |
# File 'lib/discordrb/data.rb', line 1740 def unpin API::Channel.(@bot.token, @channel.id, @id) @pinned = false nil end |
#webhook? ⇒ true, false
Returns whether this message has been sent over a webhook.
1758 1759 1760 |
# File 'lib/discordrb/data.rb', line 1758 def webhook? !@webhook_id.nil? end |