Class: Discordrb::Channel
- Inherits:
-
Object
- Object
- Discordrb::Channel
- Defined in:
- lib/discordrb/data.rb
Overview
A Discord channel, including data like the topic
Instance Attribute Summary collapse
-
#id ⇒ Integer
(also: #resolve_id)
readonly
The channel's unique ID.
-
#is_private ⇒ true, false
readonly
deprecated
Deprecated.
Use #private? instead, it's guaranteed to be accurate.
-
#name ⇒ String
This channel's name.
-
#permission_overwrites ⇒ Hash<Integer => OpenStruct>
readonly
This channel's permission overwrites, represented as a hash of role/user ID to an OpenStruct which has the
allow
anddeny
properties which are Permissions objects respectively. -
#position ⇒ Integer
The channel's position on the channel list.
-
#recipient ⇒ User?
readonly
The recipient of the private messages, or nil if this is not a PM channel.
-
#server ⇒ Server
readonly
The server this channel is on.
-
#topic ⇒ String
The channel's topic.
-
#type ⇒ String
readonly
The type of this channel (currently either 'text' or 'voice').
Instance Method Summary collapse
-
#==(other) ⇒ Object
ID based comparison.
-
#await(key, attributes = {}, &block) ⇒ Object
Add an Await for a message in this channel.
-
#delete ⇒ Object
Permanently deletes this channel.
-
#history(amount, before_id = nil, after_id = nil) ⇒ Array<Message>
Retrieves some of this channel's message history.
- #make_invite(max_age = 0, max_uses = 0, temporary = false, xkcd = false) ⇒ Object (also: #invite)
-
#private? ⇒ true, false
Whether or not this channel is a PM channel, with more accuracy than #is_private.
-
#send_file(file) ⇒ Object
Sends a file to this channel.
-
#send_message(content) ⇒ Message
(also: #send, #message)
Sends a message to this channel.
-
#start_typing ⇒ Object
Starts typing, which displays the typing indicator on the client for five seconds.
-
#users ⇒ Array<User>
The list of users currently in this channel.
Instance Attribute Details
#id ⇒ Integer (readonly) Also known as: resolve_id
If this channel is a #general channel, its ID will be equal to the server on which it is on.
Returns the channel's unique ID.
481 482 483 |
# File 'lib/discordrb/data.rb', line 481 def id @id end |
#is_private ⇒ true, false (readonly)
Use #private? instead, it's guaranteed to be accurate.
This data is sent by Discord and it's possible for this to falsely be true for certain kinds of integration channels (like Twitch subscriber ones). This appears to be a Discord bug that I can't reproduce myself, due to not having any integrations in place. If this occurs to you please tell me.
Returns whether or not this channel is a private messaging channel.
488 489 490 |
# File 'lib/discordrb/data.rb', line 488 def is_private @is_private end |
#name ⇒ String
Returns this channel's name.
471 472 473 |
# File 'lib/discordrb/data.rb', line 471 def name @name end |
#permission_overwrites ⇒ Hash<Integer => OpenStruct> (readonly)
This channel's permission overwrites, represented as a hash of role/user ID to an OpenStruct which has the
allow
and deny
properties which are Permissions objects respectively.
502 503 504 |
# File 'lib/discordrb/data.rb', line 502 def @permission_overwrites end |
#position ⇒ Integer
Returns the channel's position on the channel list.
497 498 499 |
# File 'lib/discordrb/data.rb', line 497 def position @position end |
#recipient ⇒ User? (readonly)
Returns the recipient of the private messages, or nil if this is not a PM channel.
491 492 493 |
# File 'lib/discordrb/data.rb', line 491 def recipient @recipient end |
#server ⇒ Server (readonly)
Returns the server this channel is on.
474 475 476 |
# File 'lib/discordrb/data.rb', line 474 def server @server end |
#topic ⇒ String
Returns the channel's topic.
494 495 496 |
# File 'lib/discordrb/data.rb', line 494 def topic @topic end |
#type ⇒ String (readonly)
Returns the type of this channel (currently either 'text' or 'voice').
477 478 479 |
# File 'lib/discordrb/data.rb', line 477 def type @type end |
Instance Method Details
#==(other) ⇒ Object
ID based comparison
547 548 549 |
# File 'lib/discordrb/data.rb', line 547 def ==(other) Discordrb.id_compare(@id, other) end |
#await(key, attributes = {}, &block) ⇒ Object
Add an Await for a message in this channel. This is identical in functionality to adding a
Events::MessageEvent await with the in
attribute as this channel.
637 638 639 |
# File 'lib/discordrb/data.rb', line 637 def await(key, attributes = {}, &block) @bot.add_await(key, Discordrb::Events::MessageEvent, { in: @id }.merge(attributes), &block) end |
#delete ⇒ Object
Permanently deletes this channel
565 566 567 |
# File 'lib/discordrb/data.rb', line 565 def delete API.delete_channel(@bot.token, @id) end |
#history(amount, before_id = nil, after_id = nil) ⇒ Array<Message>
Retrieves some of this channel's message history.
622 623 624 625 |
# File 'lib/discordrb/data.rb', line 622 def history(amount, before_id = nil, after_id = nil) logs = API.channel_log(@bot.token, @id, amount, before_id, after_id) JSON.parse(logs).map { || Message.new(, @bot) } end |
#make_invite(max_age = 0, max_uses = 0, temporary = false, xkcd = false) ⇒ Object Also known as: invite
641 642 643 644 |
# File 'lib/discordrb/data.rb', line 641 def make_invite(max_age = 0, max_uses = 0, temporary = false, xkcd = false) response = API.create_invite(@bot.token, @id, max_age, max_uses, temporary, xkcd) Invite.new(JSON.parse(response), @bot) end |
#private? ⇒ true, false
Returns whether or not this channel is a PM channel, with more accuracy than #is_private.
507 508 509 |
# File 'lib/discordrb/data.rb', line 507 def private? @server.nil? end |
#send_file(file) ⇒ Object
Sends a file to this channel. If it is an image, it will be embedded.
560 561 562 |
# File 'lib/discordrb/data.rb', line 560 def send_file(file) @bot.send_file(@id, file) end |
#send_message(content) ⇒ Message Also known as: send, message
Sends a message to this channel.
554 555 556 |
# File 'lib/discordrb/data.rb', line 554 def (content) @bot.(@id, content) end |
#start_typing ⇒ Object
Starts typing, which displays the typing indicator on the client for five seconds. If you want to keep typing you'll have to resend this every five seconds. (An abstraction for this will eventually be coming)
649 650 651 |
# File 'lib/discordrb/data.rb', line 649 def start_typing API.start_typing(@bot.token, @id) end |
#users ⇒ Array<User>
The list of users currently in this channel. This is mostly useful for a voice channel, for a text channel it will just return the users on the server that are online.
604 605 606 607 608 609 610 611 612 |
# File 'lib/discordrb/data.rb', line 604 def users if @type == 'text' @server.members.select { |u| u.status != :offline } else @server.members.select do |user| user.voice_channel.id == @id if user.voice_channel end end end |