Module: Discordrb::API::Channel

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

Overview

API calls for Channel

Class Method Summary collapse

Class Method Details

.add_group_user(token, group_channel_id, user_id) ⇒ Object

Deprecated.

Discord no longer supports bots in group DMs, this endpoint was repurposed and no longer works as implemented here.

Add a user to a group channel. https://discord.com/developers/docs/resources/channel#group-dm-add-recipient



422
423
424
425
426
427
428
429
430
431
432
# File 'lib/discordrb/api/channel.rb', line 422

def add_group_user(token, group_channel_id, user_id)
  Discordrb::API.request(
    :channels_cid_recipients_uid,
    nil,
    :put,
    "#{Discordrb::API.api_base}/channels/#{group_channel_id}/recipients/#{user_id}",
    {}.to_json,
    Authorization: token,
    content_type: :json
  )
end

.add_thread_member(token, channel_id, user_id) ⇒ Object



547
548
549
550
551
552
553
554
555
556
# File 'lib/discordrb/api/channel.rb', line 547

def add_thread_member(token, channel_id, user_id)
  Discordrb::API.request(
    :channels_cid_thread_members_uid,
    channel_id,
    :put,
    "#{Discordrb::API.api_base}/channels/#{channel_id}/thread-members/#{user_id}",
    nil,
    Authorization: token
  )
end

.bulk_delete_messages(token, channel_id, messages = [], reason = nil) ⇒ Object



181
182
183
184
185
186
187
188
189
190
191
192
# File 'lib/discordrb/api/channel.rb', line 181

def bulk_delete_messages(token, channel_id, messages = [], reason = nil)
  Discordrb::API.request(
    :channels_cid_messages_bulk_delete,
    channel_id,
    :post,
    "#{Discordrb::API.api_base}/channels/#{channel_id}/messages/bulk-delete",
    { messages: messages }.to_json,
    Authorization: token,
    content_type: :json,
    'X-Audit-Log-Reason': reason
  )
end

.create_empty_group(token, bot_user_id) ⇒ Object

Deprecated.

Discord no longer supports bots in group DMs, this endpoint was repurposed and no longer works as implemented here.

Create an empty group channel. https://discord.com/developers/docs/resources/user#create-group-dm



386
387
388
389
390
391
392
393
394
395
396
# File 'lib/discordrb/api/channel.rb', line 386

def create_empty_group(token, bot_user_id)
  Discordrb::API.request(
    :users_uid_channels,
    nil,
    :post,
    "#{Discordrb::API.api_base}/users/#{bot_user_id}/channels",
    {}.to_json,
    Authorization: token,
    content_type: :json
  )
end

.create_group(token, pm_channel_id, user_id) ⇒ Object

Deprecated.

Discord no longer supports bots in group DMs, this endpoint was repurposed and no longer works as implemented here.

Create a group channel. https://discord.com/developers/docs/resources/channel#group-dm-add-recipient



401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
# File 'lib/discordrb/api/channel.rb', line 401

def create_group(token, pm_channel_id, user_id)
  Discordrb::API.request(
    :channels_cid_recipients_uid,
    nil,
    :put,
    "#{Discordrb::API.api_base}/channels/#{pm_channel_id}/recipients/#{user_id}",
    {}.to_json,
    Authorization: token,
    content_type: :json
  )
rescue RestClient::InternalServerError
  raise 'Attempted to add self as a new group channel recipient!'
rescue RestClient::NoContent
  raise 'Attempted to create a group channel with the PM channel recipient!'
rescue RestClient::Forbidden
  raise 'Attempted to add a user to group channel without permission!'
end

.create_invite(token, channel_id, max_age = 0, max_uses = 0, temporary = false, unique = false, reason = nil) ⇒ Object

Create an instant invite from a server or a channel id https://discord.com/developers/docs/resources/channel#create-channel-invite



304
305
306
307
308
309
310
311
312
313
314
315
# File 'lib/discordrb/api/channel.rb', line 304

