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?, #inspect

Instance Attribute Details

#codeString (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_atTime (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

#creatorDiscorb::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

#descriptionString (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_dirtyBoolean (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

#nameString (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_guildDiscorb::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_guildnil, 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_idDiscorb::Snowflake (readonly)

Returns The ID of 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_atTime (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_countInteger (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

#deleteAsync::Task<void> Also known as: destroy

Delete the template.

Returns:

  • (Async::Task<void>)

    The task.



112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/discorb/guild_template.rb', line 112

def delete
  Async do
    @client
      .http
      .request(
        Route.new(
          "/guilds/#{@source_guild_id}/templates/#{@code}",
          "//guilds/:guild_id/templates/:code",
          :delete
        )
      )
      .wait
  end
end

#edit(name = nil, description = Discorb::Unset) ⇒ Async::Task<void> Also known as: modify

Note:

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

Edit the template.

Parameters:

  • name (String) (defaults to: nil)

    The new name of the template.

  • description (String) (defaults to: Discorb::Unset)

    The new description of the template.

Returns:

  • (Async::Task<void>)

    The task.



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/discorb/guild_template.rb', line 62

def edit(name = nil, description = Discorb::Unset)
  Async do
    payload = {}
    payload[:name] = name if name
    payload[:description] = description if description != Discorb::Unset
    @client
      .http
      .request(
        Route.new(
          "/guilds/#{@source_guild_id}/templates/#{@code}",
          "//guilds/:guild_id/templates/:code",
          :patch
        ),
        payload
      )
      .wait
  end
end

#updateAsync::Task<void>

Update the template.

Returns:

  • (Async::Task<void>)

    The task.



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/discorb/guild_template.rb', line 89

def update
  Async do
    _resp, data =
      @client
        .http
        .request(
          Route.new(
            "/guilds/#{@source_guild_id}/templates/#{@code}",
            "//guilds/:guild_id/templates/:code",
            :put
          )
        )
        .wait
    _set_data(data)
  end
end