Module: Vox::HTTP::Routes::Emoji

Defined in:
lib/vox/http/routes/emoji.rb

Overview

Mixin for emoji routes.

Instance Method Summary collapse

Instance Method Details

#create_guild_emoji(guild_id, image:, name: :undef, roles: :undef) ⇒ Hash<Symbol, Object>

Note:

Attempting to upload an emoji image larger than 256kb will result in a Error::BadRequest with no JSON status code.

Create an emoji in a target guild.

Parameters:

  • guild_id (String, Integer)

    The ID of the guild to create an emoji in.

  • image (UploadIO)

    UploadIO for the emoji image. Can be up to 256kb in size.

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

    The name for the emoji.

  • roles (Array<String, Integer>) (defaults to: :undef)

    Roles for which the emoji will be whitelisted.

Returns:

Required Permissions:

  • MANAGE_EMOJIS

View On Discord's Docs:



46
47
48
49
50
51
52
53
# File 'lib/vox/http/routes/emoji.rb', line 46

def create_guild_emoji(guild_id, image:, name: :undef, roles: :undef)
  image_data = image.io.read
  json = filter_undef({ name: name, roles: roles,
                        image: "data:#{image.content_type};base64,#{Base64.encode64(image_data)}" })

  route = Route.new(:POST, '/guilds/%{guild_id}/emojis', guild_id: guild_id)
  request(route, json: json)
end

#delete_guild_emoji(guild_id, emoji_id, reason: nil) ⇒ nil

Delete an emoji by its ID.

Parameters:

  • guild_id (String, Integer)

    The ID of the guild that owns this emoji.

  • emoji_id (String, Integer)

    The ID of the emoji to be deleted.

  • reason (String) (defaults to: nil)

    The reason this emoji is being deleted.

Returns:

  • (nil)

    Returns ‘nil` on success.

Required Permissions:

  • MANAGE_EMOJIS

View On Discord's Docs:



79
80
81
82
83
# File 'lib/vox/http/routes/emoji.rb', line 79

def delete_guild_emoji(guild_id, emoji_id, reason: nil)
  route = Route.new(:DELETE, '/guilds/%{guild_id}/emojis/%{emoji_id}',
                    guild_id: guild_id, emoji_id: emoji_id)
  request(route, reason: reason)
end

#get_guild_emoji(guild_id, emoji_id) ⇒ Hash<Symbol, Object>

Get an emoji object by ID.

Parameters:

  • guild_id (String, Integer)

    The ID of the guild this emoji belongs to.

  • emoji_id (String, Integer)

    The ID of the desired emoji.

Returns:

View On Discord's Docs:



30
31
32
33
# File 'lib/vox/http/routes/emoji.rb', line 30

def get_guild_emoji(guild_id, emoji_id)
  route = Route.new(:GET, '/guilds/%{guild_id}/emojis/%{emoji_id}', guild_id: guild_id, emoji_id: emoji_id)
  request(route)
end

#list_guild_emojis(guild_id) ⇒ Array<Hash<Symbol, Object>>

Fetch a list of emojis for a given guild.

Parameters:

  • guild_id (String, Integer)

    The ID of the guild this emoji belongs to.

Returns:

View On Discord's Docs:



19
20
21
22
# File 'lib/vox/http/routes/emoji.rb', line 19

def list_guild_emojis(guild_id)
  route = Route.new(:GET, '/guilds/%{guild_id}/emojis', guild_id: guild_id)
  request(route)
end

#modify_guild_emoji(guild_id, emoji_id, name: :undef, roles: :undef, reason: nil) ⇒ Hash<Symbol, Object>

Modify a guild emoji.

Parameters:

  • guild_id (String, Integer)

    The ID of the guild the emoji is in.

  • emoji_id (String, Integer)

    The ID of the target emoji.

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

    The name for the emoji.

  • roles (Array<String, Integer>) (defaults to: :undef)

    Roles for which the emoji will be whitelisted.

  • reason (String) (defaults to: nil)

    The reason this emoji is being modified.

Returns:

Required Permissions:

  • MANAGE_EMOJIS

View On Discord's Docs:



65
66
67
68
69
70
# File 'lib/vox/http/routes/emoji.rb', line 65

def modify_guild_emoji(guild_id, emoji_id, name: :undef, roles: :undef, reason: nil)
  json = filter_undef({ name: name, roles: roles })
  route = Route.new(:PATCH, '/guilds/%{guild_id}/emojis/%{emoji_id}',
                    guild_id: guild_id, emoji_id: emoji_id)
  request(route, json: json, reason: reason)
end