def create_invite(token, channel_id, max_age = 0, max_uses = 0, temporary = false, unique = false, reason = nil)
  Discordrb::API.request(
    :channels_cid_invites,
    channel_id,
    :post,
    "#{Discordrb::API.api_base}/channels/#{channel_id}/invites",
    { max_age: max_age, max_uses: max_uses, temporary: temporary, unique: unique }.to_json,
    Authorization: token,
    content_type: :json,
    'X-Audit-Log-Reason': reason
  )
end

.create_message(token, channel_id, message, tts = false, embeds = nil, nonce = nil, attachments = nil, allowed_mentions = nil, message_reference = nil, components = nil, flags = nil, enforce_nonce = false, poll = nil) ⇒ Object

Parameters:



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/discordrb/api/channel.rb', line 100

def create_message(token, channel_id, message, tts = false, embeds = nil, nonce = nil, attachments = nil, allowed_mentions = nil, message_reference = nil, components = nil, flags = nil, enforce_nonce = false, poll = nil)
  body = { content: message, tts: tts, embeds: embeds, nonce: nonce, allowed_mentions: allowed_mentions, message_reference: message_reference, components: components&.to_a, flags: flags, enforce_nonce: enforce_nonce, poll: poll }
  body = if attachments
           files = [*0...attachments.size].zip(attachments).to_h
           { **files, payload_json: body.to_json }
         else
           body.to_json
         end

  headers = { Authorization: token }
  headers[:content_type] = :json unless attachments

  Discordrb::API.request(
    :channels_cid_messages_mid,
    channel_id,
    :post,
    "#{Discordrb::API.api_base}/channels/#{channel_id}/messages",
    body,
    **headers
  )
rescue RestClient::BadRequest => e
  parsed = JSON.parse(e.response.body)
  raise Discordrb::Errors::MessageTooLong, "Message over the character limit (#{message.length} > 2000)" if parsed['content'].is_a?(Array) && parsed['content'].first == 'Must be 2000 or fewer in length.'

  raise
end

.create_reaction(token, channel_id, message_id, emoji) ⇒ Object

Create a reaction on a message using this client https://discord.com/developers/docs/resources/channel#create-reaction



196
197
198
199
200
201
202
203
204
205
206
207
# File 'lib/discordrb/api/channel.rb', line 196

def create_reaction(token, channel_id, message_id, emoji)
  emoji = URI.encode_www_form_component(emoji) unless emoji.ascii_only?
  Discordrb::API.request(
    :channels_cid_messages_mid_reactions_emoji_me,
    channel_id,
    :put,
    "#{Discordrb::API.api_base}/channels/#{channel_id}/messages/#{message_id}/reactions/#{emoji}/@me",
    nil,
    Authorization: token,
    content_type: :json
  )
end

.create_webhook(token, channel_id, name, avatar = nil, reason = nil) ⇒ Object



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

def create_webhook(token, channel_id, name, avatar = nil, reason = nil)
  Discordrb::API.request(
    :channels_cid_webhooks,
    channel_id,
    :post,
    "#{Discordrb::API.api_base}/channels/#{channel_id}/webhooks",
    { name: name, avatar: avatar }.to_json,
    Authorization: token,
    content_type: :json,
    'X-Audit-Log-Reason': reason
  )
end

.crosspost_message(token, channel_id, message_id) ⇒ Object



169
170
171
172
173
174
175
176
177
# File 'lib/discordrb/api/channel.rb', line 169

def crosspost_message(token, channel_id, message_id)
  Discordrb::API.request(
    :channels_cid_messages_mid,
    channel_id,
    :post,
    "#{Discordrb::API.api_base}/channels/#{channel_id}/messages/#{message_id}/crosspost",
    Authorization: token
  )
end

.delete(token, channel_id, reason = nil) ⇒ Object



53
54
55
56
57
58
59
60
61
62
# File 'lib/discordrb/api/channel.rb', line 53

def delete(token, channel_id, reason = nil)
  Discordrb::API.request(
    :channels_cid,
    channel_id,
    :delete,
    "#{Discordrb::API.api_base}/channels/#{channel_id}",
    Authorization: token,
    'X-Audit-Log-Reason': reason
  )
end

.delete_all_emoji_reactions(token, channel_id, message_id, emoji) ⇒ Object

Deletes all the reactions for a given emoji on a message https://discord.com/developers/docs/resources/channel#delete-all-reactions-for-emoji



