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.



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

def available
  @available
end

#guild -> Boolean (readonly)

Returns Whether the emoji requires colons.

Returns:

  • (Boolean)

    Whether the emoji requires colons.



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

def guild
  @guild
end

#id -> Discorb::Snowflake (readonly)

Returns The ID of the emoji.

Returns:



25
26
27
# File 'lib/discorb/emoji.rb', line 25

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



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

def managed
  @managed
end

#name -> String (readonly)

Returns The name of the emoji.

Returns:

  • (String)

    The name of the emoji.



27
28
29
# File 'lib/discorb/emoji.rb', line 27

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.



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

def require_colons
  @require_colons
end

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

Returns The roles that can use this emoji.

Returns:



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

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 44

#user -> Discorb::User (readonly)

Returns The user that created this emoji.

Returns:



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

def user
  @user
end

Instance Method Details

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

Note:

This is an asynchronous method, it will return a Async::Task object. Use Async::Task#wait to get the result.

Note:

This method calls HTTP request.

Delete the emoji.

Parameters:

  • reason (String) (defaults to: nil)

    The reason for deleting the emoji.

Returns:

  • (Async::Task<self>)

    The deleted emoji.

Raises:



116
117
118
119
120
121
122
# File 'lib/discorb/emoji.rb', line 116

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

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

Note:

This is an asynchronous method, it will return a Async::Task object. Use Async::Task#wait to get the result.

Note:

This method calls HTTP request.

Note:

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

Edit the emoji.

Parameters:

  • name (String) (defaults to: :unset)

    The new name of the emoji.

  • roles (Array<Discorb::Role>) (defaults to: :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.

Raises:



95
96
97
98
99
100
101
102
103
# File 'lib/discorb/emoji.rb', line 95

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

#inspect -> Object



79
80
81
# File 'lib/discorb/emoji.rb', line 79

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

#to_s -> String

Format the emoji for sending.

Returns:

  • (String)

    the formatted emoji.



60
61
62
# File 'lib/discorb/emoji.rb', line 60

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

#to_uri -> String

Format the emoji for URI.

Returns:

  • (String)

    the formatted emoji.



69
70
71
# File 'lib/discorb/emoji.rb', line 69

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