Module: Discordrb::API::Server

Defined in:
lib/discordrb/api/server.rb

Overview

API calls for Server

Class Method Summary collapse

Class Method Details

.add_emoji(token, server_id, image, name, reason = nil) ⇒ Object

Adds a custom emoji


401
402
403
404
405
406
407
408
409
410
411
412
# File 'lib/discordrb/api/server.rb', line 401

def add_emoji(token, server_id, image, name, reason = nil)
  Discordrb::API.request(
    :guilds_sid_emojis,
    server_id,
    :post,
    "#{Discordrb::API.api_base}/guilds/#{server_id}/emojis",
    { image: image, name: name }.to_json,
    Authorization: token,
    content_type: :json,
    'X-Audit-Log-Reason': reason
  )
end

.add_member(token, server_id, user_id, access_token, nick = nil, roles = [], mute = false, deaf = false) ⇒ Object

Adds a member to a server with an OAuth2 Bearer token that has been granted guilds.join https://discordapp.com/developers/docs/resources/guild#add-guild-member


465
466
467
468
469
470
471
472
473
474
475
# File 'lib/discordrb/api/server.rb', line 465

def add_member(token, server_id, user_id, access_token, nick = nil, roles = [], mute = false, deaf = false)
  Discordrb::API.request(
    :guilds_sid_members_uid,
    server_id,
    :put,
    "#{Discordrb::API.api_base}/guilds/#{server_id}/members/#{user_id}",
    { access_token: access_token, nick: nick, roles: roles, mute: mute, deaf: deaf }.to_json,
    content_type: :json,
    Authorization: token
  )
end

.add_member_role(token, server_id, user_id, role_id, reason = nil) ⇒ Object


273
274
275
276
277
278
279
280
281
282
283
# File 'lib/discordrb/api/server.rb', line 273

def add_member_role(token, server_id, user_id, role_id, reason = nil)
  Discordrb::API.request(
    :guilds_sid_members_uid_roles_rid,
    server_id,
    :put,
    "#{Discordrb::API.api_base}/guilds/#{server_id}/members/#{user_id}/roles/#{role_id}",
    nil,
    Authorization: token,
    'X-Audit-Log-Reason': reason
  )
end

.ban_user(token, server_id, user_id, message_days, reason = nil) ⇒ Object

Ban a user from a server and delete their messages from the last message_days days https://discordapp.com/developers/docs/resources/guild#create-guild-ban


186
187
188
189
190
191
192
193
194
195
# File 'lib/discordrb/api/server.rb', line 186

def ban_user(token, server_id, user_id, message_days, reason = nil)
  Discordrb::API.request(
    :guilds_sid_bans_uid,
    server_id,
    :put,
    "#{Discordrb::API.api_base}/guilds/#{server_id}/bans/#{user_id}?delete-message-days=#{message_days}#{reason ? "&reason=#{reason}" : ''}",
    nil,
    Authorization: token
  )
end

.bans(token, server_id) ⇒ Object


174
175
176
177
178
179
180
181
182
# File 'lib/discordrb/api/server.rb', line 174

def bans(token, server_id)
  Discordrb::API.request(
    :guilds_sid_bans,
    server_id,
    :get,
    "#{Discordrb::API.api_base}/guilds/#{server_id}/bans",
    Authorization: token
  )
end

.begin_prune(token, server_id, days, reason = nil) ⇒ Object


312
313
314
315
316
317
318
319
320
321
322
# File 'lib/discordrb/api/server.rb', line 312

def begin_prune(token, server_id, days, reason = nil)
  Discordrb::API.request(
    :guilds_sid_prune,
    server_id,
    :post,
    "#{Discordrb::API.api_base}/guilds/#{server_id}/prune",
    { days: days },
    Authorization: token,
    'X-Audit-Log-Reason': reason
  )
end

.channels(token, server_id) ⇒ Object


74
75
76
77
78
79
80
81
82
# File 'lib/discordrb/api/server.rb', line 74

