Module: Vox::HTTP::Routes::Channel
- Defined in:
- lib/vox/http/routes/channel.rb
Overview
Mixin for /channel/ routes.
Constant Summary collapse
- TYPES =
Channel types.
{ GUILD_TEXT: 0, DM: 1, GUILD_VOICE: 2, GROUP_DM: 3, GUILD_CATEGORY: 4, GUILD_NEWS: 5, GUILD_STORE: 6 }.freeze
Instance Method Summary collapse
-
#add_pinned_channel_message(channel_id, message_id, reason: nil) ⇒ Object
Add a message to a channel’s pins.
-
#bulk_delete_messages(channel_id, messages, reason: nil) ⇒ Object
Delete multiple message in a single request.
-
#create_channel_invite(channel_id, max_age: :undef, max_uses: :undef, temporary: :undef, unique: :undef, target_user: :undef, target_user_type: :undef, reason: nil) ⇒ Hash<Symbol, Object>
Create a new invite for a channel.
-
#create_message(channel_id, content: :undef, nonce: :undef, tts: :undef, file: :undef, embed: :undef, allowed_mentions: :undef, attachments: :undef) ⇒ Hash<Symbol, Object>
Create a message in a channel.
-
#create_reaction(channel_id, message_id, emoji) ⇒ Object
Create a reaction on a message.
-
#delete_all_reactions(channel_id, message_id) ⇒ Object
Delete all reactions on a message.
-
#delete_all_reactions_for_emoji(channel_id, message_id, emoji) ⇒ Object
Delete all reactions of a specific emoji on a message.
-
#delete_channel(channel_id, reason: nil) ⇒ Hash<Symbol, Object>
Delete a channel by ID, or close a private message.
-
#delete_channel_permission(channel_id, overwrite_id, reason: nil) ⇒ Object
Delete a channel permission overwrite for a user or role in a channel.
-
#delete_message(channel_id, message_id, reason: nil) ⇒ Object
Delete a previously sent message.
-
#delete_own_reaction(channel_id, message_id, emoji) ⇒ Object
Delete a reaction from the current user on a message.
-
#delete_pinned_channel_message(channel_id, message_id, reason: nil) ⇒ Object
Remove a message from a channel’s pins.
-
#delete_user_reaction(channel_id, message_id, emoji, user_id) ⇒ Object
Delete a reaction from a user on a message.
-
#edit_channel_permissions(channel_id, overwrite_id, allow:, deny:, type:, reason: nil) ⇒ Object
Edit the channel permission overwrites for a user or role in a channel.
-
#edit_message(channel_id, message_id, content: :undef, embed: :undef, flags: :undef) ⇒ Object
Edit a previously sent message.
-
#get_channel(channel_id) ⇒ Hash<Symbol, Object>
Get a channel by ID.
-
#get_channel_invites(channel_id) ⇒ Array<Hash<Symbol, Object>>
Get a list of invites (with invite metadata) for a channel.
-
#get_channel_message(channel_id, message_id) ⇒ Hash<Symbol, Object>
Get a specific message from a channel by ID.
-
#get_channel_messages(channel_id, around: :undef, before: :undef, after: :undef, limit: :undef) ⇒ Array<Hash<Symbol, Object>>
Get messages from a channel, by channel ID.
-
#get_pinned_messages(channel_id) ⇒ Array<Hash<Symbol, Object>>
Get all pinned messages in a channel.
-
#get_reactions(channel_id, message_id, emoji, before: :undef, after: :undef, limit: :undef) ⇒ Object
Get a list of users that have reacted with a specific emoji.
-
#group_dm_add_recipient(channel_id, user_id, access_token:, nick: :undef) ⇒ Object
Add a recipient to a group DM using their access token.
-
#group_dm_remove_recipient(channel_id, user_id) ⇒ Object
Remove a recipient from a group DM.
-
#modify_channel(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, reason: nil) ⇒ Hash<Symbol, Object>
Update a channel’s settings.
-
#trigger_typing_indicator(channel_id) ⇒ Object
Post a typing indicator for a channel.
Instance Method Details
#add_pinned_channel_message(channel_id, message_id, reason: nil) ⇒ Object
Add a message to a channel’s pins.
381 382 383 384 385 |
# File 'lib/vox/http/routes/channel.rb', line 381 def (channel_id, , reason: nil) route = Route.new(:POST, '/channels/%{channel_id}/pins/%{message_id}', channel_id: channel_id, message_id: ) request(route, reason: reason) end |
#bulk_delete_messages(channel_id, messages, reason: nil) ⇒ Object
The endpoint will not delete messages older than 2 weeks and will fail with Error::BadRequest if any message provided is older than that, or a duplicate within the list of message IDs.
Delete multiple message in a single request.
292 293 294 295 |
# File 'lib/vox/http/routes/channel.rb', line 292 def (channel_id, , reason: nil) route = Route.new(:POST, '/channels/%{channel_id}/messages/bulk-delete', channel_id: channel_id) request(route, json: { messages: }, reason: reason) end |
#create_channel_invite(channel_id, max_age: :undef, max_uses: :undef, temporary: :undef, unique: :undef, target_user: :undef, target_user_type: :undef, reason: nil) ⇒ Hash<Symbol, Object>
Create a new invite for a channel. All parameters aside from ‘channel_id` are optional.
337 338 339 340 341 342 343 |
# File 'lib/vox/http/routes/channel.rb', line 337 def create_channel_invite(channel_id, max_age: :undef, max_uses: :undef, temporary: :undef, unique: :undef, target_user: :undef, target_user_type: :undef, reason: nil) route = Route.new(:POST, '/channels/%{channel_id}/invites', channel_id: channel_id) json = filter_undef({ max_age: max_age, max_uses: max_uses, temporary: temporary, unique: unique, target_user: target_user, target_user_type: target_user_type }) request(route, json: json, reason: reason) end |
#create_message(channel_id, content: :undef, nonce: :undef, tts: :undef, file: :undef, embed: :undef, allowed_mentions: :undef, attachments: :undef) ⇒ Hash<Symbol, Object>
You must send one of ‘content`, `embed`, or `file`.
If ‘tts` is set to `true`, you also require the `SEND_TTS_MESSAGES` permission.
Create a message in a channel. All parameters other than ‘channel_id` are optional.
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/vox/http/routes/channel.rb', line 141 def (channel_id, content: :undef, nonce: :undef, tts: :undef, file: :undef, embed: :undef, allowed_mentions: :undef, attachments: :undef) route = Route.new(:POST, '/channels/%{channel_id}/messages', channel_id: channel_id) json = filter_undef({ content: content, nonce: nonce, tts: tts, embed: , allowed_mentions: allowed_mentions }) if file != :undef data = { file: file, payload_json: MultiJson.dump(json) } request(route, data: data) elsif != :undef = .collect { |k, v| UploadIO.new(v.io, v.content_type, k) } if .is_a? Hash attach_hash = Array(0....size).zip().to_h data = attach_hash.merge({ payload_json: MultiJson.dump(json) }) request(route, data: data) else request(route, json: json) end end |
#create_reaction(channel_id, message_id, emoji) ⇒ Object
Requires ‘READ_MESSAGE_HISTORY`, and `ADD_REACTIONS` if no other user has reacted with the emoji.
If your emoji is in the wrong format you will receive error code ‘10014: Unknown Emoji`
If the emoji name is unknown, you can provide any alphanumeric value as a placeholder.
Create a reaction on a message.
170 171 172 173 174 175 |
# File 'lib/vox/http/routes/channel.rb', line 170 def create_reaction(channel_id, , emoji) escaped_emoji = URI.encode_www_form_component(emoji) route = Route.new(:PUT, '/channels/%{channel_id}/messages/%{message_id}/reactions/%{emoji}/@me', channel_id: channel_id, message_id: , emoji: escaped_emoji) request(route) end |
#delete_all_reactions(channel_id, message_id) ⇒ Object
Delete all reactions on a message.
231 232 233 234 235 |
# File 'lib/vox/http/routes/channel.rb', line 231 def delete_all_reactions(channel_id, ) route = Route.new(:DELETE, '/channels/%{channel_id}/messages/%{message_id}/reactions', channel_id: channel_id, message_id: ) request(route) end |
#delete_all_reactions_for_emoji(channel_id, message_id, emoji) ⇒ Object
If your emoji is in the wrong format you will receive error code ‘10014: Unknown Emoji`
If the emoji name is unknown, you can provide any alphanumeric value as a placeholder.
Delete all reactions of a specific emoji on a message.
245 246 247 248 249 250 |
# File 'lib/vox/http/routes/channel.rb', line 245 def delete_all_reactions_for_emoji(channel_id, , emoji) escaped_emoji = URI.encode_www_form_component(emoji) route = Route.new(:DELETE, '/channels/%{channel_id}/messages/%{message_id}/reactions/%{emoji}', channel_id: channel_id, message_id: , emoji: escaped_emoji) request(route) end |
#delete_channel(channel_id, reason: nil) ⇒ Hash<Symbol, Object>
Fires a channel delete event.
Deleting a category will not delete its children, each child will have its ‘parent_id` field removed and a channel update will be fired for each of them.
Delete a channel by ID, or close a private message.
84 85 86 87 |
# File 'lib/vox/http/routes/channel.rb', line 84 def delete_channel(channel_id, reason: nil) route = Route.new(:DELETE, '/channels/%{channel_id}', channel_id: channel_id) request(route, reason: reason) end |
#delete_channel_permission(channel_id, overwrite_id, reason: nil) ⇒ Object
Only usable within guild channels.
Delete a channel permission overwrite for a user or role in a channel.
352 353 354 355 356 |
# File 'lib/vox/http/routes/channel.rb', line 352 def (channel_id, overwrite_id, reason: nil) route = Route.new(:DELETE, '/channels/%{channel_id}/permissions/%{overwrite_id}', channel_id: channel_id, overwrite_id: overwrite_id) request(route, reason: reason) end |
#delete_message(channel_id, message_id, reason: nil) ⇒ Object
Delete a previously sent message.
278 279 280 281 282 |
# File 'lib/vox/http/routes/channel.rb', line 278 def (channel_id, , reason: nil) route = Route.new(:DELETE, '/channels/%{channel_id}/messages/%{message_id}', channel_id: channel_id, message_id: ) request(route, reason: reason) end |
#delete_own_reaction(channel_id, message_id, emoji) ⇒ Object
If your emoji is in the wrong format you will receive error code ‘10014: Unknown Emoji`
If the emoji name is unknown, you can provide any alphanumeric value as a placeholder.
Delete a reaction from the current user on a message.
184 185 186 187 188 189 |
# File 'lib/vox/http/routes/channel.rb', line 184 def delete_own_reaction(channel_id, , emoji) escaped_emoji = URI.encode_www_form_component(emoji) route = Route.new(:DELETE, '/channels/%{channel_id}/messages/%{message_id}/reactions/%{emoji}/@me', channel_id: channel_id, message_id: , emoji: escaped_emoji) request(route) end |
#delete_pinned_channel_message(channel_id, message_id, reason: nil) ⇒ Object
Remove a message from a channel’s pins.
393 394 395 396 397 |
# File 'lib/vox/http/routes/channel.rb', line 393 def (channel_id, , reason: nil) route = Route.new(:DELETE, '/channels/%{channel_id}/pins/%{message_id}', channel_id: channel_id, message_id: ) request(route, reason: reason) end |
#delete_user_reaction(channel_id, message_id, emoji, user_id) ⇒ Object
If your emoji is in the wrong format you will receive error code ‘10014: Unknown Emoji`
If the emoji name is unknown, you can provide any alphanumeric value as a placeholder.
Delete a reaction from a user on a message.
201 202 203 204 205 206 |
# File 'lib/vox/http/routes/channel.rb', line 201 def delete_user_reaction(channel_id, , emoji, user_id) escaped_emoji = URI.encode_www_form_component(emoji) route = Route.new(:DELETE, '/channels/%{channel_id}/messages/%{message_id}/reactions/%{emoji}/%{user_id}', channel_id: channel_id, message_id: , emoji: escaped_emoji, user_id: user_id) request(route) end |
#edit_channel_permissions(channel_id, overwrite_id, allow:, deny:, type:, reason: nil) ⇒ Object
Only usable for guild channels.
Edit the channel permission overwrites for a user or role in a channel.
306 307 308 309 310 311 |
# File 'lib/vox/http/routes/channel.rb', line 306 def (channel_id, overwrite_id, allow:, deny:, type:, reason: nil) route = Route.new(:PUT, '/channels/%{channel_id}/permissions/%{overwrite_id}', channel_id: channel_id, overwrite_id: overwrite_id) json = { allow: allow, deny: deny, type: type } request(route, json: json, reason: reason) end |
#edit_message(channel_id, message_id, content: :undef, embed: :undef, flags: :undef) ⇒ Object
You can only edit the flags of a message not sent by the current user, and only if the current user has ‘MANAGE_MESSAGES` permissions.
Edit a previously sent message. All parameters other than ‘channel_id` and `message_id` are optional and nullable.
265 266 267 268 269 270 |
# File 'lib/vox/http/routes/channel.rb', line 265 def (channel_id, , content: :undef, embed: :undef, flags: :undef) route = Route.new(:PATCH, '/channels/%{channel_id}/messages/%{message_id}', channel_id: channel_id, message_id: ) json = filter_undef({ content: content, embed: , flags: flags }) request(route, json: json) end |
#get_channel(channel_id) ⇒ Hash<Symbol, Object>
Get a channel by ID.
29 30 31 |
# File 'lib/vox/http/routes/channel.rb', line 29 def get_channel(channel_id) request(Route.new(:GET, '/channels/%{channel_id}', channel_id: channel_id)) end |
#get_channel_invites(channel_id) ⇒ Array<Hash<Symbol, Object>>
Get a list of invites (with invite metadata) for a channel.
319 320 321 322 |
# File 'lib/vox/http/routes/channel.rb', line 319 def get_channel_invites(channel_id) route = Route.new(:GET, '/channels/%{channel_id}/invites', channel_id: channel_id) request(route) end |
#get_channel_message(channel_id, message_id) ⇒ Hash<Symbol, Object>
In guild channels the ‘READ_MESSAGE_HISTORY` permission is requred.
Get a specific message from a channel by ID.
117 118 119 120 121 |
# File 'lib/vox/http/routes/channel.rb', line 117 def (channel_id, ) route = Route.new(:GET, '/channels/%{channel_id}/messages/%{message_id}', channel_id: channel_id, message_id: ) request(route) end |
#get_channel_messages(channel_id, around: :undef, before: :undef, after: :undef, limit: :undef) ⇒ Array<Hash<Symbol, Object>>
If you lack the ‘READ_MESSAGE_HISTORY` permission in the desired channel this will return no messages.
Get messages from a channel, by channel ID. All parameters other than ‘channel_id` are optional.
103 104 105 106 107 |
# File 'lib/vox/http/routes/channel.rb', line 103 def (channel_id, around: :undef, before: :undef, after: :undef, limit: :undef) route = Route.new(:GET, '/channels/%{channel_id}/messages', channel_id: channel_id) params = filter_undef({ around: around, before: before, after: after, limit: limit }) request(route, query: params) end |
#get_pinned_messages(channel_id) ⇒ Array<Hash<Symbol, Object>>
Get all pinned messages in a channel.
370 371 372 373 |
# File 'lib/vox/http/routes/channel.rb', line 370 def (channel_id) route = Route.new(:GET, '/channels/%{channel_id}/pins', channel_id: channel_id) request(route) end |
#get_reactions(channel_id, message_id, emoji, before: :undef, after: :undef, limit: :undef) ⇒ Object
If your emoji is in the wrong format you will receive error code ‘10014: Unknown Emoji`
If the emoji name is unknown, you can provide any alphanumeric value as a placeholder.
Get a list of users that have reacted with a specific emoji.
218 219 220 221 222 223 224 |
# File 'lib/vox/http/routes/channel.rb', line 218 def get_reactions(channel_id, , emoji, before: :undef, after: :undef, limit: :undef) escaped_emoji = URI.encode_www_form_component(emoji) params = filter_undef({ before: before, after: after, limit: limit }) route = Route.new(:GET, '/channels/%{channel_id}/messages/%{message_id}/reactions/%{emoji}', channel_id: channel_id, message_id: , emoji: escaped_emoji) request(route, query: params) end |
#group_dm_add_recipient(channel_id, user_id, access_token:, nick: :undef) ⇒ Object
Add a recipient to a group DM using their access token.
406 407 408 409 410 411 |
# File 'lib/vox/http/routes/channel.rb', line 406 def group_dm_add_recipient(channel_id, user_id, access_token:, nick: :undef) route = Route.new(:PUT, '/channels/%{channel_id}/recipients/%{user_id}', channel_id: channel_id, user_id: user_id) json = filter_undef({ access_token: access_token, nick: nick }) request(route, json: json) end |
#group_dm_remove_recipient(channel_id, user_id) ⇒ Object
Remove a recipient from a group DM.
417 418 419 420 421 |
# File 'lib/vox/http/routes/channel.rb', line 417 def group_dm_remove_recipient(channel_id, user_id) route = Route.new(:DELETE, '/channels/%{channel_id}/recipients/%{user_id}', channel_id: channel_id, user_id: user_id) request(route) end |
#modify_channel(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, reason: nil) ⇒ Hash<Symbol, Object>
Fires a channel update. In the event of modifying a category, individual channel updates will fire for each child that is also modified.
Update a channel’s settings. Parameters other than ‘channel_id` are all optional.
59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/vox/http/routes/channel.rb', line 59 def modify_channel(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, reason: nil) json = filter_undef({ name: name, type: type, position: position, topic: topic, nsfw: nsfw, rate_limit_per_user: rate_limit_per_user, bitrate: bitrate, user_limit: user_limit, permission_overwrites: , parent_id: parent_id }) route = Route.new(:PATCH, '/channels/%{channel_id}', channel_id: channel_id) request(route, json: json, reason: reason) end |