disrb 0.1.2.2 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/disrb/guild.rb CHANGED
@@ -1,60 +1,72 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # DiscordApi
4
- # The class that contains everything that interacts with the Discord API.
3
+ # Class that contains functions that allow interacting with the Discord API.
5
4
  class DiscordApi
6
- def create_guild(name, region: nil, icon: nil, verification_level: nil, default_message_notifications: nil,
7
- explicit_content_filter: nil, roles: nil, channels: nil, afk_channel_id: nil, afk_timeout: nil,
8
- system_channel_id: nil, system_channel_flags: nil)
9
- output = {}
10
- output[:name] = name
11
- unless region.nil?
12
- @logger.warn('The "region" parameter has been deprecated and should not be used!')
13
- output[:region] = region
14
- end
15
- output[:icon] = icon unless icon.nil?
16
- output[:verification_level] = verification_level unless verification_level.nil?
17
- output[:default_message_notifications] = default_message_notifications unless default_message_notifications.nil?
18
- output[:explicit_content_filter] = explicit_content_filter unless explicit_content_filter.nil?
19
- output[:roles] = roles unless roles.nil?
20
- output[:channels] = channels unless channels.nil?
21
- output[:afk_channel_id] = afk_channel_id unless afk_channel_id.nil?
22
- output[:afk_timeout] = afk_timeout unless afk_timeout.nil?
23
- output[:system_channel_id] = system_channel_id unless system_channel_id.nil?
24
- output[:system_channel_flags] = system_channel_flags unless system_channel_flags.nil?
25
- url = "#{@base_url}/guilds"
26
- data = JSON.generate(output)
27
- headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
28
- response = DiscordApi.post(url, data, headers)
29
- return response if response.status == 200
30
-
31
- @logger.error("Could not create guild. Response: #{response.body}")
32
- response
33
- end
34
-
5
+ # Gets a guild object with the specified guild ID. See https://discord.com/developers/docs/resources/guild#get-guild
6
+ # @param guild_id [String] ID (as a string) of the guild to get.
7
+ # @param with_counts [TrueClass, FalseClass, nil] Whether to include approximate member and presence counts.
8
+ # @return [Faraday::Response] The response from the Discord API as a Faraday::Response object.
35
9
  def get_guild(guild_id, with_counts = nil)
36
10
  query_string_hash = {}
37
11
  query_string_hash[:with_counts] = with_counts unless with_counts.nil?
38
12
  query_string = DiscordApi.handle_query_strings(query_string_hash)
39
13
  url = "#{@base_url}/guilds/#{guild_id}#{query_string}"
40
14
  headers = { 'Authorization' => @authorization_header }
41
- response = DiscordApi.get(url, headers)
42
- return response if response.status == 200
15
+ response = get(url, headers)
16
+ return response if response.is_a?(Faraday::Response) && response.status == 200
43
17
 
44
- @logger.error("Could not get guild with Guild ID #{guild_id}. Response: #{response.body}")
18
+ @logger.error("Could not get guild with Guild ID #{guild_id}. Response: #{response_error_body(response)}")
45
19
  response
46
20
  end
47
21
 
22
+ # Gets the guild preview object for the specified guild ID.
23
+ # See https://discord.com/developers/docs/resources/guild#get-guild-preview
24
+ # @param guild_id [String] ID (as a string) of the guild to get the preview for.
25
+ # @return [Faraday::Response] The response from the Discord API as a Faraday::Response object.
48
26
  def get_guild_preview(guild_id)
49
27
  url = URI("#{@base_url}/guilds/#{guild_id}/preview")
50
28
  headers = { 'Authorization': @authorization_header }
51
- response = DiscordApi.get(url, headers)
52
- return response if response.status == 200
29
+ response = get(url, headers)
30
+ return response if response.is_a?(Faraday::Response) && response.status == 200
53
31
 
54
- @logger.error("Could not get guild preview with Guild ID #{guild_id}. Response: #{response.body}")
32
+ @logger.error("Could not get guild preview with Guild ID #{guild_id}. Response: #{response_error_body(response)}")
55
33
  response
56
34
  end
57
35
 