263
264
265
266
267
268
269
270
271
272
273
# File 'lib/discordrb/api/channel.rb', line 263

def delete_all_emoji_reactions(token, channel_id, message_id, emoji)
  emoji = URI.encode_www_form_component(emoji) unless emoji.ascii_only?

  Discordrb::API.request(
    :channels_cid_messages_mid_reactions_emoji,
    channel_id,
    :delete,
    "#{Discordrb::API.api_base}/channels/#{channel_id}/messages/#{message_id}/reactions/#{emoji}",
    Authorization: token
  )
end

.delete_all_reactions(token, channel_id, message_id) ⇒ Object

Deletes all reactions on a message from all clients https://discord.com/developers/docs/resources/channel#delete-all-reactions



251
252
253
254
255
256
257
258
259
# File 'lib/discordrb/api/channel.rb', line 251

def delete_all_reactions(token, channel_id, message_id)
  Discordrb::API.request(
    :channels_cid_messages_mid_reactions,
    channel_id,
    :delete,
    "#{Discordrb::API.api_base}/channels/#{channel_id}/messages/#{message_id}/reactions",
    Authorization: token
  )
end

.delete_message(token, channel_id, message_id, reason = nil) ⇒ Object



156
157
158
159
160
161
162
163
164
165
# File 'lib/discordrb/api/channel.rb', line 156

def delete_message(token, channel_id, message_id, reason = nil)
  Discordrb::API.request(
    :channels_cid_messages_mid,
    channel_id,
    :delete,
    "#{Discordrb::API.api_base}/channels/#{channel_id}/messages/#{message_id}",
    Authorization: token,
    'X-Audit-Log-Reason': reason
  )
end

.delete_own_reaction(token, channel_id, message_id, emoji) ⇒ Object

Delete this client's own reaction on a message https://discord.com/developers/docs/resources/channel#delete-own-reaction



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

def delete_own_reaction(token, channel_id, message_id, emoji)
  emoji = URI.encode_www_form_component(emoji) unless emoji.ascii_only?
  Discordrb::API.request(
    :channels_cid_messages_mid_reactions_emoji_me,
    channel_id,
    :delete,
    "#{Discordrb::API.api_base}/channels/#{channel_id}/messages/#{message_id}/reactions/#{emoji}/@me",
    Authorization: token
  )
end

.delete_permission(token, channel_id, overwrite_id, reason = nil) ⇒ Object



319
320
321
322
323
324
325
326
327
328
# File 'lib/discordrb/api/channel.rb', line 319

def delete_permission(token, channel_id, overwrite_id, reason = nil)
  Discordrb::API.request(
    :channels_cid_permissions_oid,
    channel_id,
    :delete,
    "#{Discordrb::API.api_base}/channels/#{channel_id}/permissions/#{overwrite_id}",
    Authorization: token,
    'X-Audit-Log-Reason': reason
  )
end

.delete_user_reaction(token, channel_id, message_id, emoji, user_id) ⇒ Object



224
225
226
227
228
229
230
231
232
233
# File 'lib/discordrb/api/channel.rb', line 224

def delete_user_reaction(token, channel_id, message_id, emoji, user_id)
  emoji = URI.encode_www_form_component(emoji) unless emoji.ascii_only?
  Discordrb::API.request(
    :channels_cid_messages_mid_reactions_emoji_uid,
    channel_id,
    :delete,
    "#{Discordrb::API.api_base}/channels/#{channel_id}/messages/#{message_id}/reactions/#{emoji}/#{user_id}",
    Authorization: token
  )
end

.edit_message(token, channel_id, message_id, message, mentions = nil, embeds = nil, components = nil, flags = nil) ⇒ Object



142
143
144
145
146
147
148
149
150
151
152
# File 'lib/discordrb/api/channel.rb', line 142

def edit_message(token, channel_id, message_id, message, mentions = nil, embeds = nil, components = nil, flags = nil)
  Discordrb::API.request(
    :channels_cid_messages_mid,
    channel_id,
    :patch,
    "#{Discordrb::API.api_base}/channels/#{channel_id}/messages/#{message_id}",
    { content: message, allowed_mentions: mentions, embeds: embeds, components: components, flags: flags }.reject { |_, v| v == :undef }.to_json,
    Authorization: token,
    content_type: :json
  )
