Class: Discorb::CustomEmoji

Inherits:
Emoji
  • Object
show all
Defined in:
lib/discorb/emoji.rb

Overview

Represents a custom emoji in discord.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Emoji

#==, #eql?

Instance Attribute Details

#available -> Boolean (readonly) Also known as: available?

Returns whether the emoji is available.

Returns:

  • (Boolean)

    whether the emoji is available.



46
47
48
# File 'lib/discorb/emoji.rb', line 46

def available
  @available
end

#guild -> Discorb::Guild (readonly)

Returns The guild that owns this emoji.

Returns:



38
39
40
# File 'lib/discorb/emoji.rb', line 38

def guild
  @guild
end

#id -> Discorb::Snowflake (readonly)

Returns The ID of the emoji.

Returns:



30
31
32
# File 'lib/discorb/emoji.rb', line 30

def id
  @id
end

#managed -> Boolean (readonly) Also known as: managed?

Returns whether the emoji is managed by integration (ex: Twitch).

Returns:

  • (Boolean)

    whether the emoji is managed by integration (ex: Twitch).



40
41
42
# File 'lib/discorb/emoji.rb', line 40

def managed
  @managed
end

#name -> String (readonly)

Returns The name of the emoji.

Returns:

  • (String)

    The name of the emoji.



32
33
34
# File 'lib/discorb/emoji.rb', line 32

def name
  @name
end

#require_colons -> Boolean (readonly) Also known as: require_colons?

Returns whether the emoji requires colons.

Returns:

  • (Boolean)

    whether the emoji requires colons.



43
44
45
# File 'lib/discorb/emoji.rb', line 43

def require_colons
  @require_colons
end

#roles -> Array<Discorb::Role> (readonly)

Returns The roles that can use this emoji.

Returns:



34
35
36
# File 'lib/discorb/emoji.rb', line 34

def roles
  @roles
end

#roles? -> Boolean (readonly) Also known as: role?

Returns whether or not this emoji is restricted to certain roles.

Returns:

  • (Boolean)

    whether or not this emoji is restricted to certain roles.



# File 'lib/discorb/emoji.rb', line 49

#user -> Discorb::User (readonly)

Returns The user that created this emoji.

Returns:



36
37
38
# File 'lib/discorb/emoji.rb', line 36

def user
  @user
end

Instance Method Details

#delete(reason: nil) -> Async::Task<self> Also known as: destroy

Delete the emoji.

Parameters:

  • reason (String) (defaults to: nil)

    The reason for deleting the emoji.

Returns:

  • (Async::Task<self>)

    The deleted emoji.



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/discorb/emoji.rb', line 136

def delete(reason: nil)
  Async do
    @client
      .http
      .request(
        Route.new(
          "/guilds/#{@guild.id}/emojis/#{@id}",
          "//guilds/:guild_id/emojis/:emoji_id",
          :delete
        ),
        {},
        audit_log_reason: reason
      )
      .wait
    @available = false
    self
  end
end

#edit(name: Discorb::Unset, roles: Discorb::Unset, reason: nil) -> Async::Task<self> Also known as: modify

Note:

The arguments of this method are defaultly set to Discorb::Unset. Specify value to set the value, if not don't specify or specify Discorb::Unset.

Edit the emoji.

Parameters:

  • name (String) (defaults to: Discorb::Unset)

    The new name of the emoji.

  • roles (Array<Discorb::Role>) (defaults to: Discorb::Unset)

    The new roles that can use this emoji.

  • reason (String) (defaults to: nil)

    The reason for editing the emoji.

Returns:

  • (Async::Task<self>)

    The edited emoji.



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/discorb/emoji.rb', line 106

def edit(name: Discorb::Unset, roles: Discorb::Unset, reason: nil)
  Async do
    payload = {}
    payload[:name] = name if name != Discorb::Unset
    payload[:roles] = roles.map do |r|
      Discorb::Utils.try(r, :id)
    end if roles != Discorb::Unset
    @client.http.request(
      Route.new(
        "/guilds/#{@guild.id}/emojis/#{@id}",
        "//guilds/:guild_id/emojis/:emoji_id",
        :patch
      ),
      payload,
      audit_log_reason: reason
    )
    self
  end
end

#inspect -> Object



91
92
93
# File 'lib/discorb/emoji.rb', line 91

def inspect
  "#<#{self.class} id=#{@id} :#{@name}:>"
end

#to_s -> String

Format the emoji for sending.

Returns:

  • (String)

    the formatted emoji.



72
73
74
# File 'lib/discorb/emoji.rb', line 72

def to_s
  "<#{@animated ? "a" : ""}:#{@name}:#{id}>"
end

#to_uri -> String

Format the emoji for URI.

Returns:

  • (String)

    the formatted emoji.



81
82
83
# File 'lib/discorb/emoji.rb', line 81

def to_uri
  "#{@name}:#{@id}"
end