36
+ # Modifies a guild with the specified guild ID. See https://discord.com/developers/docs/resources/guild#modify-guild
37
+ #
38
+ # If none of the optional parameters are provided (guild modifications), the function will log a warning and return
39
+ # nil.
40
+ # @param name [String, nil] The new name of the guild.
41
+ # @param region [String, nil] Guild voice region ID. [DEPRECATED]
42
+ # @param verification_level [Integer, nil] The new verification level of the guild.
43
+ # @param default_message_notifications [Integer, nil] Default message notification level.
44
+ # @param explicit_content_filter [Integer, nil] Explicit content filter level.
45
+ # @param afk_channel_id [String, nil] ID (as a string) of the afk channel.
46
+ # @param afk_timeout [Integer, nil] AFK timeout in seconds. Can be set to; 60, 300, 900, 1800 or 3600.
47
+ # @param icon [String, nil] BASE64-encoded image data to be set as the guild icon.
48
+ # See https://discord.com/developers/docs/reference#image-data. Set this parameter as the Data URI scheme
49
+ # (as a string).
50
+ # @param splash [String, nil] BASE64-encoded image data to be set as the guild splash.
51
+ # See https://discord.com/developers/docs/reference#image-data. Set this parameter as the Data URI scheme
52
+ # (as a string).
53
+ # @param discovery_splash [String, nil] BASE64-encoded image data to be set as the guild discovery splash.
54
+ # See https://discord.com/developers/docs/reference#image-data. Set this parameter as the Data URI scheme
55
+ # (as a string).
56
+ # @param banner [String, nil] BASE64-encoded image data to be set as the guild banner.
57
+ # See https://discord.com/developers/docs/reference#image-data. Set this parameter as the Data URI scheme
58
+ # (as a string).
59
+ # @param system_channel_id [String, nil] ID (as a string) of the channel to be used for guild system messages.
60
+ # @param system_channel_flags [Integer, nil] System channel flags.
61
+ # @param rules_channel_id [String, nil] ID (as a string) of the channel to be used for rules and/or guidelines.
62
+ # @param public_updates_channel_id [String, nil] ID (as a string) of the channel to be used for public updates.
63
+ # @param preferred_locale [String, nil] The preferred locale of a Community guild, default "en-US".
64
+ # @param features [Array, nil] An array of enabled guild features (strings).
65
+ # @param description [String, nil] The description of the guild.
66
+ # @param premium_progress_bar_enabled [TrueClass, FalseClass, nil] Whether the guild's boost progress bar is enabled.
67
+ # @param safety_alerts_channel_id [String, nil] ID (as a string) of the channel to be used for safety alerts.
68
+ # @return [Faraday::Response, nil] The response from the Discord API as a Faraday::Response object, or nil if no
69
+ # modifications were provided.
58
70
  def modify_guild(guild_id, name: nil, region: nil, verification_level: nil, default_message_notifications: nil,
59
71
  explicit_content_filter: nil, afk_channel_id: nil, afk_timeout: nil, icon: nil, owner_id: nil,
60
72
  splash: nil, discovery_splash: nil, banner: nil, system_channel_id: nil,
@@ -94,33 +106,63 @@ class DiscordApi
94
106
  data = JSON.generate(output)
95
107
  headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
96
108
  headers['X-Audit-Log-Reason'] = audit_reason unless audit_reason.nil?
97
- response = DiscordApi.patch(url, headers, data)
98
- return response if response.status == 200
109
+ response = patch(url, headers, data)
110
+ return response if response.is_a?(Faraday::Response) && response.status == 200
99
111
 
100
- @logger.error("Could not modify guild with Guild ID #{guild_id}. Response: #{response.body}")
112
+ @logger.error("Could not modify guild with Guild ID #{guild_id}. Response: #{response_error_body(response)}")
101
113
  response
102
114
  end
103
115
 
104
116
  def delete_guild(guild_id)
105
117
  url = "#{@base_url}/guilds/#{guild_id}"
106
118
  headers = { 'Authorization': @authorization_header }
107
- response = DiscordApi.delete(url, headers)
108
- return response if response.status == 204
119
+ response = delete(url, headers)
120
+ return response if response.is_a?(Faraday::Response) && response.status == 204
109
121
 
110
- @logger.error("Could not delete guild with Guild ID #{guild_id}. Response: #{response.body}")
122
+ @logger.error("Could not delete guild with Guild ID #{guild_id}. Response: #{response_error_body(response)}")
111
123
  response
112
124
  end
113
125
 
126
+ # Returns a list of guild channel objects for every channel in the specified guild. Doesn't include threads.
127
+ # See https://discord.com/developers/docs/resources/guild#get-guild-channels
128
+ # @param guild_id [String] ID (as a string) of the guild to get the channels for.
129
+ # @return [Faraday::Response] The response from the Discord API as a Faraday::Response object.
114
130
  def get_guild_channels(guild_id)
115
131
  url = "#{@base_url}/guilds/#{guild_id}/channels"
116
132
  headers = { 'Authorization': @authorization_header }
117
- response = DiscordApi.get(url, headers)
118
- return response if response.status == 200
133
+ response = get(url, headers)
134
+ return response if response.is_a?(Faraday::Response) && response.status == 200
119
135
 
120
- @logger.error("Could not get guild channels with Guild ID #{guild_id}. Response: #{response.body}")
136
+ @logger.error("Could not get guild channels with Guild ID #{guild_id}. Response: #{response_error_body(response)}")
121
137
  response
122
138
  end
123
139
 
140
+ # Creates a new channel in the specified guild. Returns the created channel object.
141
+ # See https://discord.com/developers/docs/resources/guild#create-guild-channel
142
+ # @param guild_id [String] ID (as a string) of the guild to create the channel in.
143
+ # @param name [String] Name of the new channel (1-100 characters)
144
+ # @param topic [String, nil] The channel topic (a.k.a. description) (0-1024 characters)
145
+ # @param bitrate [Integer, nil] Bitrate of the voice or stage channel in bits, min 8000
146
+ # @param user_limit [Integer, nil] User limit of the voice channel
147
+ # @param rate_limit_per_user [Integer, nil] Amount of seconds a user has to wait before sending another message
148
+ # (0-21600)
149
+ # @param position [Integer, nil] Sorting position of the channel (Channels with the same position are sorted by ID)
150
+ # @param permission_overwrites [Array, nil] Array of partial overwrite objects; the channel's permission overwrites
151
+ # @param parent_id [String, nil] ID (as a string) of the parent category for a channel
152
+ # @param nsfw [TrueClass, FalseClass, nil] Whether the channel is NSFW
153
+ # @param rtc_region [String, nil] Channel voice region ID (as string) of the voice or stage channel,
154
+ # set to \"auto\" for automatic region selection
155
+ # @param video_quality_mode [Integer, nil] The camera video quality mode of the voice channel
156
+ # @param default_auto_archive_duration [Integer, nil] The default duration that the clients use for newly created
157
+ # threads in the channel, in minutes, to automatically archive the thread after recent activity
158
+ # @param default_reaction_emoji [Hash, nil] Default reaction object; Emoji to show in the add reaction button on a
159
+ # thread in a forum or media channel
160
+ # @param available_tags [Array, nil] Array of tag objects; set of tags that can be used in a forum or media channel
161
+ # @param default_sort_order [Integer, nil] The default sort order type used to order posts in forum and media channels
162
+ # @param default_forum_layout [Integer, nil] The default forum layout view used to display posts in forum channels
163
+ # @param default_thread_rate_limit_per_user [Integer, nil] The initial rate_limit_per_user to set on newly created
164
+ # threads in a channel. This field is copied to the thread at creation time and does not live update.
165
+ # @return [Faraday::Response] The response from the Discord API as a Faraday::Response object.
124
166
  def create_guild_channel(guild_id, name, type: nil, topic: nil, bitrate: nil, user_limit: nil,
125
167
  rate_limit_per_user: nil, position: nil, permission_overwrites: nil, parent_id: nil,
126
168
  nsfw: nil, rtc_region: nil, video_quality_mode: nil, default_auto_archive_duration: nil,
@@ -137,7 +179,13 @@ class DiscordApi
137
179
  output[:permission_overwrites] = permission_overwrites unless permission_overwrites.nil?
138
180
  output[:parent_id] = parent_id unless parent_id.nil?
139
181
  output[:nsfw] = nsfw unless nsfw.nil?
140
- output[:rtc_region] = rtc_region unless rtc_region.nil?
182
+ unless rtc_region.nil?
183
+ output[:rtc_region] = if rtc_region == 'auto'
184
+ nil
185
+ else
186
+ rtc_region
187
+ end
188
+ end
141
189
  output[:video_quality_mode] = video_quality_mode unless video_quality_mode.nil?
142
190
  output[:default_auto_archive_duration] = default_auto_archive_duration unless default_auto_archive_duration.nil?
143
191
  output[:default_reaction_emoji] = default_reaction_emoji unless default_reaction_emoji.nil?
@@ -151,55 +199,108 @@ class DiscordApi
151
199
  data = JSON.generate(output)
152
200
  headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
153
201
  headers['X-Audit-Log-Reason'] = audit_reason unless audit_reason.nil?
154
- response = DiscordApi.post(url, data, headers)
155
- return response if response.status == 200
202
+ response = post(url, data, headers)
203
+ return response if response.is_a?(Faraday::Response) && response.status == 200
156
204
 
157
- @logger.error("Could not create guild channel in Guild ID #{guild_id}. Response: #{response.body}")
205
+ @logger.error("Could not create guild channel in Guild ID #{guild_id}. Response: #{response_error_body(response)}")
158
206
  response
159
207
  end
160
208
 
161
- def modify_guild_channel_positions(guild_id, channel_id, position: nil, lock_permissions: nil, parent_id: nil)
162
- if args[2..].all?(&:nil?)
163
- @logger.warn("No modifications for guild channel positions with guild ID #{guild_id} and channel ID " \
164
- "#{channel_id} provided. Skipping.")
209
+ # Modify the positions of a set of channel objects for the guild. Returns 204 No Content on success.
210
+ # See https://discord.com/developers/docs/resources/guild#modify-guild-channel-positions
211
+ # @param guild_id [String] ID (as a string) of the guild to modify the channel positions for.
212
+ # @param data [Hash] A hash where the keys are channel IDs (as symbols) and the values are another hash formed of keys
213
+ # that are either:
214
+ # - :position (Integer) sorting position of the channel (channels with the same position are sorted by ID)
215
+ # - :lock_permissions (TrueClass, FalseClass) whether to sync the permission overwrites with the new parent
216
+ # category, if moving to a different one. If this is provided but :parent_id isnt, this will be dropped from the
217
+ # request
218
+ # - :parent_id (String) ID (as a string) of the new parent category for a channel
219
+ # Example:
220
+ # { :1395365491005980814 => { :position => 0, :lock_permissions => false, :parent_id => "1395365491005980825" },
221
+ # 1389464920227319879 => { :position => 1 }}
222
+ #
223
+ # If no modifications are provided for a channel, that channel will be dropped, please note that :lock_permissions
224
+ # can be dropped, and this affects if it gets dropped
225
+ #
226
+ # And if the entire data hash is empty (after dropping channels with no modifications), the entire function will be
227
+ # skipped and will return nil
228
+ # @return [Faraday::Response, nil] The response from the Discord API as a Faraday::Response object, or nil if no
229
+ # modifications were provided
230
+ def modify_guild_channel_positions(guild_id, data)
231
+ output = []
232
+ data.each do |channel_id, modification|
233
+ channel_modification = {}
234
+ channel_modification[:id] = channel_id
235
+ channel_modification[:position] = modification[:position] if modification.include?(:position)
236
+ channel_modification[:lock_permissions] = modification[:lock_permissions] if modification
237
+ .include?(:lock_permissions)
238
+ channel_modification[:parent_id] = modification[:parent_id] if modification.include?(:parent_id)
239
+ if (channel_modification.keys - %i[id lock_permissions position]).empty? &&
240
+ !channel_modification.key?(:parent_id)
241
+ @logger.warn('lock_permissions has been specified, but parent_id hasn\'t. Dropping lock_permissions from ' \
242
+ 'data.')
243
+ channel_modification.delete(:lock_permissions)
244
+ end
245
+ if channel_modification.empty?
246
+ @logger.warn("No channel position modifications provided for channel with ID #{channel_id}. Skipping channel" \
247
+ ' position modification.')
248
+ else
249
+ output << channel_modification
250
+ end
251
+ end
252
+ if output.empty?
253
+ @logger.warn("No channel position modifications provided for guild with ID #{guild_id}. Skipping function.")
165
254
  return nil
166
255
  end
167
- output = {}
168
- output[:id] = channel_id
169
- output[:position] = position unless position.nil?
170
- output[:lock_permissions] = lock_permissions unless lock_permissions.nil?
171
- output[:parent_id] = parent_id unless parent_id.nil?
172
256
  url = "#{@base_url}/guilds/#{guild_id}/channels"
173
257
  data = JSON.generate(output)
174
258
  headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
175
- response = DiscordApi.patch(url, headers, data)
176
- return response if response.status == 200
259
+ response = patch(url, headers, data)
260
+ return response if response.is_a?(Faraday::Response) && response.status == 200
177
261
 
178
- @logger.error("Could not modify guild channel positions with Guild ID #{guild_id}. Response: #{response.body}")
262
+ @logger.error("Could not modify guild channel positions with Guild ID #{guild_id}." \
263
+ " Response: #{response_error_body(response)}")
179
264
  response
180
265
  end
181
266
 
267
+ # Returns a list of active threads in the specified guild.
268
+ # See https://discord.com/developers/docs/resources/guild#list-active-guild-threads
269
+ # @param guild_id [String] ID (as a string) of the guild to list active threads for.
270
+ # @return [Faraday::Response] The response from the Discord API as a Faraday::Response object.
182
271
  def list_active_guild_threads(guild_id)
183
272
  url = "#{@base_url}/guilds/#{guild_id}/threads/active"
184
273
  headers = { 'Authorization': @authorization_header }
185
- response = DiscordApi.get(url, headers)
186
- return response if response.status == 200
274
+ response = get(url, headers)
275
+ return response if response.is_a?(Faraday::Response) && response.status == 200
187
276
 
188
- @logger.error("Could not list active guild threads with Guild ID #{guild_id}. Response: #{response.body}")
277
+ @logger.error("Could not list active guild threads with Guild ID #{guild_id}." \
278
+ " Response: #{response_error_body(response)}")
189
279
  response
190
280
  end
191
281
 
282
+ # Returns a guild member object for the specified user in the specified guild.
283
+ # See https://discord.com/developers/docs/resources/guild#get-guild-member
284
+ # @param guild_id [String] ID (as a string) of the guild to get the member from.
285
+ # @param user_id [String] ID (as a string) of the user to get the member object for.
286
+ # @return [Faraday::Response] The response from the DiscordApi as a Faraday::Response object.
192
287
  def get_guild_member(guild_id, user_id)
193
288
  url = "#{@base_url}/guilds/#{guild_id}/members/#{user_id}"
194
289
  headers = { 'Authorization' => @authorization_header }
195
- response = DiscordApi.get(url, headers)
196
- return response if response.status == 200
290
+ response = get(url, headers)
291
+ return response if response.is_a?(Faraday::Response) && response.status == 200
197
292
 
198
293
  @logger.error("Could not get guild member with Guild ID #{guild_id} and User ID #{user_id}. Response:" \
199
- "#{response.body}")
294
+ "#{response_error_body(response)}")
200
295
  response
201
296
  end
202
297
 
298
+ # Returns an array of guild member objects for the specified guild.
299
+ # See https://discord.com/developers/docs/resources/guild#list-guild-members
300
+ # @param guild_id [String] ID (as a string) of the guild to list the members for.
301
+ # @param limit [Integer, nil] Maximum number of members to return (1-100). Default: 1
302
+ # @param after [String, nil] Get users after this user ID (as a string)
303
+ # @return [Faraday::Response] The response from the Discord API as a Faraday::Response object.
203
304
  def list_guild_members(guild_id, limit: nil, after: nil)
204
305
  query_string_hash = {}
205
306
  query_string_hash[:limit] = limit unless limit.nil?
@@ -207,13 +308,19 @@ class DiscordApi
207
308
  query_string = DiscordApi.handle_query_strings(query_string_hash)
208
309
  url = "#{@base_url}/guilds/#{guild_id}/members#{query_string}"
209
310
  headers = { 'Authorization': @authorization_header }
210
- response = DiscordApi.get(url, headers)
211
- return response if response.status == 200
311
+ response = get(url, headers)
312
+ return response if response.is_a?(Faraday::Response) && response.status == 200
212
313
 
213
- @logger.error("Could not list members with Guild ID #{guild_id}. Response: #{response.body}")
314
+ @logger.error("Could not list members with Guild ID #{guild_id}. Response: #{response_error_body(response)}")
214
315
  response
215
316
  end
216
317
 
318
+ # Returns an array of guild member objects whose username/nickname match the query.
319
+ # See https://discord.com/developers/docs/resources/guild#search-guild-members
320
+ # @param guild_id [String] ID (as a string) of the guild to search the members in
321
+ # @param query [String] Query string to match usernames and nicknames against.
322
+ # @param limit [Integer, nil] Maximum number of members to return (1-1000). Default: 1
323
+ # @return [Faraday::Response] The response from the Discord API as a Faraday::Response object.
217
324
  def search_guild_members(guild_id, query, limit = nil)
218
325
  query_string_hash = {}
219
326
  query_string_hash[:query] = query
@@ -221,13 +328,25 @@ class DiscordApi
221
328
  query_string = DiscordApi.handle_query_strings(query_string_hash)
222
329
  url = "#{@base_url}/guilds/#{guild_id}/members/search#{query_string}"
223
330
  headers = { 'Authorization': @authorization_header }
224
- response = DiscordApi.get(url, headers)
225
- return response if response.status == 200
331
+ response = get(url, headers)
332
+ return response if response.is_a?(Faraday::Response) && response.status == 200
226
333
 
227
- @logger.error("Could not search members with Guild ID #{guild_id}. Response: #{response.body}")
334
+ @logger.error("Could not search members with Guild ID #{guild_id}. Response: #{response_error_body(response)}")
228
335
  response
229
336
  end
230
337
 
338
+ # Adds a user to the specified guild. Returns 201 Created with the body being the Guild Member object of the added
339
+ # user or 204 No Content if the user is already in the guild.
340
+ # See https://discord.com/developers/docs/resources/guild#add-guild-member
341
+ # @param guild_id [String] ID (as a string) of the guild to add the user to
342
+ # @param user_id [String] ID (as a string) of the user to add to the guild
343
+ # @param access_token [String] A valid OAuth2 access token with the guilds.join scope created by the user you want to
344
+ # add to the guild for the bot that is adding the user
345
+ # @param roles [Array, nil] Array of role IDs (as strings) the user will be assigned
346
+ # @param nick [String, nil] String to set the user's nickname to
347
+ # @param mute [TrueClass, FalseClass, nil] Whether the user is muted in voice channels
348
+ # @param deaf [TrueClass, FalseClass, nil] Whether the user is deafened in voice channels
349
+ # @return [Faraday::Response] The response from the Discord API as a Faraday::Response object.
231
350
  def add_guild_member(guild_id, user_id, access_token, nick: nil, roles: nil, mute: nil, deaf: nil)
232
351
  output = {}
233
352
  output[:access_token] = access_token
@@ -238,17 +357,37 @@ class DiscordApi
238
357
  url = "#{@base_url}/guilds/#{guild_id}/members/#{user_id}"
239
358
  data = JSON.generate(output)
240
359
  headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
241
- response = DiscordApi.put(url, data, headers)
242
- if response.status == 204
360
+ response = put(url, data, headers)
361
+ if response.is_a?(Faraday::Response) && response.status == 204
243
362
  @logger.warn("User with ID #{user_id} is already a member of the guild with ID #{guild_id}.")
244
- elsif response.status == 201
363
+ elsif response.is_a?(Faraday::Response) && response.status == 201
245
364
  @logger.info("Added user with ID #{user_id} to guild with ID #{guild_id}.")
246
365
  else
247
- @logger.error("Could not add user with ID #{user_id} to guild with ID #{guild_id}. Response: #{response.body}")
366
+ @logger.error("Could not add user with ID #{user_id} to guild with ID #{guild_id}." \
367
+ " Response: #{response_error_body(response)}")
248
368
  end
249
369
  response
250
370
  end
251
371
 
372
+ # Modifies a user in the specified guild. Returns 200 OK with the new Guild Member object.
373
+ # See https://discord.com/developers/docs/resources/guild#modify-guild-member
374
+ #
375
+ # If none of the optional parameters are provided (member modifications), the function will log a warning, no request
376
+ # will be made to Discord, and the function will return nil. (note that audit_reason doesn't count)
377
+ # @param guild_id [String] ID (as a string) of the guild to modify the member in
378
+ # @param user_id [String] ID (as a string) of the user to modify
379
+ # @param nick [String, nil] Value to set the user's nickname to.
380
+ # @param roles [Array, nil] Array of role IDs (as strings) the user will be assigned.
381
+ # @param mute [TrueClass, FalseClass, nil] Whether the user is muted in voice channels.
382
+ # @param deaf [TrueClass, FalseClass, nil] Whether the user is deafened in voice channels.
383
+ # @param channel_id [String, nil] ID (as a string) of the ID of a voice channel to move the user to (if the user is in
384
+ # a voice channel).
385
+ # @param communication_disabled_until [String, FalseClass, nil] When the user's timeout will expire (up to 28 days in
386
+ # the future) in ISO8601 format, or false to remove timeout.
387
+ # @param flags [Integer, nil] New guild member flags.
388
+ # @param audit_reason [String, nil] Reason for the modification, shows up on the audit log entry.
389
+ # @return [Faraday::Response, nil] The response from the Discord API as a Faraday::Response object, or nil if no
390
+ # modifications were provided.
252
391
  def modify_guild_member(guild_id, user_id, nick: nil, roles: nil, mute: nil, deaf: nil, channel_id: nil,
253
392
  communication_disabled_until: nil, flags: nil, audit_reason: nil)
254
393
  if args[2..-2].all?(&:nil?)
@@ -262,92 +401,147 @@ class DiscordApi
262
401
  output[:mute] = mute unless mute.nil?
263
402
  output[:deaf] = deaf unless deaf.nil?
264
403
  output[:channel_id] = channel_id unless channel_id.nil?
265
- output[:communication_disabled_until] = communication_disabled_until unless communication_disabled_until.nil?
404
+ if communication_disabled_until == false
405
+ output[:communication_disabled_until] = nil
406
+ elsif !communication_disabled_until.nil?
407
+ output[:communication_disabled_until] = communication_disabled_until
408
+ end
266
409
  output[:flags] = flags unless flags.nil?
267
410
  url = "#{@base_url}/guilds/#{guild_id}/members/#{user_id}"
268
411
  data = JSON.generate(output)
269
412
  headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
270
413
  headers['X-Audit-Log-Reason'] = audit_reason unless audit_reason.nil?
271
- response = DiscordApi.patch(url, data, headers)
272
- return response if response.status == 200
414
+ response = patch(url, data, headers)
415
+ return response if response.is_a?(Faraday::Response) && response.status == 200
273
416
 
274
417
  @logger.error("Could not modify guild member with Guild ID #{guild_id} and User ID #{user_id}. " \
275
- "Response: #{response.body}")
418
+ "Response: #{response_error_body(response)}")
276
419
  response