end

.end_poll(token, channel_id, message_id) ⇒ Object

End a poll created by the current user. https://discord.com/developers/docs/resources/poll#end-poll



705
706
707
708
709
710
711
712
713
714
# File 'lib/discordrb/api/channel.rb', line 705

def end_poll(token, channel_id, message_id)
  Discordrb::API.request(
    :channels_cid_polls_mid_expire,
    channel_id,
    :post,
    "#{Discordrb::API.api_base}/channels/#{channel_id}/polls/#{message_id}/expire",
    nil,
    Authorization: token
  )
end

.follow_channel(token, channel_id, webhook_channel_id, reason = nil) ⇒ Object



491
492
493
494
495
496
497
498
499
500
501
502
# File 'lib/discordrb/api/channel.rb', line 491

def follow_channel(token, channel_id, webhook_channel_id, reason = nil)
  Discordrb::API.request(
    :channels_cid_followers,
    channel_id,
    :post,
    "#{Discordrb::API.api_base}/channels/#{channel_id}/followers",
    { webhook_channel_id: webhook_channel_id }.to_json,
    Authorization: token,
    content_type: :json,
    'X-Audit-Log-Reason': reason
  )
end

.get_channel_messages(token, channel_id, limit: 50, after: nil, before: nil, around: nil) ⇒ Object

Fetch the messages that have been sent in the channel. https://docs.discord.com/developers/resources/message#get-channel-messages



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

def get_channel_messages(token, channel_id, limit: 50, after: nil, before: nil, around: nil)
  query = URI.encode_www_form({ limit:, after:, before:, around: }.compact)

  Discordrb::API.request(
    :channels_cid_messages,
    channel_id,
    :get,
    "#{Discordrb::API.api_base}/channels/#{channel_id}/messages?#{query}",
    Authorization: token
  )
end

.get_poll_voters(token, channel_id, message_id, answer_id, limit: 100, after: nil) ⇒ Object

Get a list of users that have voted for a poll answer. https://discord.com/developers/docs/resources/poll#get-answer-voters



691
692
693
694
695
696
697
698
699
700
701
# File 'lib/discordrb/api/channel.rb', line 691

def get_poll_voters(token, channel_id, message_id, answer_id, limit: 100, after: nil)
  query = URI.encode_www_form({ limit:, after: }.compact)

  Discordrb::API.request(
    :channels_cid_polls_mid_answers_aid,
    channel_id,
    :get,
    "#{Discordrb::API.api_base}/channels/#{channel_id}/polls/#{message_id}/answers/#{answer_id}?#{query}",
    Authorization: token
  )
end

.get_reactions(token, channel_id, message_id, emoji, before_id, after_id, limit = 100, type = 0) ⇒ Object

Get a list of clients who reacted with a specific reaction on a message https://discord.com/developers/docs/resources/channel#get-reactions



237
238
239
240
241
242
243
244
245
246
247
# File 'lib/discordrb/api/channel.rb', line 237

def get_reactions(token, channel_id, message_id, emoji, before_id, after_id, limit = 100, type = 0)
  emoji = URI.encode_www_form_component(emoji) unless emoji.ascii_only?
  query_string = URI.encode_www_form({ limit: limit || 100, before: before_id, after: after_id, type: type }.compact)
  Discordrb::API.request(
    :channels_cid_messages_mid_reactions_emoji,
    channel_id,
    :get,
    "#{Discordrb::API.api_base}/channels/#{channel_id}/messages/#{message_id}/reactions/#{emoji}?#{query_string}",
    Authorization: token
  )
end

.invites(token, channel_id) ⇒ Object



292
293
294
295
296
297
298
299
300
# File 'lib/discordrb/api/channel.rb', line 292

def invites(token, channel_id)
  Discordrb::API.request(
    :channels_cid_invites,
    channel_id,
    :get,
    "#{Discordrb::API.api_base}/channels/#{channel_id}/invites",
    Authorization: token
  )
end

.join_thread(token, channel_id) ⇒ Object



534
535
536
537
538
539
540
541
542
543
# File 'lib/discordrb/api/channel.rb', line 534

