class Discorb::CustomEmoji
Represents a custom emoji in discord.
Attributes
@return [Boolean] whether the emoji is available.
@return [Boolean] whether the emoji is available.
@return [Boolean] Whether the emoji requires colons.
@return [Discorb::Snowflake] The ID of the emoji.
@return [Boolean] whether the emoji is managed by integration (ex: Twitch).
@return [Boolean] whether the emoji is managed by integration (ex: Twitch).
@return [String] The name of the emoji.
@return [Boolean] whether the emoji requires colons.
@return [Boolean] whether the emoji requires colons.
@return [Array<Discorb::Role>] The roles that can use this emoji.
@return [Discorb::User] The user that created this emoji.
Public Class Methods
@!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 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
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
# File lib/discorb/emoji.rb, line 75 def inspect "#<#{self.class} id=#{@id} :#{@name}:>" end
# File lib/discorb/emoji.rb, line 69 def roles? @roles != [] end
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
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
# 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