277
420
  end
278
421
 
279
- def modify_current_member(guild_id, nick: nil, audit_reason: nil)
280
- if nick.nil?
281
- @logger.warn("No modifications for current member in guild ID #{guild_id} provided. Skipping.")
282
- return nil
283
- end
422
+ # Modifies the current member in the specified guild. Returns 200 OK with the new Guild Member object.
423
+ # See https://discord.com/developers/docs/resources/guild#modify-current-member
424
+ #
425
+ # If none of the optional parameters are provided (member modifications), the function will log a warning,
426
+ # no request will be made to Discord, and the function will return nil. (note that audit_reason doesn't count)
427
+ # @param guild_id [String] ID (as a string) of the guild to modify the current member in
428
+ # @param nick [String, nil] Value to set the user's name to in the guild.
429
+ # @param banner [String, nil] Data URI scheme with BASE64-encoded image data to set as the user's banner in the guild.
430
+ # See https://discord.com/developers/docs/reference#image-data
431
+ # @param avatar [String, nil] Data URI scheme with BASE64-encoded image data to set as the user's avatar in the guild.
432
+ # See https://discord.com/developers/docs/reference#image-data
433
+ # @param bio [String, nil] Value to set the user's bio to in the guild.
434
+ # @param audit_reason [String, nil] Reason for the modification, shows up on the audit log entry.
435
+ # @return [Faraday::Response, nil] The response from the Discord API as a Faraday::Response object, or nil if no
436
+ # modifications were provided.
437
+ def modify_current_member(guild_id, nick: nil, banner: nil, avatar: nil, bio: nil, audit_reason: nil)
284
438
  output = {}