def join_thread(token, channel_id)
  Discordrb::API.request(
    :channels_cid_thread_members_me,
    channel_id,
    :put,
    "#{Discordrb::API.api_base}/channels/#{channel_id}/thread-members/@me",
    nil,
    Authorization: token
  )
end

.leave_group(token, group_channel_id) ⇒ Object

Deprecated.

Discord no longer supports bots in group DMs, this endpoint was repurposed and no longer works as implemented here.

Leave a group channel. https://discord.com/developers/docs/resources/channel#deleteclose-channel



451
452
453
454
455
456
457
458
459
460
# File 'lib/discordrb/api/channel.rb', line 451

def leave_group(token, group_channel_id)
  Discordrb::API.request(
    :channels_cid,
    nil,
    :delete,
    "#{Discordrb::API.api_base}/channels/#{group_channel_id}",
    Authorization: token,
    content_type: :json
  )
end

.leave_thread(token, channel_id) ⇒ Object



560
561
562
563
564
565
566
567
568
# File 'lib/discordrb/api/channel.rb', line 560

def leave_thread(token, channel_id)
  Discordrb::API.request(
    :channels_cid_thread_members_me,
    channel_id,
    :delete,
    "#{Discordrb::API.api_base}/channels/#{channel_id}/thread-members/#{user_id}",
    Authorization: token
  )
end

.list_active_threads(token, channel_id) ⇒ Object



612
613
614
615
616
617
618
619
620
# File 'lib/discordrb/api/channel.rb', line 612

def list_active_threads(token, channel_id)
  Discordrb::API.request(
    :channels_cid_threads_active,
    channel_id,
    :get,
    "#{Discordrb::API.api_base}/channels/#{channel_id}/threads/active",
    Authorization: token
  )
end

.list_joined_private_archived_threads(token, channel_id, before = nil, limit = nil) ⇒ Object



652
653
654
655
656
657
658
659
660
661
662
# File 'lib/discordrb/api/channel.rb', line 652

def list_joined_private_archived_threads(token, channel_id, before = nil, limit = nil)
  query = URI.encode_www_form({ before: before, limit: limit }.compact)

  Discordrb::API.request(
    :channels_cid_users_me_threads_archived_private,
    channel_id,
    :get,
    "#{Discordrb::API.api_base}/channels/#{channel_id}/users/@me/threads/archived/private?#{query}",
    Authorization: token
  )
end

.list_private_archived_threads(token, channel_id, before = nil, limit = nil) ⇒ Object



638
639
640
641
642
643
644
645
646
647
648
# File 'lib/discordrb/api/channel.rb', line 638

def list_private_archived_threads(token, channel_id, before = nil, limit = nil)
  query = URI.encode_www_form({ before: before, limit: limit }.compact)

  Discordrb::API.request(
    :channels_cid_threads_archived_private,
    channel_id,
    :get,
    "#{Discordrb::API.api_base}/channels/#{channel_id}/threads/archived/private?#{query}",
    Authorization: token
  )
end

.list_public_archived_threads(token, channel_id, before = nil, limit = nil) ⇒ Object



624
625
626
627
628
629
630
631
632
633
634
# File 'lib/discordrb/api/channel.rb', line 624

def list_public_archived_threads(token, channel_id, before = nil, limit = nil)
  query = URI.encode_www_form({ before: before, limit: limit }.compact)

  Discordrb::API.request(
    :channels_cid_threads_archived_public,
    channel_id,
    :get,
    "#{Discordrb::API.api_base}/channels/#{channel_id}/threads/archived/public?#{query}",
    Authorization: token
  )
end

.list_thread_members(token, channel_id, before, limit) ⇒ Object



584
585
586
587
588
589
590
591
592
593
594
# File 'lib/discordrb/api/channel.rb', line 584

def list_thread_members(token, channel_id, before, limit)
  query = URI.encode_www_form({ before: before, limit: limit }.compact)

  Discordrb::API.request(
    :channels_cid_thread_members,
    channel_id,
    :get,
    "#{Discordrb::API.api_base}/channels/#{channel_id}/thread-members?#{query}",
    Authorization: token
  )
end

