Module: Discordrb::API::Channel
- Defined in:
- lib/discordrb/api/channel.rb
Overview
API calls for Channel
Class Method Summary collapse
-
.add_group_user(token, group_channel_id, user_id) ⇒ Object
Add a user to a group channel.
-
.bulk_delete_messages(token, channel_id, messages = []) ⇒ Object
Delete messages in bulk https://discordapp.com/developers/docs/resources/channel#bulk-delete-messages.
-
.create_empty_group(token, bot_user_id) ⇒ Object
Create an empty group channel.
-
.create_group(token, pm_channel_id, user_id) ⇒ Object
Create a group channel.
-
.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://discordapp.com/developers/docs/resources/channel#create-channel-invite.
-
.create_message(token, channel_id, message, tts = false, embed = nil, nonce = nil) ⇒ Object
Send a message to a channel https://discordapp.com/developers/docs/resources/channel#create-message.
-
.create_reaction(token, channel_id, message_id, emoji) ⇒ Object
Create a reaction on a message using this client https://discordapp.com/developers/docs/resources/channel#create-reaction.
-
.create_webhook(token, channel_id, name, avatar = nil, reason = nil) ⇒ Object
Create a webhook https://discordapp.com/developers/docs/resources/webhook#create-webhook.
- .delete(token, channel_id, reason = nil) ⇒ Object
-
.delete_all_reactions(token, channel_id, message_id) ⇒ Object
Deletes all reactions on a message from all clients https://discordapp.com/developers/docs/resources/channel#delete-all-reactions.
-
.delete_message(token, channel_id, message_id) ⇒ Object
Delete a message https://discordapp.com/developers/docs/resources/channel#delete-message.
-
.delete_own_reaction(token, channel_id, message_id, emoji) ⇒ Object
Delete this client's own reaction on a message https://discordapp.com/developers/docs/resources/channel#delete-own-reaction.
-
.delete_permission(token, channel_id, overwrite_id, reason = nil) ⇒ Object
Delete channel permission https://discordapp.com/developers/docs/resources/channel#delete-channel-permission.
-
.delete_user_reaction(token, channel_id, message_id, emoji, user_id) ⇒ Object
Delete another client's reaction on a message https://discordapp.com/developers/docs/resources/channel#delete-user-reaction.
- .edit_message(token, channel_id, message_id, message, mentions = [], embed = nil) ⇒ Object
-
.get_reactions(token, channel_id, message_id, emoji) ⇒ Object
Get a list of clients who reacted with a specific reaction on a message https://discordapp.com/developers/docs/resources/channel#get-reactions.
-
.invites(token, channel_id) ⇒ Object
Get a channel's invite list https://discordapp.com/developers/docs/resources/channel#get-channel-invites.
-
.leave_group(token, group_channel_id) ⇒ Object
Leave a group channel.
-
.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.
-
.messages(token, channel_id, amount, before = nil, after = nil, around = nil) ⇒ Object
Get a list of messages from a channel's history https://discordapp.com/developers/docs/resources/channel#get-channel-messages.
- .pin_message(token, channel_id, message_id) ⇒ Object
-
.pinned_messages(token, channel_id) ⇒ Object
Get a list of pinned messages in a channel https://discordapp.com/developers/docs/resources/channel#get-pinned-messages.
-
.remove_group_user(token, group_channel_id, user_id) ⇒ Object
Remove a user from a group channel.
-
.resolve(token, channel_id) ⇒ Object
Get a channel's data https://discordapp.com/developers/docs/resources/channel#get-channel.
-
.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.
- .unpin_message(token, channel_id, message_id) ⇒ Object
-
.update(token, channel_id, name, topic, position, bitrate, user_limit, nsfw, permission_overwrites = nil, parent_id = nil, rate_limit_per_user = nil, reason = nil) ⇒ Object
Update a channel's data https://discordapp.com/developers/docs/resources/channel#modify-channel.
-
.update_permission(token, channel_id, overwrite_id, allow, deny, type, reason = nil) ⇒ Object
Update a channels permission for a role or member https://discordapp.com/developers/docs/resources/channel#edit-channel-permissions.
-
.upload_file(token, channel_id, file, caption: nil, tts: false) ⇒ Object
Send a file as a message to a channel https://discordapp.com/developers/docs/resources/channel#upload-file.
-
.webhooks(token, channel_id) ⇒ Object
Get channel webhooks https://discordapp.com/developers/docs/resources/webhook#get-channel-webhooks.
Class Method Details
.add_group_user(token, group_channel_id, user_id) ⇒ Object
Add a user to a group channel.
349 350 351 352 353 354 355 356 357 358 359 |
# File 'lib/discordrb/api/channel.rb', line 349 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
Delete messages in bulk https://discordapp.com/developers/docs/resources/channel#bulk-delete-messages
133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/discordrb/api/channel.rb', line 133 def (token, channel_id, = []) Discordrb::API.request( :channels_cid_messages_bulk_delete, channel_id, :post, "#{Discordrb::API.api_base}/channels/#{channel_id}/messages/bulk-delete", { messages: }.to_json, Authorization: token, content_type: :json ) end |
.create_empty_group(token, bot_user_id) ⇒ Object
Create an empty group channel.
317 318 319 320 321 322 323 324 325 326 327 |
# File 'lib/discordrb/api/channel.rb', line 317 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.
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 |
# File 'lib/discordrb/api/channel.rb', line 330 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://discordapp.com/developers/docs/resources/channel#create-channel-invite
240 241 242 243 244 245 246 247 248 249 250 251 |
# File 'lib/discordrb/api/channel.rb', line 240 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, embed = nil, nonce = nil) ⇒ Object
Send a message to a channel https://discordapp.com/developers/docs/resources/channel#create-message
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/discordrb/api/channel.rb', line 75 def (token, channel_id, , tts = false, = nil, nonce = nil) Discordrb::API.request( :channels_cid_messages_mid, channel_id, :post, "#{Discordrb::API.api_base}/channels/#{channel_id}/messages", { content: , tts: tts, embed: , nonce: nonce }.to_json, Authorization: token, content_type: :json ) rescue RestClient::BadRequest => e parsed = JSON.parse(e.response.body) raise Discordrb::Errors::MessageTooLong, "Message over the character limit (#{.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://discordapp.com/developers/docs/resources/channel#create-reaction
147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/discordrb/api/channel.rb', line 147 def create_reaction(token, channel_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/#{}/reactions/#{emoji}/@me", nil, Authorization: token, content_type: :json ) end |
.create_webhook(token, channel_id, name, avatar = nil, reason = nil) ⇒ Object
387 388 389 390 391 392 393 394 395 396 397 398 |
# File 'lib/discordrb/api/channel.rb', line 387 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 |
.delete(token, channel_id, reason = nil) ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/discordrb/api/channel.rb', line 38 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_reactions(token, channel_id, message_id) ⇒ Object
Deletes all reactions on a message from all clients https://discordapp.com/developers/docs/resources/channel#delete-all-reactions
201 202 203 204 205 206 207 208 209 |
# File 'lib/discordrb/api/channel.rb', line 201 def delete_all_reactions(token, channel_id, ) Discordrb::API.request( :channels_cid_messages_mid_reactions, channel_id, :delete, "#{Discordrb::API.api_base}/channels/#{channel_id}/messages/#{}/reactions", Authorization: token ) end |
.delete_message(token, channel_id, message_id) ⇒ Object
121 122 123 124 125 126 127 128 129 |
# File 'lib/discordrb/api/channel.rb', line 121 def (token, channel_id, ) Discordrb::API.request( :channels_cid_messages_mid, channel_id, :delete, "#{Discordrb::API.api_base}/channels/#{channel_id}/messages/#{}", Authorization: token ) end |
.delete_own_reaction(token, channel_id, message_id, emoji) ⇒ Object
Delete this client's own reaction on a message https://discordapp.com/developers/docs/resources/channel#delete-own-reaction
162 163 164 165 166 167 168 169 170 171 |
# File 'lib/discordrb/api/channel.rb', line 162 def delete_own_reaction(token, channel_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/#{}/reactions/#{emoji}/@me", Authorization: token ) end |
.delete_permission(token, channel_id, overwrite_id, reason = nil) ⇒ Object
Delete channel permission https://discordapp.com/developers/docs/resources/channel#delete-channel-permission
255 256 257 258 259 260 261 262 263 264 |
# File 'lib/discordrb/api/channel.rb', line 255 def (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
Delete another client's reaction on a message https://discordapp.com/developers/docs/resources/channel#delete-user-reaction
175 176 177 178 179 180 181 182 183 184 |
# File 'lib/discordrb/api/channel.rb', line 175 def delete_user_reaction(token, channel_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/#{}/reactions/#{emoji}/#{user_id}", Authorization: token ) end |
.edit_message(token, channel_id, message_id, message, mentions = [], embed = nil) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/discordrb/api/channel.rb', line 107 def (token, channel_id, , , mentions = [], = nil) Discordrb::API.request( :channels_cid_messages_mid, channel_id, :patch, "#{Discordrb::API.api_base}/channels/#{channel_id}/messages/#{}", { content: , mentions: mentions, embed: }.to_json, Authorization: token, content_type: :json ) end |
.get_reactions(token, channel_id, message_id, emoji) ⇒ Object
Get a list of clients who reacted with a specific reaction on a message https://discordapp.com/developers/docs/resources/channel#get-reactions
188 189 190 191 192 193 194 195 196 197 |
# File 'lib/discordrb/api/channel.rb', line 188 def get_reactions(token, channel_id, , emoji) emoji = URI.encode_www_form_component(emoji) unless emoji.ascii_only? Discordrb::API.request( :channels_cid_messages_mid_reactions_emoji, channel_id, :get, "#{Discordrb::API.api_base}/channels/#{channel_id}/messages/#{}/reactions/#{emoji}", Authorization: token ) end |
.invites(token, channel_id) ⇒ Object
Get a channel's invite list https://discordapp.com/developers/docs/resources/channel#get-channel-invites
228 229 230 231 232 233 234 235 236 |
# File 'lib/discordrb/api/channel.rb', line 228 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.
374 375 376 377 378 379 380 381 382 383 |
# File 'lib/discordrb/api/channel.rb', line 374 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
63 64 65 66 67 68 69 70 71 |
# File 'lib/discordrb/api/channel.rb', line 63 def (token, channel_id, ) Discordrb::API.request( :channels_cid_messages_mid, channel_id, :get, "#{Discordrb::API.api_base}/channels/#{channel_id}/messages/#{}", Authorization: token ) end |
.messages(token, channel_id, amount, before = nil, after = nil, around = nil) ⇒ Object
Get a list of messages from a channel's history https://discordapp.com/developers/docs/resources/channel#get-channel-messages
51 52 53 54 55 56 57 58 59 |
# File 'lib/discordrb/api/channel.rb', line 51 def (token, channel_id, amount, before = nil, after = nil, around = 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}#{"&around=#{around}" if around}", Authorization: token ) end |
.pin_message(token, channel_id, message_id) ⇒ Object
293 294 295 296 297 298 299 300 301 302 |
# File 'lib/discordrb/api/channel.rb', line 293 def (token, channel_id, ) Discordrb::API.request( :channels_cid_pins_mid, channel_id, :put, "#{Discordrb::API.api_base}/channels/#{channel_id}/pins/#{}", nil, Authorization: token ) end |
.pinned_messages(token, channel_id) ⇒ Object
Get a list of pinned messages in a channel https://discordapp.com/developers/docs/resources/channel#get-pinned-messages
281 282 283 284 285 286 287 288 289 |
# File 'lib/discordrb/api/channel.rb', line 281 def (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.
362 363 364 365 366 367 368 369 370 371 |
# File 'lib/discordrb/api/channel.rb', line 362 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
Get a channel's data https://discordapp.com/developers/docs/resources/channel#get-channel
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_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
268 269 270 271 272 273 274 275 276 277 |
# File 'lib/discordrb/api/channel.rb', line 268 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
306 307 308 309 310 311 312 313 314 |
# File 'lib/discordrb/api/channel.rb', line 306 def (token, channel_id, ) Discordrb::API.request( :channels_cid_pins_mid, channel_id, :delete, "#{Discordrb::API.api_base}/channels/#{channel_id}/pins/#{}", Authorization: token ) 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) ⇒ Object
Update a channel's data https://discordapp.com/developers/docs/resources/channel#modify-channel
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, = nil, parent_id = nil, rate_limit_per_user = nil, reason = 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 } data[:permission_overwrites] = unless .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_permission(token, channel_id, overwrite_id, allow, deny, type, reason = nil) ⇒ Object
Update a channels permission for a role or member https://discordapp.com/developers/docs/resources/channel#edit-channel-permissions
213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'lib/discordrb/api/channel.rb', line 213 def (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
Send a file as a message to a channel https://discordapp.com/developers/docs/resources/channel#upload-file
94 95 96 97 98 99 100 101 102 103 |
# File 'lib/discordrb/api/channel.rb', line 94 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: , tts: tts }, Authorization: token ) end |
.webhooks(token, channel_id) ⇒ Object
Get channel webhooks https://discordapp.com/developers/docs/resources/webhook#get-channel-webhooks
402 403 404 405 406 407 408 409 410 |
# File 'lib/discordrb/api/channel.rb', line 402 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 |