285
439
  output[:nick] = nick unless nick.nil?
440
+ output[:banner] = banner unless banner.nil?
441
+ output[:avatar] = avatar unless avatar.nil?
442
+ output[:bio] = bio unless bio.nil?
286
443
  url = "#{@base_url}/guilds/#{guild_id}/members/@me"
287
444
  data = JSON.generate(output)
445
+ if data.empty?
446
+ @logger.warn("No modifications for current member in guild ID #{guild_id} provided. Skipping.")
447
+ return nil
448
+ end
288
449
  headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
289
450
  headers['X-Audit-Log-Reason'] = audit_reason unless audit_reason.nil?
290
- response = DiscordApi.patch(url, data, headers)
291
- return response if response.status == 200
451
+ response = patch(url, data, headers)
452
+ return response if response.is_a?(Faraday::Response) && response.status == 200
292
453
 
293
- @logger.error("Could not modify current member in guild with Guild ID #{guild_id}. Response: #{response.body}")
454
+ @logger.error("Could not modify current member in guild with Guild ID #{guild_id}." \
455
+ " Response: #{response_error_body(response)}")
294
456
  response
295
457
  end
296
458
 
297
- def modify_current_user_nick(guild_id, nick: nil, audit_reason: nil)
459
+ # THIS ENDPOINT HAS BEEN DEPRECATED AND SHOULD NOT BE USED, PLEASE USE {DiscordApi#modify_current_member} INSTEAD!
460
+ # Modifies the current user's nickname in the specified guild. Returns 200 OK with the new nickname.
461
+ # See https://discord.com/developers/docs/resources/guild#modify-current-user-nick
462
+ # @param guild_id [String] ID (as a string) of the guild to modify the current user's nickname in
463
+ # @param nick [String] Value to set the user's nickname to in the specified guild.
464
+ # @param audit_reason [String, nil] Reason for the modification, shows up on the audit log entry.
465
+ # @return [Faraday::Response] The response from the Discord API as a Faraday::Response object.
466
+ def modify_current_user_nick(guild_id, nick, audit_reason: nil)
298
467
  @logger.warn('The "Modify Current User Nick" endpoint has been deprecated and should not be used!')
299
- if nick.nil?
300
- @logger.warn("No modifications for current user nick in guild ID #{guild_id} provided. Skipping.")
301
- return nil
302
- end
303
468
  output = {}
304
469
  output[:nick] = nick unless nick.nil?
305
470
  url = "#{@base_url}/guilds/#{guild_id}/users/@me/nick"
306
471
  data = JSON.generate(output)
307
472
  headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
308
473
  headers['X-Audit-Log-Reason'] = audit_reason unless audit_reason.nil?
309
- response = DiscordApi.patch(url, data, headers)
310
- return response if response.status == 200
474
+ response = patch(url, data, headers)
475
+ return response if response.is_a?(Faraday::Response) && response.status == 200
311
476
 
312
- @logger.error("Could not modify current user nick in guild with ID #{guild_id}. Response: #{response.body}")
477
+ @logger.error("Could not modify current user nick in guild with ID #{guild_id}." \
478
+ " Response: #{response_error_body(response)}")
313
479
  response
314
480
  end
315
481
 
482
+ # Adds a role to a guild member. Returns 204 No Content on success.
483
+ # See https://discord.com/developers/docs/resources/guild#add-guild-member-role
484
+ # @param guild_id [String] ID (as a string) of the guild to add the role to the member in
485
+ # @param user_id [String] ID (as a string) of the user to add the role to
486
+ # @param role_id [String] ID (as a string) of the role to add to the user
487
+ # @param audit_reason [String, nil] Reason for the modification, shows up on the audit log entry.
488
+ # @return [Faraday::Response] The response from the Discord API as a Faraday::Response object.
316
489
  def add_guild_member_role(guild_id, user_id, role_id, audit_reason = nil)
317
490
  url = "#{@base_url}/guilds/#{guild_id}/members/#{user_id}/roles/#{role_id}"
318
491
  headers = { 'Authorization': @authorization_header }
319
492
  headers['X-Audit-Log-Reason'] = audit_reason unless audit_reason.nil?
320
- response = DiscordApi.put(url, nil, headers)
321
- return response if response.status == 204
493
+ response = put(url, nil, headers)
494
+ return response if response.is_a?(Faraday::Response) && response.status == 204
322
495
 
323
496
  @logger.error("Could not add role with ID #{role_id}, to user with ID #{user_id} in guild with ID #{guild_id}." \
324
- " Response: #{response.body}")
497
+ " Response: #{response_error_body(response)}")
325
498
  response
326
499
  end
327
500
 
501
+ # Removes a role from a guild member. Returns 204 No Content on success.
502
+ # See https://discord.com/developers/docs/resources/guild#remove-guild-member-role
503
+ # @param guild_id [String] ID (as a string) of the guild to remove the role from the member in
504
+ # @param user_id [String] ID (as a string) of the user to remove the role from
505
+ # @param role_id [String] ID (as a string) of the role to remove from the user
506
+ # @param audit_reason [String, nil] Reason for the modification, shows up on the audit log entry.
507
+ # @return [Faraday::Response] The response from the Discord API as a Faraday::Response object.
328
508
  def remove_guild_member_role(guild_id, user_id, role_id, audit_reason = nil)
329
509
  url = "#{@base_url}/guilds/#{guild_id}/members/#{user_id}/roles/#{role_id}"
330
510
  headers = { 'Authorization': @authorization_header }
331
511
  headers['x-Audit-Log-Reason'] = audit_reason unless audit_reason.nil?
332
- response = DiscordApi.delete(url, headers)
333
- return response if response.status == 204
512
+ response = delete(url, headers)
513
+ return response if response.is_a?(Faraday::Response) && response.status == 204
334
514
 
335
515
  @logger.error("Could not remove role with ID #{role_id}, from user with ID #{user_id}" \
336
- " in guild with ID #{guild_id}. Response: #{response.body}")
516
+ " in guild with ID #{guild_id}. Response: #{response_error_body(response)}")
337
517
  response
338
518
  end
339
519
 
520
+ # Removes a member from a guild. Returns 204 No Content on success.
521
+ # See https://discord.com/developers/docs/resources/guild#remove-guild-member
522
+ # @param guild_id [String] ID (as a string) of the guild to remove the member from
523
+ # @param user_id [String] ID (as a string) of the user to remove from the guild
524
+ # @param audit_reason [String, nil] Reason for the kick, shows up on the audit log entry.
525
+ # @return [Faraday::Response] The response from the Discord API as a Faraday::Response object.
340
526
  def remove_guild_member(guild_id, user_id, audit_reason = nil)
341
527
  url = "#{@base_url}/guilds/#{guild_id}/members/#{user_id}"
342
528
  headers = { 'Authorization' => @authorization_header }
343
529
  headers['X-Audit-Log-Reason'] = audit_reason unless audit_reason.nil?
344
- response = DiscordApi.delete(url, headers)
345
- return response if response.status == 204
530
+ response = delete(url, headers)
531
+ return response if response.is_a?(Faraday::Response) && response.status == 204
346
532
 
347
- @logger.error("Could not remove user with ID #{user_id} from guild with ID #{guild_id}. Response: #{response.body}")
533
+ @logger.error("Could not remove user with ID #{user_id} from guild with ID #{guild_id}." \
534
+ " Response: #{response_error_body(response)}")
348
535
  response
349
536
  end
350
537
 
538
+ # Returns a list of ban objects for users banned from the specified guild.
539
+ # See https://discord.com/developers/docs/resources/guild#get-guild-bans
540
+ # @param guild_id [String] ID (as a string) of the guild to get the bans from.
541
+ # @param limit [Integer, nil] Maximum number of bans to return (1-1000)
542
+ # @param before [String, nil] Get bans before this user ID (as a string)
543
+ # @param after [String, nil] Get bans after this user ID (as a string)
544
+ # @return [Faraday::Response] The response from the Discord API as a Faraday::Response object.
351
545
  def get_guild_bans(guild_id, limit: nil, before: nil, after: nil)
352
546
  query_string_hash = {}
353
547
  query_string_hash[:limit] = limit unless limit.nil?
@@ -356,28 +550,42 @@ class DiscordApi
356
550
  query_string = DiscordApi.handle_query_strings(query_string_hash)
357
551
  url = "#{@base_url}/guilds/#{guild_id}/bans#{query_string}"
358
552
  headers = { 'Authorization' => @authorization_header }
359
- response = DiscordApi.get(url, headers)
360
- return response if response.status == 200
553
+ response = get(url, headers)
554
+ return response if response.is_a?(Faraday::Response) && response.status == 200
361
555
 
362
- @logger.error("Could not get guild bans with Guild ID #{guild_id}. Response: #{response.body}")
556
+ @logger.error("Could not get guild bans with Guild ID #{guild_id}. Response: #{response_error_body(response)}")
363
557
  response
364
558
  end
365
559
 
560
+ # Returns a ban object for the specified user in the specified guild. Returns 404 Not Found if the user is not banned.
561
+ # See https://discord.com/developers/docs/resources/guild#get-guild-ban
562
+ # @param guild_id [String] ID (as a string) of the guild to get the ban from
563
+ # @param user_id [String] ID (as a string) of the user to get the ban object for
564
+ # @return [Faraday::Response] The response from the Discord API as a Faraday::Response object.
366
565
  def get_guild_ban(guild_id, user_id)