.list_thread_members!(token, channel_id, after = nil, limit = 100, with_member = false) ⇒ Object



598
599
600
601
602
603
604
605
606
607
608
# File 'lib/discordrb/api/channel.rb', line 598

def list_thread_members!(token, channel_id, after = nil, limit = 100, with_member = false)
  query = URI.encode_www_form({ after: after, limit: limit, with_member: with_member }.compact)

  Discordrb::API.request(
    :channels_cid_thread_members,
    channel_id,
    :get,
    "#{Discordrb::API.api_base}/channels/#{channel_id}/thread-members?#{query}",
    Authorization: token
  )
end

.message(token, channel_id, message_id) ⇒ Object

Get a single message from a channel's history by id https://discord.com/developers/docs/resources/channel#get-channel-message



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

def message(token, channel_id, message_id)
  Discordrb::API.request(
    :channels_cid_messages_mid,
    channel_id,
    :get,
    "#{Discordrb::API.api_base}/channels/#{channel_id}/messages/#{message_id}",
    Authorization: token
  )
end

.messages(token, channel_id, amount, before = nil, after = nil, around = nil) ⇒ Object



66
67
68
# File 'lib/discordrb/api/channel.rb', line 66

def messages(token, channel_id, amount, before = nil, after = nil, around = nil)
  get_channel_messages(token, channel_id, limit: amount, after:, before:, around:)
end

.pin_message(token, channel_id, message_id, reason = nil) ⇒ Object



358
359
360
361
362
363
364
365
366
367
368
# File 'lib/discordrb/api/channel.rb', line 358

def pin_message(token, channel_id, message_id, reason = nil)
  Discordrb::API.request(
    :channels_cid_pins_mid,
    channel_id,
    :put,
    "#{Discordrb::API.api_base}/channels/#{channel_id}/messages/pins/#{message_id}",
    nil,
    Authorization: token,
    'X-Audit-Log-Reason': reason
  )
end

.pinned_messages(token, channel_id, limit = 50, before = nil) ⇒ Object



345
346
347
348
349
350
351
352
353
354
# File 'lib/discordrb/api/channel.rb', line 345

def pinned_messages(token, channel_id, limit = 50, before = nil)
  query = URI.encode_www_form({ limit: limit, before: before }.compact)
  Discordrb::API.request(
    :channels_cid_pins,
    channel_id,
    :get,
    "#{Discordrb::API.api_base}/channels/#{channel_id}/messages/pins?#{query}",
    Authorization: token
  )
end

.remove_group_user(token, group_channel_id, user_id) ⇒ Object

Deprecated.

Discord no longer supports bots in group DMs, this endpoint was repurposed and no longer works as implemented here.

Remove a user from a group channel. https://discord.com/developers/docs/resources/channel#group-dm-remove-recipient



437
438
439
440
441
442
443
444
445
446
# File 'lib/discordrb/api/channel.rb', line 437

def remove_group_user(token, group_channel_id, user_id)
  Discordrb::API.request(
    :channels_cid_recipients_uid,
    nil,
    :delete,
    "#{Discordrb::API.api_base}/channels/#{group_channel_id}/recipients/#{user_id}",
    Authorization: token,
    content_type: :json
  )
end

.remove_thread_member(token, channel_id, user_id) ⇒ Object



572
573
574
575
576
577
578
579
580
# File 'lib/discordrb/api/channel.rb', line 572

def remove_thread_member(token, channel_id, user_id)
  Discordrb::API.request(
    :channels_cid_thread_members_uid,
    channel_id,
    :delete,
    "#{Discordrb::API.api_base}/channels/#{channel_id}/thread-members/#{user_id}",
    Authorization: token
  )
end

.resolve(token, channel_id) ⇒ Object



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

def resolve(token, channel_id)
  Discordrb::API.request(
    :channels_cid,
    channel_id,
    :get,
    "#{Discordrb::API.api_base}/channels/#{channel_id}",
    Authorization: token
  )
end

.start_thread_in_forum_or_media_channel(token, channel_id, name, message, attachments = nil, rate_limit_per_user = nil, auto_archive_duration = nil, applied_tags = nil, reason = nil) ⇒ Object



666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
# File 'lib/discordrb/api/channel.rb', line 666