def channels(token, server_id)
  Discordrb::API.request(
    :guilds_sid_channels,
    server_id,
    :get,
    "#{Discordrb::API.api_base}/guilds/#{server_id}/channels",
    Authorization: token
  )
end

.create(token, name, region = eu-central) ⇒ Object


7
8
9
10
11
12
13
14
15
16
17
# File 'lib/discordrb/api/server.rb', line 7

def create(token, name, region = :'eu-central')
  Discordrb::API.request(
    :guilds,
    nil,
    :post,
    "#{Discordrb::API.api_base}/guilds",
    { name: name, region: region.to_s }.to_json,
    Authorization: token,
    content_type: :json
  )
end

.create_channel(token, server_id, name, type, bitrate, user_limit, permission_overwrites, nsfw, reason = nil) ⇒ Object


86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/discordrb/api/server.rb', line 86

def create_channel(token, server_id, name, type, bitrate, user_limit, permission_overwrites, nsfw, reason = nil)
  Discordrb::API.request(
    :guilds_sid_channels,
    server_id,
    :post,
    "#{Discordrb::API.api_base}/guilds/#{server_id}/channels",
    { name: name, type: type, bitrate: bitrate, user_limit: user_limit, permission_overwrites: permission_overwrites, nsfw: nsfw }.to_json,
    Authorization: token,
    content_type: :json,
    'X-Audit-Log-Reason': reason
  )
end

.create_integration(token, server_id, type, id) ⇒ Object


350
351
352
353
354
355
356
357
358
359
# File 'lib/discordrb/api/server.rb', line 350

def create_integration(token, server_id, type, id)
  Discordrb::API.request(
    :guilds_sid_integrations,
    server_id,
    :post,
    "#{Discordrb::API.api_base}/guilds/#{server_id}/integrations",
    { type: type, id: id },
    Authorization: token
  )
end

.create_role(token, server_id, name, colour, hoist, mentionable, packed_permissions, reason = nil) ⇒ Object