367
566
  url = "#{@base_url}/guilds/#{guild_id}/bans/#{user_id}"
368
567
  headers = { 'Authorization': @authorization_header }
369
- response = DiscordApi.get(url, headers)
370
- return response if response.status == 200
568
+ response = get(url, headers)
569
+ return response if response.is_a?(Faraday::Response) && response.status == 200
371
570
 
372
- if response.status == 404
571
+ if response.is_a?(Faraday::Response) && response.status == 404
373
572
  @logger.warn("No ban found for user with ID #{user_id} in guild with ID #{guild_id}.")
374
573
  else
375
574
  @logger.error("Could not get guild ban for user with ID #{user_id} in guild with ID #{guild_id}." \
376
- " Response: #{response.body}")
575
+ " Response: #{response_error_body(response)}")
377
576
  end
378
577
  response
379
578
  end
380
579
 
580
+ # Bans the specified user from the specified guild. Returns 204 No Content on success.
581
+ # See https://discord.com/developers/docs/resources/guild#create-guild-ban
582
+ # @param guild_id [String] ID (as a string) of the guild to ban the user from
583
+ # @param user_id [String] ID (as a string) of the user to ban from the guild
584
+ # @param delete_message_days [Integer, nil] Number of days to delete messages for (0-7) (DEPRECATED, use
585
+ # delete_message_seconds instead)
586
+ # @param delete_message_seconds [Integer, nil] Number of seconds to delete messages for (0-604800) (604800s=7d)
587
+ # @param audit_reason [String, nil] Reason for the ban, shows up on the audit log entry.
588
+ # @return [Faraday::Response] The response from the Discord API as a Faraday::Response object.
381
589
  def create_guild_ban(guild_id, user_id, delete_message_days: nil, delete_message_seconds: nil, audit_reason: nil)
382
590
  output = {}
383
591
  unless delete_message_days.nil?
@@ -389,26 +597,40 @@ class DiscordApi
389
597
  data = JSON.generate(output)
390
598
  headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
391
599
  headers['X-Audit-Log-Reason'] = audit_reason unless audit_reason.nil?
392
- response = DiscordApi.put(url, data, headers)
393
- return response if response.status == 204
600
+ response = put(url, data, headers)
601
+ return response if response.is_a?(Faraday::Response) && response.status == 204
394
602
 
395
603
  @logger.error("Could not create guild ban for user with ID #{user_id} in guild with ID #{guild_id}." \
396
- " Response: #{response.body}")
604
+ " Response: #{response_error_body(response)}")
397
605
  response
398
606
  end
399
607
 
608
+ # Unbans the specified user from the specified guild. Returns 204 No Content on success.
609
+ # See https://discord.com/developers/docs/resources/guild#remove-guild-ban
610
+ # @param guild_id [String] ID (as a string) of the guild to unban the user from
611
+ # @param user_id [String] ID (as a string) of the user to unban from the guild
612
+ # @param audit_reason [String, nil] Reason for the unban, shows up on the audit log entry.
613
+ # @return [Faraday::Response] The response from the Discord API as a Faraday::Response object.
400
614
  def remove_guild_ban(guild_id, user_id, audit_reason = nil)
401
615
  url = "#{@base_url}/guilds/#{guild_id}/bans/#{user_id}"
402
616
  headers = { 'Authorization': @authorization_header }
403
617
  headers['X-Audit-Log-Reason'] = audit_reason unless audit_reason.nil?
404
- response = DiscordApi.delete(url, headers)
405
- return response if response.status == 204
618
+ response = delete(url, headers)
619
+ return response if response.is_a?(Faraday::Response) && response.status == 204
406
620
 
407
621
  @logger.error("Could not remove guild ban for user with ID #{user_id} in guild with ID #{guild_id}" \
408
- " Response: #{response.body}")
622
+ " Response: #{response_error_body(response)}")
409
623
  response
410
624
  end
411
625
 
626
+ # Ban up to 200 users from a guild in a single request. Returns 200 OK with an array of the banned user IDs and the
627
+ # users that couldn't be banned if atleast one user has been banned successfully.
628
+ # See https://discord.com/developers/docs/resources/guild#bulk-guild-ban
629
+ # @param guild_id [String] ID (as a string) of the guild to bulk ban users from
630
+ # @param user_ids [Array] Array of user IDs (as strings) to ban from the specified guild (max 200)
631
+ # @param delete_message_seconds [Integer, nil] Number of seconds to delete messages for (0-604800) (604800s=7d)
632
+ # @param audit_reason [String, nil] Reason for the bulk ban, shows up on the audit log entry.
633
+ # @return [Faraday::Response] The response from the Discord API as a Faraday::Response object
412
634
  def bulk_guild_ban(guild_id, user_ids, delete_message_seconds: nil, audit_reason: nil)
413
635
  output = {}
414
636
  output[:user_ids] = user_ids unless user_ids.nil?
@@ -417,37 +639,63 @@ class DiscordApi
417
639
  data = JSON.generate(output)
418
640
  headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
419
641
  headers['X-Audit-Log-Reason'] = audit_reason unless audit_reason.nil?
420
- response = DiscordApi.post(url, data, headers)
421
- return response if response.status == 200
642
+ response = post(url, data, headers)
643
+ return response if response.is_a?(Faraday::Response) && response.status == 200
422
644
 
423
- if response.status == 500_000
424
- @logger.error("No users were banned in bulk ban in guild with ID #{guild_id}. Response: #{response.body}")
645
+ if response.is_a?(Faraday::Response) && response.status == 500_000
646
+ @logger.error("No users were banned in bulk ban in guild with ID #{guild_id}." \
647
+ " Response: #{response_error_body(response)}")
425
648
  else
426
- @logger.error("Could not bulk ban users in guild with ID #{guild_id}. Response: #{response.body}")
649
+ @logger.error("Could not bulk ban users in guild with ID #{guild_id}. Response: #{response_error_body(response)}")
427
650
  end
428
651
  response
429
652
  end
430
653
 
654
+ # Returns a list of role objects for the specified guild.
655
+ # See https://discord.com/developers/docs/resources/guild#get-guild-roles
656
+ # @param guild_id [String] ID (as a string) of the guild to get the roles from.
657
+ # @return [Faraday::Response] The response from the Discord API as a Faraday::Response object.
431
658
  def get_guild_roles(guild_id)
432
659
  url = "#{@base_url}/guilds/#{guild_id}/roles"
433
660
  headers = { 'Authorization': @authorization_header }
434
- response = DiscordApi.get(url, headers)
435
- return response if response.status == 200
661
+ response = get(url, headers)
662
+ return response if response.is_a?(Faraday::Response) && response.status == 200
436
663
 
437
- @logger.error("Could not get guild roles with Guild ID #{guild_id}. Response: #{response.body}")
664
+ @logger.error("Could not get guild roles with Guild ID #{guild_id}. Response: #{response_error_body(response)}")
438
665
  response
439
666
  end
440
667
 
668
+ # Returns the role object for the specified role in the specified guild.
669
+ # See https://discord.com/developers/docs/resources/guild#get-guild-role
670
+ # @param guild_id [String] ID (as a string) of the guild to get the role from.
671
+ # @param role_id [String] ID (as a string) of the role to get.
672
+ # @return [Faraday::Response] The response from the Discord API as a Faraday::Response object.
441
673
  def get_guild_role(guild_id, role_id)
442
674
  url = "#{@base_url}/guilds/#{guild_id}/roles/#{role_id}"
443
675
  headers = { 'Authorization': @authorization_header }
444
- response = DiscordApi.get(url, headers)
445
- return response if response.status == 200
676
+ response = get(url, headers)
677
+ return response if response.is_a?(Faraday::Response) && response.status == 200
446
678
 
447
- @logger.error("Could not get role with ID #{role_id} in guild with ID #{guild_id}. Response: #{response.body}")
679
+ @logger.error("Could not get role with ID #{role_id} in guild with ID #{guild_id}." \
680
+ " Response: #{response_error_body(response)}")
448
681
  response
449
682
  end
450
683
 
684
+ # Creates a new role in the specified guild. Returns 200 OK with the new role object.
685
+ # See https://discord.com/developers/docs/resources/guild#create-guild-role
686
+ # @param guild_id [String] ID (as a string) of the guild to create the role in
687
+ # @param name [String, nil] Name of the role (default: "new role")
688
+ # @param permissions [String, nil] Bitwise value of the permissions for the role (default: @everyone permissions)
689
+ # @param color [Integer, nil] (DEPRECATED, USE colors INSTEAD) RGB color value for the role (default: 0)
690
+ # @param colors [Hash, nil] Role colors object
691
+ # @param hoist [TrueClass, FalseClass, nil] Whether the role should be displayed separately in the sidebar
692
+ # (default: false)
693
+ # @param icon [String, nil] URI-encoded base64 image data for the role icon (default: nil)
694
+ # @param unicode_emoji [String, nil] The role's unicode emoji as a standard emoji (default: nil)
695
+ # @param mentionable [TrueClass, FalseClass, nil] Whether the role should be able to be mentioned by @everyone
696
+ # (default: false)
697
+ # @param audit_reason [String, nil] Reason for the creation, shows up on the audit log entry.
698
+ # @return [Faraday::Response] The response from the Discord API as a Faraday::Response object.
451
699
  def create_guild_role(guild_id, name: nil, permissions: nil, color: nil, colors: nil, hoist: nil, icon: nil,
452
700
  unicode_emoji: nil, mentionable: nil, audit_reason: nil)
453
701
  output = {}
@@ -466,32 +714,57 @@ class DiscordApi
466
714
  data = JSON.generate(output)
467
715
  headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
468
716
  headers['X-Audit-Log-Reason'] = audit_reason unless audit_reason.nil?
