Class: Discorb::TextChannel
- Inherits:
-
GuildChannel
- Object
- DiscordModel
- Channel
- GuildChannel
- Discorb::TextChannel
- Includes:
- Messageable
- Defined in:
- lib/discorb/channel.rb
Overview
Represents a text channel.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#last_message_id -> Discorb::Snowflake
readonly
The id of the last message.
-
#last_pin_timestamp -> Time
(also: #last_pinned_at)
readonly
The time when the last pinned message was pinned.
-
#nsfw -> Boolean
readonly
Whether the channel is nsfw.
-
#rate_limit_per_user -> Integer
(also: #slowmode)
readonly
The rate limit per user (Slowmode) in the channel.
-
#threads -> Array<Discorb::ThreadChannel>
readonly
The threads in the channel.
-
#topic -> String
readonly
The topic of the channel.
Attributes inherited from GuildChannel
#permission_overwrites, #position
Attributes inherited from Channel
Instance Method Summary collapse
-
#create_invite(max_age: nil, max_uses: nil, temporary: false, unique: false, reason: nil) -> Async::Task<Invite>
Create an invite in the channel.
-
#create_webhook(name, avatar: nil) -> Async::Task<Discorb::Webhook::IncomingWebhook>
Create webhook in the channel.
-
#delete_messages!(*messages, force: false) -> Async::Task<void>
(also: #bulk_delete!, #destroy_messages!)
Bulk delete messages in the channel.
-
#delete_permissions(target, reason: nil) -> Async::Task<void>
(also: #delete_permission, #destroy_permissions, #destroy_permission)
Delete the channel's permission overwrite.
-
#edit(name: Discorb::Unset, position: Discorb::Unset, category: Discorb::Unset, parent: Discorb::Unset, topic: Discorb::Unset, nsfw: Discorb::Unset, announce: Discorb::Unset, rate_limit_per_user: Discorb::Unset, slowmode: Discorb::Unset, default_auto_archive_duration: Discorb::Unset, archive_in: Discorb::Unset, reason: nil) -> Async::Task<self>
(also: #modify)
Edits the channel.
-
#fetch_archived_private_threads -> Async::Task<Array<Discorb::ThreadChannel>>
Fetch archived private threads in the channel.
-
#fetch_archived_public_threads -> Async::Task<Array<Discorb::ThreadChannel>>
Fetch archived threads in the channel.
-
#fetch_invites -> Async::Task<Array<Discorb::Invite>>
Fetch the channel's invites.
-
#fetch_joined_archived_private_threads(limit: nil, before: nil) -> Async::Task<Array<Discorb::ThreadChannel>>
Fetch joined archived private threads in the channel.
-
#fetch_webhooks -> Async::Task<Array<Discorb::Webhook>>
Fetch webhooks in the channel.
-
#follow_from(target, reason: nil) -> Async::Task<void>
Follow the existing announcement channel.
-
#follow_to(target, reason: nil) -> Async::Task<void>
Follow the existing announcement channel from self.
-
#set_permissions(target, reason: nil, **perms) -> Async::Task<void>
(also: #modify_permissions, #modify_permisssion, #edit_permissions, #edit_permission)
Set the channel's permission overwrite.
-
#start_thread(name, message: nil, auto_archive_duration: 1440, public: true, rate_limit_per_user: nil, slowmode: nil, reason: nil) -> Async::Task<Discorb::ThreadChannel>
(also: #create_thread)
Start thread in the channel.
Methods included from Messageable
#delete_message!, #edit_message, #fetch_message, #fetch_messages, #fetch_pins, #pin_message, #post, #typing, #unpin_message
Methods inherited from GuildChannel
#<=>, #==, #delete!, #guild, #inspect, #mention, #move, #parent, #to_s
Methods inherited from Channel
Methods inherited from DiscordModel
Instance Attribute Details
#last_message_id -> Discorb::Snowflake (readonly)
Returns The id of the last message.
235 236 237 |
# File 'lib/discorb/channel.rb', line 235 def @last_message_id end |
#last_pin_timestamp -> Time (readonly) Also known as: last_pinned_at
Returns The time when the last pinned message was pinned.
240 241 242 |
# File 'lib/discorb/channel.rb', line 240 def @last_pin_timestamp end |
#nsfw -> Boolean (readonly)
Returns Whether the channel is nsfw.
233 234 235 |
# File 'lib/discorb/channel.rb', line 233 def nsfw @nsfw end |
#rate_limit_per_user -> Integer (readonly) Also known as: slowmode
Returns The rate limit per user (Slowmode) in the channel.
237 238 239 |
# File 'lib/discorb/channel.rb', line 237 def rate_limit_per_user @rate_limit_per_user end |
#threads -> Array<Discorb::ThreadChannel> (readonly)
Returns The threads in the channel.
243 244 245 |
# File 'lib/discorb/channel.rb', line 243 def threads @threads end |
#topic -> String (readonly)
Returns The topic of the channel.
231 232 233 |
# File 'lib/discorb/channel.rb', line 231 def topic @topic end |
Instance Method Details
#create_invite(max_age: nil, max_uses: nil, temporary: false, unique: false, reason: nil) -> Async::Task<Invite>
Create an invite in the channel.
441 442 443 444 445 446 447 448 449 450 451 |
# File 'lib/discorb/channel.rb', line 441 def create_invite(max_age: nil, max_uses: nil, temporary: false, unique: false, reason: nil) Async do _resp, data = @client.http.request(Route.new("/channels/#{@id}/invites", "//channels/:channel_id/invites", :post), { max_age: max_age, max_uses: max_uses, temporary: temporary, unique: unique, }, audit_log_reason: reason).wait Invite.new(@client, data) end end |
#create_webhook(name, avatar: nil) -> Async::Task<Discorb::Webhook::IncomingWebhook>
Create webhook in the channel.
311 312 313 314 315 316 317 318 319 |
# File 'lib/discorb/channel.rb', line 311 def create_webhook(name, avatar: nil) Async do payload = {} payload[:name] = name payload[:avatar] = avatar.to_s if avatar _resp, data = @client.http.request(Route.new("/channels/#{@id}/webhooks", "//channels/:channel_id/webhooks", :post), payload).wait Webhook.new([@client, data]) end end |
#delete_messages!(*messages, force: false) -> Async::Task<void> Also known as: bulk_delete!, destroy_messages!
Bulk delete messages in the channel.
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 |
# File 'lib/discorb/channel.rb', line 343 def (*, force: false) Async do = .first if .length == 1 && .first.is_a?(Array) unless force time = Time.now .delete_if do || next false unless .is_a?(Message) time - .created_at > 60 * 60 * 24 * 14 end end = .map { |m| Discorb::Utils.try(m, :id).to_s } @client.http.request(Route.new("/channels/#{@id}/messages/bulk-delete", "//channels/:channel_id/messages/bulk-delete", :post), { messages: }).wait end end |
#delete_permissions(target, reason: nil) -> Async::Task<void> Also known as: delete_permission, destroy_permissions, destroy_permission
Delete the channel's permission overwrite.
405 406 407 408 409 |
# File 'lib/discorb/channel.rb', line 405 def (target, reason: nil) Async do @client.http.request(Route.new("/channels/#{@id}/permissions/#{target.id}", "//channels/:channel_id/permissions/:target_id", :delete), audit_log_reason: reason).wait end end |
#edit(name: Discorb::Unset, position: Discorb::Unset, category: Discorb::Unset, parent: Discorb::Unset, topic: Discorb::Unset, nsfw: Discorb::Unset, announce: Discorb::Unset, rate_limit_per_user: Discorb::Unset, slowmode: Discorb::Unset, default_auto_archive_duration: Discorb::Unset, archive_in: Discorb::Unset, reason: nil) -> Async::Task<self> Also known as: modify
The arguments of this method are defaultly set to Discorb::Unset
. Specify value to set the value, if not don't specify or specify Discorb::Unset
.
Edits the channel.
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 |
# File 'lib/discorb/channel.rb', line 275 def edit(name: Discorb::Unset, position: Discorb::Unset, category: Discorb::Unset, parent: Discorb::Unset, topic: Discorb::Unset, nsfw: Discorb::Unset, announce: Discorb::Unset, rate_limit_per_user: Discorb::Unset, slowmode: Discorb::Unset, default_auto_archive_duration: Discorb::Unset, archive_in: Discorb::Unset, reason: nil) Async do payload = {} payload[:name] = name if name != Discorb::Unset payload[:announce] = announce ? 5 : 0 if announce != Discorb::Unset payload[:position] = position if position != Discorb::Unset payload[:topic] = topic || "" if topic != Discorb::Unset payload[:nsfw] = nsfw if nsfw != Discorb::Unset slowmode = rate_limit_per_user if slowmode == Discorb::Unset payload[:rate_limit_per_user] = slowmode || 0 if slowmode != Discorb::Unset parent = category if parent == Discorb::Unset payload[:parent_id] = parent&.id if parent != Discorb::Unset default_auto_archive_duration ||= archive_in payload[:default_auto_archive_duration] = default_auto_archive_duration if default_auto_archive_duration != Discorb::Unset @client.http.request(Route.new("/channels/#{@id}", "//channels/:channel_id", :patch), payload, audit_log_reason: reason).wait self end end |
#fetch_archived_private_threads -> Async::Task<Array<Discorb::ThreadChannel>>
Fetch archived private threads in the channel.
537 538 539 540 541 542 |
# File 'lib/discorb/channel.rb', line 537 def fetch_archived_private_threads Async do _resp, data = @client.http.request(Route.new("/channels/#{@id}/threads/archived/private", "//channels/:channel_id/threads/archived/private", :get)).wait data.map { |thread| Channel.make_channel(@client, thread) } end end |
#fetch_archived_public_threads -> Async::Task<Array<Discorb::ThreadChannel>>
Fetch archived threads in the channel.
524 525 526 527 528 529 |
# File 'lib/discorb/channel.rb', line 524 def fetch_archived_public_threads Async do _resp, data = @client.http.request(Route.new("/channels/#{@id}/threads/archived/public", "//channels/:channel_id/threads/archived/public", :get)).wait data.map { |thread| Channel.make_channel(@client, thread) } end end |
#fetch_invites -> Async::Task<Array<Discorb::Invite>>
Fetch the channel's invites.
421 422 423 424 425 426 |
# File 'lib/discorb/channel.rb', line 421 def fetch_invites Async do _resp, data = @client.http.request(Route.new("/channels/#{@id}/invites", "//channels/:channel_id/invites", :get)).wait data.map { |invite| Invite.new(@client, invite) } end end |
#fetch_joined_archived_private_threads(limit: nil, before: nil) -> Async::Task<Array<Discorb::ThreadChannel>>
Fetch joined archived private threads in the channel.
553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 |
# File 'lib/discorb/channel.rb', line 553 def fetch_joined_archived_private_threads(limit: nil, before: nil) Async do if limit.nil? before = 0 threads = [] loop do _resp, data = @client.http.request(Route.new("/channels/#{@id}/users/@me/threads/archived/private?before=#{before}", "//channels/:channel_id/users/@me/threads/archived/private", :get)).wait threads += data[:threads].map { |thread| Channel.make_channel(@client, thread) } before = data[:threads][-1][:id] break unless data[:has_more] end threads else _resp, data = @client.http.request(Route.new("/channels/#{@id}/users/@me/threads/archived/private?limit=#{limit}&before=#{before}", "//channels/:channel_id/users/@me/threads/archived/private", :get)).wait data.map { |thread| Channel.make_channel(@client, thread) } end end end |
#fetch_webhooks -> Async::Task<Array<Discorb::Webhook>>
Fetch webhooks in the channel.
327 328 329 330 331 332 |
# File 'lib/discorb/channel.rb', line 327 def fetch_webhooks Async do _resp, data = @client.http.request(Route.new("/channels/#{@id}/webhooks", "//channels/:channel_id/webhooks", :get)).wait data.map { |webhook| Webhook.new([@client, webhook]) } end end |
#follow_from(target, reason: nil) -> Async::Task<void>
Follow the existing announcement channel.
462 463 464 465 466 |
# File 'lib/discorb/channel.rb', line 462 def follow_from(target, reason: nil) Async do @client.http.request(Route.new("/channels/#{target.id}/followers", "//channels/:channel_id/followers", :post), { webhook_channel_id: @id }, audit_log_reason: reason).wait end end |
#follow_to(target, reason: nil) -> Async::Task<void>
Follow the existing announcement channel from self.
477 478 479 480 481 |
# File 'lib/discorb/channel.rb', line 477 def follow_to(target, reason: nil) Async do @client.http.request(Route.new("/channels/#{@id}/followers", "//channels/:channel_id/followers", :post), { webhook_channel_id: target.id }, audit_log_reason: reason).wait end end |
#set_permissions(target, reason: nil, **perms) -> Async::Task<void> Also known as: modify_permissions, modify_permisssion, edit_permissions, edit_permission
Set the channel's permission overwrite.
374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 |
# File 'lib/discorb/channel.rb', line 374 def (target, reason: nil, **perms) Async do allow_value = @permission_overwrites[target]&.allow_value.to_i deny_value = @permission_overwrites[target]&.deny_value.to_i perms.each do |perm, value| allow_value[Discorb::Permission.bits[perm]] = 1 if value == true deny_value[Discorb::Permission.bits[perm]] = 1 if value == false end payload = { allow: allow_value, deny: deny_value, type: target.is_a?(Member) ? 1 : 0, } @client.http.request(Route.new("/channels/#{@id}/permissions/#{target.id}", "//channels/:channel_id/permissions/:target_id", :put), payload, audit_log_reason: reason).wait end end |
#start_thread(name, message: nil, auto_archive_duration: 1440, public: true, rate_limit_per_user: nil, slowmode: nil, reason: nil) -> Async::Task<Discorb::ThreadChannel> Also known as: create_thread
Start thread in the channel.
497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 |
# File 'lib/discorb/channel.rb', line 497 def start_thread(name, message: nil, auto_archive_duration: 1440, public: true, rate_limit_per_user: nil, slowmode: nil, reason: nil) Async do _resp, data = if .nil? @client.http.request(Route.new("/channels/#{@id}/threads", "//channels/:channel_id/threads", :post), { name: name, auto_archive_duration: auto_archive_duration, type: public ? 11 : 10, rate_limit_per_user: rate_limit_per_user || slowmode, }, audit_log_reason: reason).wait else @client.http.request(Route.new("/channels/#{@id}/messages/#{Utils.try(, :id)}/threads", "//channels/:channel_id/messages/:message_id/threads", :post), { name: name, auto_archive_duration: auto_archive_duration, }, audit_log_reason: reason).wait end Channel.make_channel(@client, data) end end |