Create a role (parameters such as name and colour if not set can be set by update_role afterwards) Permissions are the Discord defaults; allowed: invite creation, reading/sending messages, sending TTS messages, embedding links, sending files, reading the history, mentioning everybody, connecting to voice, speaking and voice activity (push-to-talk isn't mandatory) https://discordapp.com/developers/docs/resources/guild#get-guild-roles


227
228
229
230
231
232
233
234
235
236
237
238
# File 'lib/discordrb/api/server.rb', line 227

def create_role(token, server_id, name, colour, hoist, mentionable, packed_permissions, reason = nil)
  Discordrb::API.request(
    :guilds_sid_roles,
    server_id,
    :post,
    "#{Discordrb::API.api_base}/guilds/#{server_id}/roles",
    { color: colour, name: name, hoist: hoist, mentionable: mentionable, permissions: packed_permissions }.to_json,
    Authorization: token,
    content_type: :json,
    'X-Audit-Log-Reason': reason
  )
end

.delete(token, server_id) ⇒ Object


62
63
64
65
66
67
68
69
70
# File 'lib/discordrb/api/server.rb', line 62

def delete(token, server_id)
  Discordrb::API.request(
    :guilds_sid,
    server_id,
    :delete,
    "#{Discordrb::API.api_base}/guilds/#{server_id}",
    Authorization: token
  )
end

.delete_emoji(token, server_id, emoji_id, reason = nil) ⇒ Object

Deletes a custom emoji


429
430
431
432
433
434
435
436
437
438
# File 'lib/discordrb/api/server.rb', line 429

def delete_emoji(token, server_id, emoji_id, reason = nil)
  Discordrb::API.request(
    :guilds_sid_emojis_eid,
    server_id,
    :delete,
    "#{Discordrb::API.api_base}/guilds/#{server_id}/emojis/#{emoji_id}",
    Authorization: token,
    'X-Audit-Log-Reason': reason
  )
end

.delete_integration(token, server_id, integration_id) ⇒ Object


377
378
379
380
381
382
383
384
385
# File 'lib/discordrb/api/server.rb', line 377

def delete_integration(token, server_id, integration_id)
  Discordrb::API.request(
    :guilds_sid_integrations_iid,
    server_id,
    :delete,
    "#{Discordrb::API.api_base}/guilds/#{server_id}/integrations/#{integration_id}",
    Authorization: token
  )
end

.delete_role(token, server_id, role_id, reason = nil) ⇒ Object


260
261
262
263
264
265
266
267
268
269
# File 'lib/discordrb/api/server.rb', line 260

def delete_role(token, server_id, role_id, reason = nil)
  Discordrb::API.request(
    :guilds_sid_roles_rid,
    server_id,
    :delete,
    "#{Discordrb::API.api_base}/guilds/#{server_id}/roles/#{role_id}",
    Authorization: token,
    'X-Audit-Log-Reason': reason
  )
end

.edit_emoji(token, server_id, emoji_id, name, reason = nil) ⇒ Object

Changes an emoji name


415
416
417
418
419
420
421
422
423
424
425
426
# File 'lib/discordrb/api/server.rb', line 415

def edit_emoji(token, server_id, emoji_id, name, reason = nil)
  Discordrb::API.request(
    :guilds_sid_emojis_eid,
    server_id,
    :patch,
    "#{Discordrb::API.api_base}/guilds/#{server_id}/emojis/#{emoji_id}",
    { name: name }.to_json,
    Authorization: token,
    content_type: :json,
    'X-Audit-Log-Reason': reason
  )
end

.integrations(token, server_id) ⇒ Object


338
339
340
341
342
343
344
345
346
# File 'lib/discordrb/api/server.rb', line 338

def integrations(token, server_id)
  Discordrb::API.request(
    :guilds_sid_integrations,
    server_id,
    :get,
    "#{Discordrb::API.api_base}/guilds/#{server_id}/integrations",
    Authorization: token
  )
end

.invites(token, server_id) ⇒ Object


326
327
328
329
330
331
332
333
334
# File 'lib/discordrb/api/server.rb', line 326

def invites(token, server_id)
  Discordrb::API.request(
    :guilds_sid_invites,
    server_id,
    :get,
    "#{Discordrb::API.api_base}/guilds/#{server_id}/invites",
    Authorization: token
  )
end

.prune_count(token, server_id, days) ⇒ Object


300
301
302
303
304
305
306
307
308
# File 'lib/discordrb/api/server.rb', line 300

def prune_count(token, server_id, days)
  Discordrb::API.request(
    :guilds_sid_prune,
    server_id,
    :get,
    "#{Discordrb::API.api_base}/guilds/#{server_id}/prune?days=#{days}",
    Authorization: token
  )
end

.regions(token, server_id) ⇒ Object

Available voice regions for this server


441
442
443
444
445
446
447
448
449
# File 'lib/discordrb/api/server.rb', line 441

def regions(token, server_id)
  Discordrb::API.request(
    :guilds_sid_regions,
    server_id,
    :get,
    "#{Discordrb::API.api_base}/guilds/#{server_id}/regions",
    Authorization: token
  )
end

.remove_member(token, server_id, user_id, reason = nil) ⇒ Object


160
161
162
163
164
165
166
167
168
169
170
# File 'lib/discordrb/api/server.rb', line 160

def remove_member(token, server_id, user_id, reason = nil)
  Discordrb::API.request(
    :guilds_sid_members_uid,
    server_id,
    :delete,
    "#{Discordrb::API.api_base}/guilds/#{server_id}/members/#{user_id}",
    Authorization: token,
    content_type: :json,
    'X-Audit-Log-Reason': reason
  )
end

.remove_member_role(token, server_id, user_id, role_id, reason = nil) ⇒ Object


287
288
289
290
291
292
293
294
295
296
# File 'lib/discordrb/api/server.rb', line 287

def remove_member_role(token, server_id, user_id, role_id, reason = nil)
  Discordrb::API.request(
    :guilds_sid_members_uid_roles_rid,
    server_id,
    :delete,
    "#{Discordrb::API.api_base}/guilds/#{server_id}/members/#{user_id}/roles/#{role_id}",
    Authorization: token,
    'X-Audit-Log-Reason': reason
  )
end

.resolve(token, server_id) ⇒ Object


21
22
23
24
25
26
27
28
29
# File 'lib/discordrb/api/server.rb', line 21

def resolve(token, server_id)
  Discordrb::API.request(
    :guilds_sid,
    server_id,
    :get,
    "#{Discordrb::API.api_base}/guilds/#{server_id}",
    Authorization: token
  )
end

.resolve_member(token, server_id, user_id) ⇒ Object


116
117
118
119
120
121
122
123
124
# File 'lib/discordrb/api/server.rb', line 116

def resolve_member(token, server_id, user_id)
  Discordrb::API.request(
    :guilds_sid_members_uid,
    server_id,
    :get,
    "#{Discordrb::API.api_base}/guilds/#{server_id}/members/#{user_id}",
    Authorization: token
  )
end

.resolve_members(token, server_id, limit, after = nil) ⇒ Object


128
129
130
131
132
133
134
135
136
# File 'lib/discordrb/api/server.rb', line 128

def resolve_members(token, server_id, limit, after = nil)
  Discordrb::API.request(
    :guilds_sid_members,
    server_id,
    :get,
    "#{Discordrb::API.api_base}/guilds/#{server_id}/members?limit=#{limit}#{"&after=#{after}" if after}",
    Authorization: token
  )
end

.roles(token, server_id) ⇒ Object


212
213
214
215
216
217
218
219
220
# File 'lib/discordrb/api/server.rb', line 212

def roles(token, server_id)
  Discordrb::API.request(
    :guilds_sid_roles,
    server_id,
    :get,
    "#{Discordrb::API.api_base}/guilds/#{server_id}/roles",
    Authorization: token
  )
end

.sync_integration(token, server_id, integration_id) ⇒ Object


389
390
391
392
393
394
395
396
397
398
# File 'lib/discordrb/api/server.rb', line 389

def sync_integration(token, server_id, integration_id)
  Discordrb::API.request(
    :guilds_sid_integrations_iid_sync,
    server_id,
    :post,
    "#{Discordrb::API.api_base}/guilds/#{server_id}/integrations/#{integration_id}/sync",
    nil,
    Authorization: token
  )
end

.transfer_ownership(token, server_id, user_id, reason = nil) ⇒ Object

Transfer server ownership


47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/discordrb/api/server.rb', line 47

def transfer_ownership(token, server_id, user_id, reason = nil)
  Discordrb::API.request(
    :guilds_sid,
    server_id,
    :patch,
    "#{Discordrb::API.api_base}/guilds/#{server_id}",
    { owner_id: user_id }.to_json,
    Authorization: token,
    content_type: :json,
    'X-Audit-Log-Reason': reason
  )
end

.unban_user(token, server_id, user_id, reason = nil) ⇒ Object


199
200
201
202
203
204
205
206
207
208
# File 'lib/discordrb/api/server.rb', line 199

def unban_user(token, server_id, user_id, reason = nil)
  Discordrb::API.request(
    :guilds_sid_bans_uid,
    server_id,
    :delete,
    "#{Discordrb::API.api_base}/guilds/#{server_id}/bans/#{user_id}",
    Authorization: token,
    'X-Audit-Log-Reason': reason
  )
end

.update(token, server_id, name, region, icon, afk_channel_id, afk_timeout, splash, default_message_notifications, verification_level, explicit_content_filter, system_channel_id, reason = nil) ⇒ Object


33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/discordrb/api/server.rb', line 33

def update(token, server_id, name, region, icon, afk_channel_id, afk_timeout, splash, default_message_notifications, verification_level, explicit_content_filter, system_channel_id, reason = nil)
  Discordrb::API.request(
    :guilds_sid,
    server_id,
    :patch,
    "#{Discordrb::API.api_base}/guilds/#{server_id}",
    { name: name, region: region, icon: icon, afk_channel_id: afk_channel_id, afk_timeout: afk_timeout, splash: splash, default_message_notifications: default_message_notifications, verification_level: verification_level, explicit_content_filter: explicit_content_filter, system_channel_id: system_channel_id }.to_json,
    Authorization: token,
    content_type: :json,
    'X-Audit-Log-Reason': reason
  )
end

.update_channel(token, server_id, channel_id, position, reason = nil) ⇒ Object


101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/discordrb/api/server.rb', line 101

def update_channel(token, server_id, channel_id, position, reason = nil)
  Discordrb::API.request(
    :guilds_sid_channels,
    server_id,
    :patch,
    "#{Discordrb::API.api_base}/guilds/#{server_id}/channels",
    { id: channel_id, position: position }.to_json,
    Authorization: token,
    content_type: :json,
    'X-Audit-Log-Reason': reason
  )
end

.update_integration(token, server_id, integration_id, expire_behavior, expire_grace_period, enable_emoticons) ⇒ Object


363
364
365
366
367
368
369
370
371
372
373
# File 'lib/discordrb/api/server.rb', line 363

def update_integration(token, server_id, integration_id, expire_behavior, expire_grace_period, enable_emoticons)
  Discordrb::API.request(
    :guilds_sid_integrations_iid,
    server_id,
    :patch,
    "#{Discordrb::API.api_base}/guilds/#{server_id}/integrations/#{integration_id}",
    { expire_behavior: expire_behavior, expire_grace_period: expire_grace_period, enable_emoticons: enable_emoticons }.to_json,
    Authorization: token,
    content_type: :json
  )
end

.update_member(token, server_id, user_id, nick: nil, roles: nil, mute: nil, deaf: nil, channel_id: nil, reason: nil) ⇒ Object


140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/discordrb/api/server.rb', line 140

def update_member(token, server_id, user_id, nick: nil, roles: nil, mute: nil, deaf: nil, channel_id: nil, reason: nil)
  Discordrb::API.request(
    :guilds_sid_members_uid,
    server_id,
    :patch,
    "#{Discordrb::API.api_base}/guilds/#{server_id}/members/#{user_id}", {
      roles: roles,
      nick: nick,
      mute: mute,
      deaf: deaf,
      channel_id: channel_id
    }.reject { |_, v| v.nil? }.to_json,
    Authorization: token,
    content_type: :json,
    'X-Audit-Log-Reason': reason
  )
end

.update_role(token, server_id, role_id, name, colour, hoist = false, mentionable = false, packed_permissions = 104_324_161, reason = nil) ⇒ Object

Update a role Permissions are the Discord defaults; allowed: invite creation, reading/sending messages, sending TTS messages, embedding links, sending files, reading the history, mentioning everybody, connecting to voice, speaking and voice activity (push-to-talk isn't mandatory) https://discordapp.com/developers/docs/resources/guild#batch-modify-guild-role


245
246
247
248
249
250
251
252
253
254
255
256
# File 'lib/discordrb/api/server.rb', line 245

def update_role(token, server_id, role_id, name, colour, hoist = false, mentionable = false, packed_permissions = 104_324_161, reason = nil)
  Discordrb::API.request(
    :guilds_sid_roles_rid,
    server_id,
    :patch,
    "#{Discordrb::API.api_base}/guilds/#{server_id}/roles/#{role_id}",
    { color: colour, name: name, hoist: hoist, mentionable: mentionable, permissions: packed_permissions }.to_json,
    Authorization: token,
    content_type: :json,
    'X-Audit-Log-Reason': reason
  )
end

.webhooks(token, server_id) ⇒ Object


453
454
455
456
457
458
459
460
461
# File 'lib/discordrb/api/server.rb', line 453

def webhooks(token, server_id)
  Discordrb::API.request(
    :guilds_sid_webhooks,
    server_id,
    :get,
    "#{Discordrb::API.api_base}/guilds/#{server_id}/webhooks",
    Authorization: token
  )
end