469
- response = DiscordApi.post(url, data, headers)
470
- return response if response.status == 200
717
+ response = post(url, data, headers)
718
+ return response if response.is_a?(Faraday::Response) && response.status == 200
471
719
 
472
- @logger.error("Could not create guild role in guild with ID #{guild_id}. Response: #{response.body}")
720
+ @logger.error("Could not create guild role in guild with ID #{guild_id}." \
721
+ "Response: #{response_error_body(response)}")
473
722
  response
474
723
  end
475
724
 
476
- def modify_guild_role_positions(guild_id, id, position: nil, audit_reason: nil)
477
- if position.nil?
725
+ # Modifies the position of a set of role objects in the specified guild. Returns 200 OK with an array of all of the
726
+ # modified role objects on success.
727
+ # See https://discord.com/developers/docs/resources/guild#modify-guild-role-positions
728
+ # @param guild_id [String] ID (as a string) of the guild to modify the role positions in
729
+ # @param role_positions [Array] Array of objects (hashes) with "id" and "position" keys
730
+ # with "id" being the role ID (as a string) and "position" being the sorting position of the role
731
+ # (roles with the same position are sorted by id), if this array is empty, a warning will be logged
732
+ # and the function will be skipped, return nil. (no request will be made to discord)
733
+ # @param audit_reason [String, nil] Reason for the modification, shows up on the audit log entry.
734
+ # @return [Faraday::Response, nil] The response from the Discord API as a Faraday::Response object, or nil if
735
+ # role_positions was empty.
736
+ def modify_guild_role_positions(guild_id, role_positions, audit_reason: nil)
737
+ if role_positions.empty?
478
738
  @logger.warn("No role positions provided for guild with ID #{guild_id}. Skipping function.")
479
739
  return nil
480
740
  end
481
- output = {}
482
- output[:id] = id
483
- output[:position] = position unless position.nil?
484
741
  url = "#{@base_url}/guilds/#{guild_id}/roles"
485
- data = JSON.generate(output)
742
+ data = JSON.generate(role_positions)
486
743
  headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
487
744
  headers['X-Audit-Log-Reason'] = audit_reason unless audit_reason.nil?
488
- response = DiscordApi.patch(url, data, headers)
489
- return response if response.status == 200
745
+ response = patch(url, data, headers)
746
+ return response if response.is_a?(Faraday::Response) && response.status == 200
490
747
 
491
- @logger.error("Could not modify guild role positions in guild with ID #{guild_id}. Response: #{response.body}")
748
+ @logger.error("Could not modify guild role positions in guild with ID #{guild_id}." \
749
+ " Response: #{response_error_body(response)}")
492
750
  response
493
751
  end
494
752
 
753
+ # Modifies a guild role. Returns 200 OK with the modified role object, or nil if no modifications were provided.
754
+ # See https://discord.com/developers/docs/resources/guild#modify-guild-role
755
+ # @param guild_id [String] ID (as a string) of the guild the role to modify is in
756
+ # @param role_id [String] ID (as a string) of the role to modify
757
+ # @param name [String, nil] New name of the role
758
+ # @param permissions [String, nil] New bitwise value of the permissions for the role
759
+ # @param color [Integer, nil] (DEPRECATED, USE colors INSTEAD) New RGB color value for the role
760
+ # @param colors [Hash, nil] New role colors object
761
+ # @param hoist [TrueClass, FalseClass, nil] Whether the role should be displayed separately in the sidebar
762
+ # @param icon [String, nil] URI-encoded base64 image data for the role icon
763
+ # @param unicode_emoji [String, nil] The role's unicode emoji as a standard emoji
764
+ # @param mentionable [TrueClass, FalseClass, nil] Whether the role should be able to be mentioned by @everyone
765
+ # @param audit_reason [String, nil] Reason for the modification, shows up on the audit log entry.
766
+ # @return [Faraday::Response, nil] The response from the Discord API as a Faraday::Response object, or nil if no
767
+ # modifications were provided.
495
768
  def modify_guild_role(guild_id, role_id, name: nil, permissions: nil, color: nil, hoist: nil, icon: nil,
496
769
  unicode_emoji: nil, mentionable: nil, audit_reason: nil)
497
770
  if args[2..-2].all?(&:nil?)
@@ -511,14 +784,20 @@ class DiscordApi
511
784
  data = JSON.generate(output)
512
785
  headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
513
786
  headers['X-Audit-Log-Reason'] = audit_reason unless audit_reason.nil?
514
- response = DiscordApi.patch(url, data, headers)
515
- return response if response.status == 200
787
+ response = patch(url, data, headers)
788
+ return response if response.is_a?(Faraday::Response) && response.status == 200
516
789
 
517
790
  @logger.error("Could not modify guild role with ID #{role_id} in guild with ID #{guild_id}." \
518
- " Response: #{response.body}")
791
+ " Response: #{response_error_body(response)}")
519
792
  response
520
793
  end
521
794
 
795
+ # Modifies the MFA level required for a guild. Returns 200 OK on success.
796
+ # @param guild_id [String] ID (as a string) of the guild to modify the MFA level for
797
+ # @param level [Integer] The MFA level to set for the guild, can be 0 (no MFA required) or 1 (MFA required for
798
+ # administrative actions)
799
+ # @param audit_reason [String, nil] Reason for the modification, shows up on the audit log entry.
800
+ # @return [Faraday::Response] The response from the Discord API as a Faraday::Response object.
522
801
  def modify_guild_mfa_level(guild_id, level, audit_reason = nil)
523
802
  output = {}
524
803
  output[:level] = level
@@ -526,24 +805,37 @@ class DiscordApi
526
805
  data = JSON.generate(output)
527
806
  headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
528
807
  headers['X-Audit-Log-Reason'] = audit_reason unless audit_reason.nil?
529
- response = DiscordApi.post(url, data, headers)
530
- return unless response.status != 200
808
+ response = post(url, data, headers)
809
+ return response if response.is_a?(Faraday::Response) && response.status == 200
531
810
 
532
- @logger.error("Failed to modify guild MFA level. Response: #{response.body}")
811
+ @logger.error("Failed to modify guild MFA level. Response: #{response_error_body(response)}")
533
812
  response
534
813
  end
535
814
 
815
+ # Deletes a guild role. Returns 204 No Content on success.
816
+ # See https://discord.com/developers/docs/resources/guild#delete-guild-role
817
+ # @param guild_id [String] ID (as a string) of the guild the role to delete is in
818
+ # @param role_id [String] ID (as a string) of the role to delete
819
+ # @param audit_reason [String, nil] Reason for the deletion of the role, shows up in the audit log
820
+ # @return [Faraday::Response] The response from the Discord API as a Faraday::Response object.
536
821
  def delete_guild_role(guild_id, role_id, audit_reason = nil)
537
822
  url = "#{@base_url}/guilds/#{guild_id}/roles/#{role_id}"
538
823
  headers = { 'Authorization': @authorization_header }
539
824
  headers['X-Audit-Log-Reason'] = audit_reason unless audit_reason.nil?
540
- response = DiscordApi.delete(url, headers)
541
- return response if response.status == 204
825
+ response = delete(url, headers)
826
+ return response if response.is_a?(Faraday::Response) && response.status == 204
542
827
 
543
- @logger.error("Failed to delete guild role. Response: #{response.body}")
828
+ @logger.error("Failed to delete guild role. Response: #{response_error_body(response)}")
544
829
  response
545
830
  end
546
831
 
832
+ # Returns a JSON object with a 'pruned' key indicating the number of members that would be removed in a prune
833
+ # operation with status code 200 OK. See https://discord.com/developers/docs/resources/guild#get-guild-prune-count
834
+ # @param guild_id [String] ID (as a string) of the guild to get the prune count for
835
+ # @param days [Integer, nil] Number of days to count prune for (1-30)
836
+ # @param include_roles [String, nil] Comma-delimited list of role IDs (as strings), these roles will also be included
837
+ # in the prune count
838
+ # @return [Faraday::Response] The response from the Discord API as a Faraday::Response object.
547
839
  def get_guild_prune_count(guild_id, days: nil, include_roles: nil)
548
840
  query_string_hash = {}
549
841
  query_string_hash[:days] = days unless days.nil?
@@ -551,13 +843,25 @@ class DiscordApi
551
843
  query_string = DiscordApi.handle_query_strings(query_string_hash)
552
844
  url = "#{@base_url}/guilds/#{guild_id}/prune#{query_string}"
553
845
  headers = { 'Authorization': @authorization_header }
554
- response = DiscordApi.get(url, headers)
555
- return response if response.status == 200
846
+ response = get(url, headers)
847
+ return response if response.is_a?(Faraday::Response) && response.status == 200
556
848
 
557
- @logger.error("Failed to get guild prune count. Response: #{response.body}")
849
+ @logger.error("Failed to get guild prune count. Response: #{response_error_body(response)}")
558
850
  response
559
851
  end
560
852
 
853
+ # Begins a guild prune operation. Returns 200 OK with a JSON object containing a 'pruned' key
854
+ # (optional, enabled by default) indicating the number of members that were removed on success.
855
+ # See https://discord.com/developers/docs/resources/guild#begin-guild-prune
856
+ # @param guild_id [String] ID (as a string) of the guild to start the guild prune in
857
+ # @param days [Integer, nil] Number of days to prune for (1-30)
858
+ # @param compute_prune_count [TrueClass, FalseClass, nil] Whether to return the 'pruned' key in the response
859
+ # @param include_roles [Array, nil] Array of role IDs (as strings), these roles will also be included in the prune
860
+ # operation
861
+ # @param reason [String, nil] (DEPRECATED, use audit_reason instead) Reason for the prune, shows up on the audit log
862
+ # entry.
863
+ # @param audit_reason [String, nil] Reason for the prune, shows up on the audit log entry.
864
+ # @return [Faraday::Response] The response from the Discord API as a Faraday::Response object.
561
865
  def begin_guild_prune(guild_id, days: nil, compute_prune_count: nil, include_roles: nil, reason: nil,
562
866
  audit_reason: nil)
