class Discorb::CustomEmoji

Represents a custom emoji in discord.

Attributes

available[R]

@return [Boolean] whether the emoji is available.

available?[R]

@return [Boolean] whether the emoji is available.

guild[R]

@return [Boolean] Whether the emoji requires colons.

id[R]

@return [Discorb::Snowflake] The ID of the emoji.

managed[R]

@return [Boolean] whether the emoji is managed by integration (ex: Twitch).

managed?[R]

@return [Boolean] whether the emoji is managed by integration (ex: Twitch).

name[R]

@return [String] The name of the emoji.

require_colons[R]

@return [Boolean] whether the emoji requires colons.

require_colons?[R]

@return [Boolean] whether the emoji requires colons.

roles[R]

@return [Array<Discorb::Role>] The roles that can use this emoji.

user[R]

@return [Discorb::User] The user that created this emoji.

Public Class Methods

new(client, guild, data) click to toggle source

@!visibility private

# File lib/discorb/emoji.rb, line 44
def initialize(client, guild, data)
  @client = client
  @guild = guild
  @data = {}
  _set_data(data)
end

Public Instance Methods

delete!(reason: nil) click to toggle source

Delete the emoji. @macro async @macro http

@param [String] reason The reason for deleting the emoji.

@return [self] The deleted emoji.

# File lib/discorb/emoji.rb, line 112
def delete!(reason: nil)
  Async do
    @client.http.delete("/guilds/#{@guild.id}/emojis/#{@id}", audit_log_reason: reason).wait
    @available = false
    self
  end
end
Also aliased as: destroy!
destroy!(reason: nil)
Alias for: delete!
edit(name: :unset, roles: :unset, reason: nil) click to toggle source

Edit the emoji. @macro async @macro http @macro edit

@param [String] name The new name of the emoji. @param [Array<Discorb::Role>] roles The new roles that can use this emoji. @param [String] reason The reason for editing the emoji.

@return [self] The edited emoji.

# File lib/discorb/emoji.rb, line 91
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
Also aliased as: modify
inspect() click to toggle source
# File lib/discorb/emoji.rb, line 75
def inspect
  "#<#{self.class} id=#{@id} :#{@name}:>"
end
modify(name: :unset, roles: :unset, reason: nil)
Alias for: edit
role?()
Alias for: roles?
roles?() click to toggle source
# File lib/discorb/emoji.rb, line 69
def roles?
  @roles != []
end
Also aliased as: role?
to_s() click to toggle source

Format the emoji for sending.

@return [String] the formatted emoji.

# File lib/discorb/emoji.rb, line 56
def to_s
  "<#{@animated ? "a" : ""}:#{@name}:#{id}>"
end
to_uri() click to toggle source

Format the emoji for URI.

@return [String] the formatted emoji.

# File lib/discorb/emoji.rb, line 65
def to_uri
  "#{@name}:#{@id}"
end

Private Instance Methods

_set_data(data) click to toggle source
# File lib/discorb/emoji.rb, line 124
def _set_data(data)
  @id = Snowflake.new(data[:id])
  @name = data[:name]
  @roles = data[:role] ? data[:role].map { |r| Role.new(@client, r) } : []
  @user = User.new(@client, data[:user]) if data[:user]
  @require_colons = data[:require_colons]
  @managed = data[:managed]
  @animated = data[:animated]
  @available = data[:available]
  @guild.emojis[@id] = self unless data[:no_cache]
  @data.update(data)
end