class Discorb::GuildTemplate

Represents a guild template.

Attributes

code[R]

@return [String] The code of the template.

content[R]

@return [Discorb::GuildTemplate::TemplateGuild] The guild where the template was created.

created_at[R]

@return [Time] The time this template was created.

creator[R]

@return [Discorb::User] The user who created this template.

description[R]

@return [String] The description of the template.

dirty?[R]

@return [Boolean] Whether this template is dirty.

is_dirty[R]

@return [Boolean] Whether this template is dirty.

name[R]

@return [String] The name of the template.

serialized_source_guild[R]

@return [Discorb::GuildTemplate::TemplateGuild] The guild where the template was created.

source_guild_id[R]

@return [Discorb::Guild] The guild where the template was created.

updated_at[R]

@return [Time] The time this template was last updated.

usage_count[R]

@return [Integer] The number of times this template has been used.

Public Class Methods

new(client, data) click to toggle source

@!visibility private

# File lib/discorb/guild_template.rb, line 37
def initialize(client, data)
  @client = client
  _set_data(data)
end

Public Instance Methods

delete!() click to toggle source

Delete the template. @macro async @macro http

# File lib/discorb/guild_template.rb, line 83
def delete!
  Async do
    @client.http.delete("/guilds/#{@source_guild_id}/templates/#{@code}").wait
  end
end
Also aliased as: destroy!
destroy!()
Alias for: delete!
edit(name = nil, description = :unset) click to toggle source

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

@param [String] name The new name of the template. @param [String] description The new description of the template.

# File lib/discorb/guild_template.rb, line 55
def edit(name = nil, description = :unset)
  Async do
    payload = {}
    payload[:name] = name if name
    payload[:description] = description if description != :unset
    @client.http.patch("/guilds/#{@source_guild_id}/templates/#{@code}", payload).wait
  end
end
Also aliased as: modify
modify(name = nil, description = :unset)
Alias for: edit
source_guild() click to toggle source
# File lib/discorb/guild_template.rb, line 42
def source_guild
  @client.guilds[@source_guild_id]
end
update() click to toggle source

Update the template. @macro async @macro http

# File lib/discorb/guild_template.rb, line 71
def update
  Async do
    _resp, data = @client.http.put("/guilds/#{@source_guild_id}/templates/#{@code}").wait
    _set_data(data)
  end
end

Private Instance Methods

_set_data(data) click to toggle source
# File lib/discorb/guild_template.rb, line 197
def _set_data(data)
  @code = data[:code]
  @name = data[:name]
  @description = data[:description]
  @usage_count = data[:usage_count]
  @creator_id = Snowflake.new(data[:creator_id])
  @creator = @client.users[@creator_id] || User.new(@client, data[:creator])
  @created_at = Time.iso8601(data[:created_at])
  @updated_at = Time.iso8601(data[:updated_at])
  @source_guild_id = Snowflake.new(data[:source_guild_id])
  @serialized_source_guild = data[:serialized_source_guild]
  @is_dirty = data[:is_dirty]
end