563
867
  output = {}
@@ -572,69 +876,99 @@ class DiscordApi
572
876
  data = JSON.generate(output)
573
877
  headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
574
878
  headers['X-Audit-Log-Reason'] = audit_reason unless audit_reason.nil?
575
- response = DiscordApi.post(url, data, headers)
576
- return response if response.status == 200
879
+ response = post(url, data, headers)
880
+ return response if response.is_a?(Faraday::Response) && response.status == 200
577
881
 
578
- @logger.error("Failed to begin guild prune. Response: #{response.body}")
882
+ @logger.error("Failed to begin guild prune. Response: #{response_error_body(response)}")
579
883
  response
580
884
  end
581
885
 
886
+ # Returns a list of voice region objects for the specified guild with status code 200 OK on success.
887
+ # See https://discord.com/developers/docs/resources/guild#get-guild-voice-regions
888
+ # @param guild_id [String] ID (as a string) of the guild to get the voice regions from
889
+ # @return [Faraday::Response] The response from the Discord API as a Faraday::Response object.
582
890
  def get_guild_voice_regions(guild_id)
583
891
  url = "#{@base_url}/guilds/#{guild_id}/regions"
584
892
  headers = { 'Authorization': @authorization_header }
585
- response = DiscordApi.get(url, headers)
586
- return response if response.status == 200
893
+ response = get(url, headers)
894
+ return response if response.is_a?(Faraday::Response) && response.status == 200
587
895
 
588
- @logger.error("Failed to get guild voice regions. Response: #{response.body}")
896
+ @logger.error("Failed to get guild voice regions. Response: #{response_error_body(response)}")
589
897
  response
590
898
  end
591
899
 
900
+ # Returns a list of invite objects for the specified guild with status code 200 OK on success.
901
+ # See https://discord.com/developers/docs/resources/guild#get-guild-invites
902
+ # @param guild_id [String] ID (as a string) of the guild to get the invites from
903
+ # @return [Faraday::Response] The response from the Discord API as a Faraday::Response object.
592
904
  def get_guild_invites(guild_id)
593
905
  url = "#{@base_url}/guilds/#{guild_id}/invites"
594
906
  headers = { 'Authorization': @authorization_header }
595
- response = DiscordApi.get(url, headers)
596
- return response if response.status == 200
907
+ response = get(url, headers)
908
+ return response if response.is_a?(Faraday::Response) && response.status == 200
597
909
 
598
- @logger.error("Failed to get guild invites. Response: #{response.body}")
910
+ @logger.error("Failed to get guild invites. Response: #{response_error_body(response)}")
599
911
  response
600
912
  end
601
913
 
914
+ # Returns a list of integration objects for the specified guild with status code 200 OK on success.
915
+ # See https://discord.com/developers/docs/resources/guild#get-guild-integrations
916
+ # @param guild_id [String] ID (as a string) of the guild to get the integrations from
917
+ # @return [Faraday::Response] The response from the Discord API as a Faraday::Response object.
602
918
  def get_guild_integrations(guild_id)
603
919
  url = "#{@base_url}/guilds/#{guild_id}/integrations"
604
920
  headers = { 'Authorization': @authorization_header }
605
- response = DiscordApi.get(url, headers)
606
- if response.status == 200
921
+ response = get(url, headers)
922
+ if response.is_a?(Faraday::Response) && response.status == 200
607
923
  if JSON.parse(response.body).length == 50
608
924
  @logger.warn('The endpoint returned 50 integrations, which means there could be more integrations not shown.')
609
925
  end
610
926
  return response
611
927
  end
612
928
 
613
- @logger.error("Failed to get guild integrations. Response: #{response.body}")
929
+ @logger.error("Failed to get guild integrations. Response: #{response_error_body(response)}")
614
930
  response
615
931
  end
616
932
 
933
+ # Deletes a guild integration. Returns 204 No Content on success.
934
+ # See https://discord.com/developers/docs/resources/guild#delete-guild-integration
935
+ # @param guild_id [String] ID (as a string) of the guild containing the integration to delete
936
+ # @param integration_id [String] ID (as a string) of the integration to delete
937
+ # @param audit_reason [String, nil] Reason for the deletion, shows up on the audit log entry.
938
+ # @return [Faraday::Response] The response from the Discord API as a Faraday::Response object.
617
939
  def delete_guild_integration(guild_id, integration_id, audit_reason = nil)
618
940
  url = "#{@base_url}/guilds/#{guild_id}/integrations/#{integration_id}"
619
941
  headers = { 'Authorization': @authorization_header }
620
942
  headers['X-Audit-Log-Reason'] = audit_reason unless audit_reason.nil?
621
- response = DiscordApi.delete(url, headers)
622
- return response if response.status == 204
943
+ response = delete(url, headers)
944
+ return response if response.is_a?(Faraday::Response) && response.status == 204
623
945
 
624
- @logger.error("Failed to delete guild integration. Response: #{response.body}")
946
+ @logger.error("Failed to delete guild integration. Response: #{response_error_body(response)}")
625
947
  response
626
948
  end
627
949
 
950
+ # Returns the guild widget settings object for the specified guild with status code 200 OK on success.
951
+ # See https://discord.com/developers/docs/resources/guild#get-guild-widget-settings
952
+ # @param guild_id [String] ID (as a string) of the guild to get the widget settings from
953
+ # @return [Faraday::Response] The response from the Discord API as a Faraday::Response object.
628
954
  def get_guild_widget_settings(guild_id)
629
955
  url = "#{@base_url}/guilds/#{guild_id}/widget"
630
956
  headers = { 'Authorization': @authorization_header }
631
- response = DiscordApi.get(url, headers)
632
- return response if response.status == 200
957
+ response = get(url, headers)
958
+ return response if response.is_a?(Faraday::Response) && response.status == 200
633
959
 
634
- @logger.error("Failed to get guild widget settings. Response: #{response.body}")
960
+ @logger.error("Failed to get guild widget settings. Response: #{response_error_body(response)}")
635
961
  response
636
962
  end
637
963
 
964
+ # Modifies the guild widget settings for the specified guild. Returns the updated guild widget settings object
965
+ # with status code 200 OK on success.
966
+ # See https://discord.com/developers/docs/resources/guild#modify-guild-widget
967
+ # @param guild_id [String] ID (as a string) of the guild to modify the widget settings for
968
+ # @param enabled [TrueClass, FalseClass] Whether the guild widget is enabled
969
+ # @param channel_id [String] ID (as a string) of the channel to show in the widget
970
+ # @param audit_reason [String] Reason for the modification, shows up on the audit log entry.
971
+ # @return [Faraday::Response] The response from the Discord API as a Faraday::Response object.
638
972
  def modify_guild_widget(guild_id, enabled, channel_id, audit_reason: nil)
639
973
  output = {}
640
974
  output[:enabled] = enabled
@@ -643,33 +977,53 @@ class DiscordApi
643
977
  data = JSON.generate(output)
644
978
  headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
645
979
  headers['X-Audit-Log-Reason'] = audit_reason unless audit_reason.nil?
646
- response = DiscordApi.patch(url, data, headers)
647
- return response if response.status == 200
980
+ response = patch(url, data, headers)
981
+ return response if response.is_a?(Faraday::Response) && response.status == 200
648
982
 
649
- @logger.error("Failed to modify guild widget. Response: #{response.body}")
983
+ @logger.error("Failed to modify guild widget. Response: #{response_error_body(response)}")
650
984
  response
651
985
  end
652
986
 
653
- def get_guild_wiget(guild_id)
987
+ # Returns the widget object for the specified guild with status code 200 OK on success.
988
+ # See https://discord.com/developers/docs/resources/guild#get-guild-widget
989
+ # @param guild_id [String] ID (as a string) of the guild to get the widget from
990
+ # @return [Faraday::Response] The response from the Discord API as a Faraday::Response object.
991
+ def get_guild_widget(guild_id)
654
992
  url = "#{@base_url}/guilds/#{guild_id}/widget.json"
655
993
  headers = { 'Authorization': @authorization_header }
656
- response = DiscordApi.get(url, headers)
657
- return response if response.status == 200
994
+ response = get(url, headers)
995
+ return response if response.is_a?(Faraday::Response) && response.status == 200
658
996
 
659
- @logger.error("Failed to get guild widget. Response: #{response.body}")
997
+ @logger.error("Failed to get guild widget. Response: #{response_error_body(response)}")
660
998
  response
661
999
  end
662
1000
 
1001
+ # Returns a partial invite object for guilds with that feature enabled with status code 200 OK on success.
1002
+ # See https://discord.com/developers/docs/resources/guild#get-guild-vanity-url
1003
+ # @param guild_id [String] ID (as a string) of the guild to get the vanity URL from
1004
+ # @return [Faraday::Response] The response from the Discord API as a Faraday::Response object.
663
1005
  def get_guild_vanity_url(guild_id)
664
1006
  url = "#{@base_url}/guilds/#{guild_id}/vanity-url"
665
1007
  headers = { 'Authorization': @authorization_header }
666
- response = DiscordApi.get(url, headers)
667
- return response if response.status == 200
1008
+ response = get(url, headers)
1009
+ return response if response.is_a?(Faraday::Response) && response.status == 200
668
1010
 
669
- @logger.error("Failed to get guild vanity URL. Response: #{response.body}")
1011
+ @logger.error("Failed to get guild vanity URL. Response: #{response_error_body(response)}")
670
1012
  response
671
1013
  end