def start_thread_in_forum_or_media_channel(token, channel_id, name, message, attachments = nil, rate_limit_per_user = nil, auto_archive_duration = nil, applied_tags = nil, reason = nil)
  body = { name: name, message: message, rate_limit_per_user: rate_limit_per_user, auto_archive_duration: auto_archive_duration, applied_tags: applied_tags }.compact

  body = if attachments
           files = [*0...attachments.size].zip(attachments).to_h
           { **files, payload_json: body.to_json }
         else
           body.to_json
         end

  headers = { Authorization: token, 'X-Audit-Log-Reason': reason }
  headers[:content_type] = :json unless attachments

  Discordrb::API.request(
    :channels_cid_threads,
    channel_id,
    :post,
    "#{Discordrb::API.api_base}/channels/#{channel_id}/threads",
    body,
    headers
  )
end

.start_thread_with_message(token, channel_id, message_id, name, auto_archive_duration) ⇒ Object



506
507
508
509
510
511
512
513
514
515
516
# File 'lib/discordrb/api/channel.rb', line 506

def start_thread_with_message(token, channel_id, message_id, name, auto_archive_duration)
  Discordrb::API.request(
    :channels_cid_messages_mid_threads,
    channel_id,
    :post,
    "#{Discordrb::API.api_base}/channels/#{channel_id}/messages/#{message_id}/threads",
    { name: name, auto_archive_duration: auto_archive_duration }.to_json,
    Authorization: token,
    content_type: :json
  )
end

.start_thread_without_message(token, channel_id, name, auto_archive_duration, type = 11) ⇒ Object



520
521
522
523
524
525
526
527
528
529
530
# File 'lib/discordrb/api/channel.rb', line 520

def start_thread_without_message(token, channel_id, name, auto_archive_duration, type = 11)
  Discordrb::API.request(
    :channels_cid_threads,
    channel_id,
    :post,
    "#{Discordrb::API.api_base}/channels/#{channel_id}/threads",
    { name: name, auto_archive_duration: auto_archive_duration, type: type },
    Authorization: token,
    content_type: :json
  )
end

.start_typing(token, channel_id) ⇒ Object

Start typing (needs to be resent every 5 seconds to keep up the typing) https://discord.com/developers/docs/resources/channel#trigger-typing-indicator



332
333
334
335
336
337
338
339
340
341
# File 'lib/discordrb/api/channel.rb', line 332

def start_typing(token, channel_id)
  Discordrb::API.request(
    :channels_cid_typing,
    channel_id,
    :post,
    "#{Discordrb::API.api_base}/channels/#{channel_id}/typing",
    nil,
    Authorization: token
  )
end

.unpin_message(token, channel_id, message_id, reason = nil) ⇒ Object



372
373
374
375
376
377
378
379
380
381
# File 'lib/discordrb/api/channel.rb', line 372

def unpin_message(token, channel_id, message_id, reason = nil)
  Discordrb::API.request(
    :channels_cid_pins_mid,
    channel_id,
    :delete,
    "#{Discordrb::API.api_base}/channels/#{channel_id}/messages/pins/#{message_id}",
    Authorization: token,
    'X-Audit-Log-Reason': reason
  )
end

.update(token, channel_id, name, topic, position, bitrate, user_limit, nsfw, permission_overwrites = nil, parent_id = nil, rate_limit_per_user = nil, reason = nil, archived = nil, auto_archive_duration = nil, locked = nil, invitable = nil, flags = nil, applied_tags = nil) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/discordrb/api/channel.rb', line 21

def update(token, channel_id, name, topic, position, bitrate, user_limit, nsfw, permission_overwrites = nil, parent_id = nil, rate_limit_per_user = nil, reason = nil, archived = nil, auto_archive_duration = nil, locked = nil, invitable = nil, flags = nil, applied_tags = nil)
  data = { name: name, position: position, topic: topic, bitrate: bitrate, user_limit: user_limit, nsfw: nsfw, parent_id: parent_id, rate_limit_per_user: rate_limit_per_user, archived: archived, auto_archive_duration: auto_archive_duration, locked: locked, invitable: invitable, flags: flags, applied_tags: applied_tags }
  data[:permission_overwrites] = permission_overwrites unless permission_overwrites.nil?
  Discordrb::API.request(
    :channels_cid,
    channel_id,
    :patch,
    "#{Discordrb::API.api_base}/channels/#{channel_id}",
    data.to_json,
    Authorization: token,
    content_type: :json,
    'X-Audit-Log-Reason': reason
  )
