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

Add a user to a group channel.



271
272
273
274
275
276
277
278
279
280
281
# File 'lib/discordrb/api/channel.rb', line 271

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

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



124
125
126
127
128
129
130
131
132
133
134
# File 'lib/discordrb/api/channel.rb', line 124

def bulk_delete_messages(token, channel_id, messages = [])
  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
  )
end

.create_empty_group(token, bot_user_id) ⇒ Object

Create an empty group channel.



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

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

Create a group channel.



252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
# File 'lib/discordrb/api/channel.rb', line 252

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) ⇒ Object

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



164
165
166
167
168
169
170
171
172
173
174
# File 'lib/discordrb/api/channel.rb', line 164

def create_invite(token, channel_id, max_age = 0, max_uses = 0, temporary = false)
  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 }.to_json,
    Authorization: token,
    content_type: :json
  )
end

.create_message(token, channel_id, message, mentions = [], tts = false, _server_id = nil) ⇒ Object



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

def create_message(token, channel_id, message, mentions = [], tts = false, _server_id = nil) # send message
  Discordrb::API.request(
    :channels_cid_messages_mid,
    channel_id,
    :post,
    "#{Discordrb::API.api_base}/channels/#{channel_id}/messages",
    { content: message, mentions: mentions, tts: tts }.to_json,
    Authorization: token,
    content_type: :json
  )
rescue RestClient::InternalServerError
  raise Discordrb::Errors::MessageTooLong, "Message over the character limit (#{message.length} > 2000)"
end

.delete(token, channel_id) ⇒ Object



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

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

.delete_message(token, channel_id, message_id) ⇒ Object



112
113
114
115
116
117
118
119
120
# File 'lib/discordrb/api/channel.rb', line 112

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

.delete_permission(token, channel_id, overwrite_id) ⇒ Object



178
179
180
181
182
183
184
185
186
# File 'lib/discordrb/api/channel.rb', line 178

def delete_permission(token, channel_id, overwrite_id)
  Discordrb::API.request(
    :channels_cid_permissions_oid,
    channel_id,
    :delete,
    "#{Discordrb::API.api_base}/channels/#{channel_id}/permissions/#{overwrite_id}",
    Authorization: token
  )
end

.edit_message(token, channel_id, message_id, message, mentions = []) ⇒ Object



98
99
100
101
102
103
104
105
106
107
108
# File 'lib/discordrb/api/channel.rb', line 98

def edit_message(token, channel_id, message_id, message, mentions = [])
  Discordrb::API.request(
    :channels_cid_messages_mid,
    channel_id,
    :patch,
    "#{Discordrb::API.api_base}/channels/#{channel_id}/messages/#{message_id}",
    { content: message, mentions: mentions }.to_json,
    Authorization: token,
    content_type: :json
  )
end

.invites(token, channel_id) ⇒ Object



152
153
154
155
156
157
158
159
160
# File 'lib/discordrb/api/channel.rb', line 152

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

.leave_group(token, group_channel_id) ⇒ Object

Leave a group channel.



296
297
298
299
300
301
302
303
304
305
# File 'lib/discordrb/api/channel.rb', line 296

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

.message(token, channel_id, message_id) ⇒ Object

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



57
58
59
60
61
62
63
64
65
# File 'lib/discordrb/api/channel.rb', line 57

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) ⇒ Object



45
46
47
48
49
50
51
52
53
# File 'lib/discordrb/api/channel.rb', line 45

def messages(token, channel_id, amount, before = nil, after = nil)
  Discordrb::API.request(
    :channels_cid_messages,
    channel_id,
    :get,
    "#{Discordrb::API.api_base}/channels/#{channel_id}/messages?limit=#{amount}#{"&before=#{before}" if before}#{"&after=#{after}" if after}",
    Authorization: token
  )
end

.pin_message(token, channel_id, message_id) ⇒ Object



215
216
217
218
219
220
221
222
223
224
# File 'lib/discordrb/api/channel.rb', line 215

def pin_message(token, channel_id, message_id)
  Discordrb::API.request(
    :channels_cid_pins_mid,
    channel_id,
    :put,
    "#{Discordrb::API.api_base}/channels/#{channel_id}/pins/#{message_id}",
    nil,
    Authorization: token
  )
end

.pinned_messages(token, channel_id) ⇒ Object



203
204
205
206
207
208
209
210
211
# File 'lib/discordrb/api/channel.rb', line 203

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

.remove_group_user(token, group_channel_id, user_id) ⇒ Object

Remove a user from a group channel.



284
285
286
287
288
289
290
291
292
293
# File 'lib/discordrb/api/channel.rb', line 284

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

.resolve(token, channel_id) ⇒ Object



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

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

.start_typing(token, channel_id) ⇒ Object

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



190
191
192
193
194
195
196
197
198
199
# File 'lib/discordrb/api/channel.rb', line 190

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) ⇒ Object



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

def unpin_message(token, channel_id, message_id)
  Discordrb::API.request(
    :channels_cid_pins_mid,
    channel_id,
    :delete,
    "#{Discordrb::API.api_base}/channels/#{channel_id}/pins/#{message_id}",
    Authorization: token
  )
end

.update(token, channel_id, name, topic, position, bitrate, user_limit) ⇒ Object



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

def update(token, channel_id, name, topic, position, bitrate, user_limit)
  Discordrb::API.request(
    :channels_cid,
    channel_id,
    :patch,
    "#{Discordrb::API.api_base}/channels/#{channel_id}",
    { name: name, position: position, topic: topic, bitrate: bitrate, user_limit: user_limit }.to_json,
    Authorization: token,
    content_type: :json
  )
end

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



138
139
140
141
142
143
144
145
146
147
148
# File 'lib/discordrb/api/channel.rb', line 138

def update_permission(token, channel_id, overwrite_id, allow, deny, type)
  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
  )
end

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



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

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