Class: Discorb::GuildTemplate

Inherits:
DiscordModel show all
Defined in:
lib/discorb/guild_template.rb

Overview

Represents a guild template.

Defined Under Namespace

Classes: TemplateGuild

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from DiscordModel

#==, #eql?, #hash

Instance Attribute Details

#code -> String (readonly)

Returns The code of the template.

Returns:

  • (String)

    The code of the template.



9
10
11
# File 'lib/discorb/guild_template.rb', line 9

def code
  @code
end

#created_at -> Time (readonly)

Returns The time this template was created.

Returns:

  • (Time)

    The time this template was created.



19
20
21
# File 'lib/discorb/guild_template.rb', line 19

def created_at
  @created_at
end

#creator -> Discorb::User (readonly)

Returns The user who created this template.

Returns:



17
18
19
# File 'lib/discorb/guild_template.rb', line 17

def creator
  @creator
end

#description -> String (readonly)

Returns The description of the template.

Returns:

  • (String)

    The description of the template.



13
14
15
# File 'lib/discorb/guild_template.rb', line 13

def description
  @description
end

#is_dirty -> Boolean (readonly) Also known as: dirty?

Returns Whether this template is dirty.

Returns:

  • (Boolean)

    Whether this template is dirty.



28
29
30
# File 'lib/discorb/guild_template.rb', line 28

def is_dirty
  @is_dirty
end

#name -> String (readonly)

Returns The name of the template.

Returns:

  • (String)

    The name of the template.



11
12
13
# File 'lib/discorb/guild_template.rb', line 11

def name
  @name
end

#serialized_source_guild -> Discorb::GuildTemplate::TemplateGuild (readonly) Also known as: content

Returns The guild where the template was created.

Returns:



25
26
27
# File 'lib/discorb/guild_template.rb', line 25

def serialized_source_guild
  @serialized_source_guild
end

#source_guild -> nil, Discorb::Guild (readonly)

Note:

This method returns an object from client cache. it will return nil if the object is not in cache.

Returns:

  • (nil)

    The object wasn't cached.

  • (Discorb::Guild)

    The guild this template is based on.

  • (nil)

    Client wasn't able to find the guild this template is based on.



# File 'lib/discorb/guild_template.rb', line 31

#source_guild_id -> Discorb::Guild (readonly)

Returns The guild where the template was created.

Returns:



23
24
25
# File 'lib/discorb/guild_template.rb', line 23

def source_guild_id
  @source_guild_id
end

#updated_at -> Time (readonly)

Returns The time this template was last updated.

Returns:

  • (Time)

    The time this template was last updated.



21
22
23
# File 'lib/discorb/guild_template.rb', line 21

def updated_at
  @updated_at
end

#usage_count -> Integer (readonly)

Returns The number of times this template has been used.

Returns:

  • (Integer)

    The number of times this template has been used.



15
16
17
# File 'lib/discorb/guild_template.rb', line 15

def usage_count
  @usage_count
end

Instance Method Details

#delete! -> Object Also known as: destroy!

Note:

This is an asynchronous method, it will return a Async::Task object. Use Async::Task#wait to get the result.

Note:

This method calls HTTP request.

Delete the template.

Raises:



83
84
85
86
87
# 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(name = nil, description = :unset) -> Object Also known as: modify

Note:

This is an asynchronous method, it will return a Async::Task object. Use Async::Task#wait to get the result.

Note:

This method calls HTTP request.

Note:

The arguments of this method are defaultly set to :unset. Specify value to set the value, if not don't specify or specify :unset.

Edit the template.

Parameters:

  • name (String) (defaults to: nil)

    The new name of the template.

  • description (String) (defaults to: :unset)

    The new description of the template.

Raises:



55
56
57
58
59
60
61
62
# 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

#update -> Object

Note:

This is an asynchronous method, it will return a Async::Task object. Use Async::Task#wait to get the result.

Note:

This method calls HTTP request.

Update the template.

Raises:



71
72
73
74
75
76
# 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