end

.update!(token, channel_id, name: :undef, type: :undef, position: :undef, topic: :undef, nsfw: :undef, rate_limit_per_user: :undef, bitrate: :undef, user_limit: :undef, permission_overwrites: :undef, parent_id: :undef, rtc_region: :undef, video_quality_mode: :undef, default_auto_archive_duration: :undef, flags: :undef, available_tags: :undef, default_reaction_emoji: :undef, default_thread_rate_limit_per_user: :undef, default_sort_order: :undef, default_forum_layout: :undef, archived: :undef, auto_archive_duration: :undef, locked: :undef, invitable: :undef, applied_tags: :undef, reason: nil) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/discordrb/api/channel.rb', line 38

def update!(token, channel_id, name: :undef, type: :undef, position: :undef, topic: :undef, nsfw: :undef, rate_limit_per_user: :undef, bitrate: :undef, user_limit: :undef, permission_overwrites: :undef, parent_id: :undef, rtc_region: :undef, video_quality_mode: :undef, default_auto_archive_duration: :undef, flags: :undef, available_tags: :undef, default_reaction_emoji: :undef, default_thread_rate_limit_per_user: :undef, default_sort_order: :undef, default_forum_layout: :undef, archived: :undef, auto_archive_duration: :undef, locked: :undef, invitable: :undef, applied_tags: :undef, reason: nil)
  Discordrb::API.request(
    :channels_cid,
    channel_id,
    :patch,
    "#{Discordrb::API.api_base}/channels/#{channel_id}",
    { name:, type:, position:, topic:, nsfw:, rate_limit_per_user:, bitrate:, user_limit:, permission_overwrites:, parent_id:, rtc_region:, video_quality_mode:, default_auto_archive_duration:, flags:, available_tags:, default_reaction_emoji:, default_thread_rate_limit_per_user:, default_sort_order:, default_forum_layout:, archived:, auto_archive_duration:, locked:, invitable:, applied_tags: }.reject { |_, value| value == :undef }.to_json,
    Authorization: token,
    content_type: :json,
    'X-Audit-Log-Reason': reason
  )
end

.update_permission(token, channel_id, overwrite_id, allow, deny, type, reason = nil) ⇒ Object

Update a channels permission for a role or member https://discord.com/developers/docs/resources/channel#edit-channel-permissions



277
278
279
280
281
282
283
284
285
286
287
288
# File 'lib/discordrb/api/channel.rb', line 277

def update_permission(token, channel_id, overwrite_id, allow, deny, type, reason = nil)
  Discordrb::API.request(
    :channels_cid_permissions_oid,
    channel_id,
    :put,
    "#{Discordrb::API.api_base}/channels/#{channel_id}/permissions/#{overwrite_id}",
    { type: type, id: overwrite_id, allow: allow, deny: deny }.to_json,
    Authorization: token,
    content_type: :json,
    'X-Audit-Log-Reason': reason
  )
end

.upload_file(token, channel_id, file, caption: nil, tts: false) ⇒ Object



129
130
131
132
133
134
135
136
137
138
# File 'lib/discordrb/api/channel.rb', line 129

def upload_file(token, channel_id, file, caption: nil, tts: false)
  Discordrb::API.request(
    :channels_cid_messages_mid,
    channel_id,
    :post,
    "#{Discordrb::API.api_base}/channels/#{channel_id}/messages",
    { file: file, content: caption, tts: tts },
    Authorization: token
  )
end

.webhooks(token, channel_id) ⇒ Object



479
480
481
482
483
484
485
486
487
# File 'lib/discordrb/api/channel.rb', line 479

def webhooks(token, channel_id)
  Discordrb::API.request(
    :channels_cid_webhooks,
    channel_id,
    :get,
    "#{Discordrb::API.api_base}/channels/#{channel_id}/webhooks",
    Authorization: token
  )
end