672
1014
 
1015
+ # Returns the widget image (PNG) for the specified guild.
1016
+ # Only one of the style convenience booleans (shield, banner1, banner2, banner3, banner4) can be true; if more than
1017
+ # one is specified the function logs an error and returns nil. If none are true, the default style is used (shield).
1018
+ # See https://discord.com/developers/docs/resources/guild#get-guild-widget-image
1019
+ # @param guild_id [String] ID (as a string) of the guild to get the widget image for.
1020
+ # @param shield [TrueClass, FalseClass] Whether to request the "shield" style widget image.
1021
+ # @param banner1 [TrueClass, FalseClass] Whether to request the "banner1" style widget image.
1022
+ # @param banner2 [TrueClass, FalseClass] Whether to request the "banner2" style widget image.
1023
+ # @param banner3 [TrueClass, FalseClass] Whether to request the "banner3" style widget image.
1024
+ # @param banner4 [TrueClass, FalseClass] Whether to request the "banner4" style widget image.
1025
+ # @return [Faraday::Response, nil] The response from the Discord API as a Faraday::Response object containing the
1026
+ # PNG image data, or nil if more than one style was specified.
673
1027
  def get_guild_widget_image(guild_id, shield: false, banner1: false, banner2: false, banner3: false, banner4: false)
674
1028
  options = { shield: shield, banner1: banner1, banner2: banner2, banner3: banner3, banner4: banner4 }
675
1029
  true_keys = options.select { |_k, v| v }.keys
@@ -688,23 +1042,38 @@ class DiscordApi
688
1042
  query_string = DiscordApi.handle_query_strings(query_string_hash)
689
1043
 
690
1044
  url = "#{@base_url}/guilds/#{guild_id}/widget.png#{query_string}"
691
- response = DiscordApi.get(url)
692
- return unless response.status != 200
1045
+ response = get(url)
1046
+ return response if response.is_a?(Faraday::Response) && response.status == 200
693
1047
 
694
- @logger.error("Failed to get guild widget image. Response: #{response.body}")
1048
+ @logger.error("Failed to get guild widget image. Response: #{response_error_body(response)}")
695
1049
  response
696
1050
  end
697
1051
 
1052
+ # Returns the welcome screen object for the specified guild.
1053
+ # See https://discord.com/developers/docs/resources/guild#get-guild-welcome-screen
1054
+ # @param guild_id [String] ID (as a string) of the guild to get the welcome screen for.
1055
+ # @return [Faraday::Response] The response from the Discord API as a Faraday::Response object.
698
1056
  def get_guild_welcome_screen(guild_id)
699
1057
  url = "#{@base_url}/guilds/#{guild_id}/welcome-screen"
700
1058
  headers = { 'Authorization': @authorization_header }
701
- response = DiscordApi.get(url, headers)
702
- return response if response.status == 200
1059
+ response = get(url, headers)
1060
+ return response if response.is_a?(Faraday::Response) && response.status == 200
703
1061
 
704
- @logger.error("Failed to get guild welcome screen. Response: #{response.body}")
1062
+ @logger.error("Failed to get guild welcome screen. Response: #{response_error_body(response)}")
705
1063
  response
706
1064
  end
707
1065
 
1066
+ # Modifies the welcome screen for the specified guild. Returns the updated welcome screen object on success.
1067
+ # If none of the optional parameters are specified (modifications, except audit_reason),
1068
+ # the function logs a warning and returns nil.
1069
+ # See https://discord.com/developers/docs/resources/guild#modify-guild-welcome-screen
1070
+ # @param guild_id [String] ID (as a string) of the guild to modify the welcome screen for.
1071
+ # @param enabled [TrueClass, FalseClass, nil] Whether the welcome screen is enabled.
1072
+ # @param welcome_channels [Array, nil] Array of welcome channel objects (hashes) to set.
1073
+ # @param description [String, nil] Description text for the welcome screen.
1074
+ # @param audit_reason [String, nil] Reason for the modification (appears in audit log entry).
1075
+ # @return [Faraday::Response, nil] The response from the Discord API as a Faraday::Response object, or nil if no
1076
+ # modifications were provided.
708
1077
  def modify_guild_welcome_screen(guild_id, enabled: nil, welcome_channels: nil, description: nil,
709
1078
  audit_reason: nil)
710
1079
  if args[1..-2].all?(&:nil?)
@@ -720,23 +1089,39 @@ class DiscordApi
720
1089
  data = JSON.generate(output)
721
1090
  headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
722
1091
  headers['X-Audit-Log-Reason'] = audit_reason unless audit_reason.nil?
723
- response = DiscordApi.patch(url, data, headers)
724
- return response if response.status == 200
1092
+ response = patch(url, data, headers)
1093
+ return response if response.is_a?(Faraday::Response) && response.status == 200
725
1094
 
726
- @logger.error("Failed to modify guild welcome screen. Response: #{response.body}")
1095
+ @logger.error("Failed to modify guild welcome screen. Response: #{response_error_body(response)}")
727
1096
  response
728
1097
  end
729
1098
 
1099
+ # Returns the onboarding object for the specified guild.
1100
+ # See https://discord.com/developers/docs/resources/guild#get-guild-onboarding
1101
+ # @param guild_id [String] ID (as a string) of the guild to get onboarding for.
1102
+ # @return [Faraday::Response] The response from the Discord API as a Faraday::Response object.
730
1103
  def get_guild_onboarding(guild_id)
731
1104
  url = "#{@base_url}/guilds/#{guild_id}/onboarding"
732
1105
  headers = { 'Authorization': @authorization_header }
733
- response = DiscordApi.get(url, headers)
734
- return response if response.status == 200
1106
+ response = get(url, headers)
1107
+ return response if response.is_a?(Faraday::Response) && response.status == 200
735
1108
 
736
- @logger.error("Failed to get guild onboarding. Response: #{response.body}")
1109
+ @logger.error("Failed to get guild onboarding. Response: #{response_error_body(response)}")
737
1110
  response
738
1111
  end
739
1112
 
1113
+ # Modifies the onboarding configuration for the specified guild. Returns the updated onboarding object on success.
1114
+ # If none of the optional parameters are specified (modifications, except audit_reason),
1115
+ # the function logs a warning and returns nil.
1116
+ # See https://discord.com/developers/docs/resources/guild#modify-guild-onboarding
1117
+ # @param guild_id [String] ID (as a string) of the guild to modify onboarding for.
1118
+ # @param prompts [Array, nil] Array of prompt objects to set.
1119
+ # @param default_channel_ids [Array, nil] Array of channel IDs (as strings) considered default for onboarding.
1120
+ # @param enabled [TrueClass, FalseClass, nil] Whether onboarding is enabled in the guild.
1121
+ # @param mode [Integer, nil] The onboarding mode to set.
1122
+ # @param audit_reason [String, nil] Reason for the modification (appears in audit log entry).
1123
+ # @return [Faraday::Response, nil] The response from the Discord API as a Faraday::Response object, or nil if no
1124
+ # modifications were provided.
740
1125
  def modify_guild_onboarding(guild_id, prompts: nil, default_channel_ids: nil, enabled: nil, mode: nil,
741
1126
  audit_reason: nil)
742
1127
  if args[1..-2].all?(&:nil?)
@@ -753,13 +1138,23 @@ class DiscordApi
753
1138
  data = JSON.generate(output)
754
1139
  headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
755
1140
  headers['X-Audit-Log-Reason'] = audit_reason unless audit_reason.nil?
756
- response = DiscordApi.put(url, data, headers)
757
- return response if response.status == 200
1141
+ response = put(url, data, headers)
1142
+ return response if response.is_a?(Faraday::Response) && response.status == 200
758
1143
 
759
- @logger.error("Failed to modify guild onboarding. Response: #{response.body}")
1144
+ @logger.error("Failed to modify guild onboarding. Response: #{response_error_body(response)}")
760
1145
  response
761
1146
  end
762
1147
 
1148
+ # Modifies the incident actions for a guild (e.g. temporarily disabling invites or direct messages).
1149
+ # If none of the optional parameters are specified (modifications), the function logs a warning and returns nil.
1150
+ # See https://discord.com/developers/docs/resources/guild#modify-guild-incident-actions
1151
+ # @param guild_id [String] ID (as a string) of the guild to modify incident actions for.
1152
+ # @param invites_disabled_until [String, FalseClass, nil] ISO8601 timestamp until which invites are disabled,
1153
+ # false to clear, or nil to leave unchanged.
1154
+ # @param dms_disabled_until [String, FalseClass, nil] ISO8601 timestamp until which DMs are disabled,
1155
+ # false to clear, or nil to leave unchanged.
1156
+ # @return [Faraday::Response, nil] The response from the Discord API as a Faraday::Response object, or nil if no
1157
+ # modifications were provided.
763
1158
  def modify_guild_incident_actions(guild_id, invites_disabled_until: nil, dms_disabled_until: nil)
764
1159
  if args[1..].all?(&:nil?)
765
1160
  @logger.warn("No modifications for guild incident actions with guild ID #{guild_id} provided. " \
@@ -780,10 +1175,10 @@ class DiscordApi
780
1175
  url = "#{@base_url}/guilds/#{guild_id}/incident-actions"
781
1176
  data = JSON.generate(output)
782
1177
  headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
783
- response = DiscordApi.put(url, data, headers)
784
- return response if response.status == 200
1178
+ response = put(url, data, headers)
1179
+ return response if response.is_a?(Faraday::Response) && response.status == 200
785
1180
 
786
- @logger.error("Failed to modify guild incident actions. Response: #{response.body}")
1181
+ @logger.error("Failed to modify guild incident actions. Response: #{response_error_body(response)}")
787
1182
  response
788
1183
  end
789
1184
  end