class Discorb::GuildTemplate
Represents a guild template.
Attributes
@return [String] The code of the template.
@return [Discorb::GuildTemplate::TemplateGuild] The guild where the template was created.
@return [Time] The time this template was created.
@return [Discorb::User] The user who created this template.
@return [String] The description of the template.
@return [Boolean] Whether this template is dirty.
@return [Boolean] Whether this template is dirty.
@return [String] The name of the template.
@return [Discorb::GuildTemplate::TemplateGuild] The guild where the template was created.
@return [Discorb::Guild] The guild where the template was created.
@return [Time] The time this template was last updated.
@return [Integer] The number of times this template has been used.
Public Class Methods
@!visibility private
# File lib/discorb/guild_template.rb, line 37 def initialize(client, data) @client = client _set_data(data) end
Public Instance Methods
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
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
# File lib/discorb/guild_template.rb, line 42 def source_guild @client.guilds[@source_guild_id] end
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
# 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