Class: Discordrb::Channel
- Inherits:
-
Object
- Object
- Discordrb::Channel
- Includes:
- IDObject
- Defined in:
- lib/discordrb/data.rb
Overview
A Discord channel, including data like the topic
Constant Summary collapse
- TYPES =
Map of channel types
{ text: 0, dm: 1, voice: 2, group: 3, category: 4 }.freeze
Instance Attribute Summary collapse
-
#bitrate ⇒ Integer
The bitrate (in bps) of the channel.
-
#name ⇒ String
This channel's name.
-
#nsfw ⇒ true, false
(also: #nsfw?)
If this channel is marked as nsfw.
-
#owner_id ⇒ Integer?
readonly
The id of the owner of the group channel or nil if this is not a group channel.
-
#parent_id ⇒ Integer?
readonly
The ID of the parent channel, if this channel is inside a cateogry.
-
#position ⇒ Integer
The channel's position on the channel list.
-
#rate_limit_per_user ⇒ Integer
(also: #slowmode_rate)
The amount of time (in seconds) users need to wait to send in between messages.
-
#recipients ⇒ Array<Recipient>?
readonly
The array of recipients of the private messages, or nil if this is not a Private channel.
-
#server ⇒ Server?
readonly
The server this channel is on.
-
#topic ⇒ String
The channel's topic.
-
#type ⇒ Integer
readonly
The type of this channel (0: text, 1: private, 2: voice, 3: group).
-
#user_limit ⇒ Integer
(also: #limit)
The amount of users that can be in the channel.
Attributes included from IDObject
Instance Method Summary collapse
-
#add_group_users(user_ids) ⇒ Channel
(also: #add_group_user)
Adds a user to a group channel.
-
#await(key, attributes = {}, &block) ⇒ Object
deprecated
Deprecated.
Will be changed to blocking behavior in v4.0. Use #await! instead.
-
#await!(attributes = {}) ⇒ Object
Add a blocking Await for a message in this channel.
-
#category ⇒ Channel?
(also: #parent)
The category channel, if this channel is in a category.
-
#category=(channel) ⇒ Object
(also: #parent=)
Sets this channels parent category.
- #category? ⇒ true, false
-
#children ⇒ Array<Channel>
(also: #channels)
Returns the children of this channel, if it is a category.
-
#create_group(user_ids) ⇒ Channel
Creates a Group channel.
-
#default_channel? ⇒ true, false
(also: #default?)
Whether or not this channel is the default channel.
-
#define_overwrite(thing, allow = 0, deny = 0, reason: nil) ⇒ Object
Defines a permission overwrite for this channel that sets the specified thing to the specified allow and deny permission sets, or change an existing one.
-
#delete(reason = nil) ⇒ Object
Permanently deletes this channel.
-
#delete_message(message) ⇒ Object
Deletes a message on this channel.
-
#delete_messages(messages, strict = false) ⇒ Integer
Deletes a collection of messages.
-
#delete_overwrite(target, reason = nil) ⇒ Object
Deletes a permission overwrite for this channel.
-
#group? ⇒ true, false
Whether or not this channel is a group channel.
-
#history(amount, before_id = nil, after_id = nil, around_id = nil) ⇒ Array<Message>
Retrieves some of this channel's message history.
-
#inspect ⇒ Object
The default
inspect
method is overwritten to give more useful output. -
#invites ⇒ Array<Invite>
Requests a list of Invites to the channel.
-
#leave_group ⇒ Object
(also: #leave)
Leaves the group.
-
#load_message(message_id) ⇒ Message?
(also: #message)
Returns a single message from this channel's history by ID.
-
#make_invite(max_age = 0, max_uses = 0, temporary = false, unique = false, reason = nil) ⇒ Invite
(also: #invite)
Creates a new invite to this channel.
-
#member_overwrites ⇒ Overwrite
Any member-type permission overwrites on this channel.
-
#mention ⇒ String
A string that will mention the channel as a clickable link on Discord.
-
#permission_overwrites(type = nil) ⇒ Object
(also: #overwrites)
This channel's permission overwrites.
-
#permission_overwrites=(overwrites) ⇒ Object
Bulk sets this channels permission overwrites.
-
#pins ⇒ Array<Message>
Requests all pinned messages in a channel.
-
#pm? ⇒ true, false
Whether or not this channel is a PM channel.
-
#private? ⇒ true, false
Whether or not this channel is a PM or group channel.
-
#prune(amount, strict = false) {|message| ... } ⇒ Integer
Delete the last N messages on this channel.
-
#recipient ⇒ Recipient?
The recipient of the private messages, or nil if this is not a PM channel.
-
#remove_group_users(user_ids) ⇒ Channel
(also: #remove_group_user)
Removes a user from a group channel.
-
#role_overwrites ⇒ Overwrite
Any role-type permission overwrites on this channel.
-
#send_embed(message = '', embed = nil) {|embed| ... } ⇒ Message
Convenience method to send a message with an embed.
-
#send_file(file, caption: nil, tts: false) ⇒ Object
Sends a file to this channel.
-
#send_message(content, tts = false, embed = nil) ⇒ Message
(also: #send)
Sends a message to this channel.
-
#send_multiple(content) ⇒ Object
Sends multiple messages to a channel.
-
#send_temporary_message(content, timeout, tts = false, embed = nil) ⇒ Object
Sends a temporary message to this channel.
-
#slowmode? ⇒ true, false
Whether or not this channel has slowmode enabled.
-
#sort_after(other = nil, lock_permissions = false) ⇒ Object
Sorts this channel's position to follow another channel.
-
#split_send(content) ⇒ Object
Splits a message into chunks whose length is at most the Discord character limit, then sends them individually.
-
#start_typing ⇒ Object
Starts typing, which displays the typing indicator on the client for five seconds.
-
#sync_overwrites ⇒ Object
(also: #sync)
Syncs this channels overwrites with its parent category.
-
#synchronized? ⇒ true, ...
(also: #synced?)
Whether this channels permissions match the permission overwrites of the category that it's in, or nil if it is not in a category.
-
#text? ⇒ true, false
Whether or not this channel is a text channel.
-
#text_channels ⇒ Array<Channel>
Returns the text channels in this category, if it is a category channel.
-
#users ⇒ Array<Member>
The list of users currently in this channel.
-
#voice? ⇒ true, false
Whether or not this channel is a voice channel.
-
#voice_channels ⇒ Array<Channel>
Returns the voice channels in this category, if it is a category channel.
-
#webhooks ⇒ Array<Webhook>
Requests a list of Webhooks on the channel.
Methods included from IDObject
#==, #creation_time, synthesise
Instance Attribute Details
#bitrate ⇒ Integer
Returns the bitrate (in bps) of the channel.
1335 1336 1337 |
# File 'lib/discordrb/data.rb', line 1335 def bitrate @bitrate end |
#name ⇒ String
Returns this channel's name.
1314 1315 1316 |
# File 'lib/discordrb/data.rb', line 1314 def name @name end |
#nsfw ⇒ true, false Also known as: nsfw?
Returns if this channel is marked as nsfw.
1345 1346 1347 |
# File 'lib/discordrb/data.rb', line 1345 def nsfw @nsfw end |
#owner_id ⇒ Integer? (readonly)
Returns the id of the owner of the group channel or nil if this is not a group channel.
1326 1327 1328 |
# File 'lib/discordrb/data.rb', line 1326 def owner_id @owner_id end |
#parent_id ⇒ Integer? (readonly)
Returns the ID of the parent channel, if this channel is inside a cateogry.
1320 1321 1322 |
# File 'lib/discordrb/data.rb', line 1320 def parent_id @parent_id end |
#position ⇒ Integer
Returns the channel's position on the channel list.
1342 1343 1344 |
# File 'lib/discordrb/data.rb', line 1342 def position @position end |
#rate_limit_per_user ⇒ Integer Also known as: slowmode_rate
Returns the amount of time (in seconds) users need to wait to send in between messages.
1349 1350 1351 |
# File 'lib/discordrb/data.rb', line 1349 def rate_limit_per_user @rate_limit_per_user end |
#recipients ⇒ Array<Recipient>? (readonly)
Returns the array of recipients of the private messages, or nil if this is not a Private channel.
1329 1330 1331 |
# File 'lib/discordrb/data.rb', line 1329 def recipients @recipients end |
#server ⇒ Server? (readonly)
Returns the server this channel is on. If this channel is a PM channel, it will be nil.
1317 1318 1319 |
# File 'lib/discordrb/data.rb', line 1317 def server @server end |
#topic ⇒ String
Returns the channel's topic.
1332 1333 1334 |
# File 'lib/discordrb/data.rb', line 1332 def topic @topic end |
#type ⇒ Integer (readonly)
Returns the type of this channel (0: text, 1: private, 2: voice, 3: group).
1323 1324 1325 |
# File 'lib/discordrb/data.rb', line 1323 def type @type end |
#user_limit ⇒ Integer Also known as: limit
Returns the amount of users that can be in the channel. 0
means it is unlimited.
1338 1339 1340 |
# File 'lib/discordrb/data.rb', line 1338 def user_limit @user_limit end |
Instance Method Details
#add_group_users(user_ids) ⇒ Channel Also known as: add_group_user
Adds a user to a group channel.
1946 1947 1948 1949 1950 1951 1952 1953 1954 |
# File 'lib/discordrb/data.rb', line 1946 def add_group_users(user_ids) raise 'Attempted to add a user to a non-group channel!' unless group? user_ids = [user_ids] unless user_ids.is_a? Array user_ids.each do |user_id| API::Channel.add_group_user(@bot.token, @id, user_id.resolve_id) end self end |
#await(key, attributes = {}, &block) ⇒ Object
Will be changed to blocking behavior in v4.0. Use #await! instead.
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.
1897 1898 1899 |
# File 'lib/discordrb/data.rb', line 1897 def await(key, attributes = {}, &block) @bot.add_await(key, Discordrb::Events::MessageEvent, { in: @id }.merge(attributes), &block) end |
#await!(attributes = {}) ⇒ Object
Add a blocking 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.
1904 1905 1906 |
# File 'lib/discordrb/data.rb', line 1904 def await!(attributes = {}) @bot.add_await!(Discordrb::Events::MessageEvent, { in: @id }.merge(attributes)) end |
#category ⇒ Channel? Also known as: parent
Returns the category channel, if this channel is in a category.
1430 1431 1432 |
# File 'lib/discordrb/data.rb', line 1430 def category @bot.channel(@parent_id) if @parent_id end |
#category=(channel) ⇒ Object Also known as: parent=
Sets this channels parent category
1439 1440 1441 1442 1443 1444 |
# File 'lib/discordrb/data.rb', line 1439 def category=(channel) channel = @bot.channel(channel) raise ArgumentError, 'Cannot set parent category to a channel that isn\'t a category' unless channel.category? update_channel_data(parent_id: channel.id) end |
#category? ⇒ true, false
1425 1426 1427 |
# File 'lib/discordrb/data.rb', line 1425 def category? @type == 4 end |
#children ⇒ Array<Channel> Also known as: channels
Returns the children of this channel, if it is a category. Otherwise returns an empty array.
1578 1579 1580 1581 1582 |
# File 'lib/discordrb/data.rb', line 1578 def children return [] unless category? server.channels.select { |c| c.parent_id == id } end |
#create_group(user_ids) ⇒ Channel
Creates a Group channel
1935 1936 1937 1938 1939 1940 1941 |
# File 'lib/discordrb/data.rb', line 1935 def create_group(user_ids) raise 'Attempted to create group channel on a non-pm channel!' unless pm? response = API::Channel.create_group(@bot.token, @id, user_ids.shift) channel = Channel.new(JSON.parse(response), @bot) channel.add_group_users(user_ids) end |
#default_channel? ⇒ true, false Also known as: default?
Returns whether or not this channel is the default channel.
1609 1610 1611 |
# File 'lib/discordrb/data.rb', line 1609 def default_channel? server.default_channel == self end |
#define_overwrite(overwrite) ⇒ Object #define_overwrite(thing, allow, deny) ⇒ Object
Defines a permission overwrite for this channel that sets the specified thing to the specified allow and deny permission sets, or change an existing one.
1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 |
# File 'lib/discordrb/data.rb', line 1750 def define_overwrite(thing, allow = 0, deny = 0, reason: nil) unless thing.is_a? Overwrite allow_bits = allow.respond_to?(:bits) ? allow.bits : allow deny_bits = deny.respond_to?(:bits) ? deny.bits : deny thing = Overwrite.new thing, allow: allow_bits, deny: deny_bits end API::Channel.(@bot.token, @id, thing.id, thing.allow.bits, thing.deny.bits, thing.type, reason) end |
#delete(reason = nil) ⇒ Object
Permanently deletes this channel
1687 1688 1689 |
# File 'lib/discordrb/data.rb', line 1687 def delete(reason = nil) API::Channel.delete(@bot.token, @id, reason) end |
#delete_message(message) ⇒ Object
Deletes a message on this channel. Mostly useful in case a message needs to be deleted when only the ID is known
1681 1682 1683 |
# File 'lib/discordrb/data.rb', line 1681 def () API::Channel.(@bot.token, @id, .resolve_id) end |
#delete_messages(messages, strict = false) ⇒ Integer
Deletes a collection of messages
1879 1880 1881 1882 1883 1884 |
# File 'lib/discordrb/data.rb', line 1879 def (, strict = false) raise ArgumentError, 'Can only delete between 2 and 100 messages!' unless .count.between?(2, 100) .map!(&:resolve_id) bulk_delete(, strict) end |
#delete_overwrite(target, reason = nil) ⇒ Object
Deletes a permission overwrite for this channel
1764 1765 1766 1767 1768 |
# File 'lib/discordrb/data.rb', line 1764 def delete_overwrite(target, reason = nil) raise 'Tried deleting a overwrite for an invalid target' unless target.is_a?(Member) || target.is_a?(User) || target.is_a?(Role) || target.is_a?(Profile) || target.is_a?(Recipient) || target.respond_to?(:resolve_id) API::Channel.(@bot.token, @id, target.resolve_id, reason) end |
#group? ⇒ true, false
Returns whether or not this channel is a group channel.
1420 1421 1422 |
# File 'lib/discordrb/data.rb', line 1420 def group? @type == 3 end |
#history(amount, before_id = nil, after_id = nil, around_id = nil) ⇒ Array<Message>
Retrieves some of this channel's message history.
1811 1812 1813 1814 |
# File 'lib/discordrb/data.rb', line 1811 def history(amount, before_id = nil, after_id = nil, around_id = nil) logs = API::Channel.(@bot.token, @id, amount, before_id, after_id, around_id) JSON.parse(logs).map { || Message.new(, @bot) } end |
#inspect ⇒ Object
The default inspect
method is overwritten to give more useful output.
2001 2002 2003 |
# File 'lib/discordrb/data.rb', line 2001 def inspect "<Channel name=#{@name} id=#{@id} topic=\"#{@topic}\" type=#{@type} position=#{@position} server=#{@server}>" end |
#invites ⇒ Array<Invite>
Requests a list of Invites to the channel.
1993 1994 1995 1996 1997 1998 |
# File 'lib/discordrb/data.rb', line 1993 def invites raise 'Tried to request invites from a non-server channel' unless server invites = JSON.parse(API::Channel.invites(@bot.token, @id)) invites.map { |invite_data| Invite.new(invite_data, @bot) } end |
#leave_group ⇒ Object Also known as: leave
Leaves the group.
1974 1975 1976 1977 1978 |
# File 'lib/discordrb/data.rb', line 1974 def leave_group raise 'Attempted to leave a non-group channel!' unless group? API::Channel.leave_group(@bot.token, @id) end |
#load_message(message_id) ⇒ Message? Also known as: message
Returns a single message from this channel's history by ID.
1827 1828 1829 1830 1831 1832 |
# File 'lib/discordrb/data.rb', line 1827 def () response = API::Channel.(@bot.token, @id, ) Message.new(JSON.parse(response), @bot) rescue RestClient::ResourceNotFound nil end |
#make_invite(max_age = 0, max_uses = 0, temporary = false, unique = false, reason = nil) ⇒ Invite Also known as: invite
Creates a new invite to this channel.
1915 1916 1917 1918 |
# File 'lib/discordrb/data.rb', line 1915 def make_invite(max_age = 0, max_uses = 0, temporary = false, unique = false, reason = nil) response = API::Channel.create_invite(@bot.token, @id, max_age, max_uses, temporary, unique, reason) Invite.new(JSON.parse(response), @bot) end |
#member_overwrites ⇒ Overwrite
Returns any member-type permission overwrites on this channel.
1599 1600 1601 |
# File 'lib/discordrb/data.rb', line 1599 def member_overwrites :member end |
#mention ⇒ String
Returns a string that will mention the channel as a clickable link on Discord.
1358 1359 1360 |
# File 'lib/discordrb/data.rb', line 1358 def mention "<##{@id}>" end |
#permission_overwrites ⇒ Hash<Integer => Overwrite> #permission_overwrites(type) ⇒ Array<Overwrite> Also known as: overwrites
This channel's permission overwrites
1532 1533 1534 1535 1536 |
# File 'lib/discordrb/data.rb', line 1532 def (type = nil) return @permission_overwrites unless type @permission_overwrites.values.select { |e| e.type == type } end |
#permission_overwrites=(overwrites) ⇒ Object
Bulk sets this channels permission overwrites
1542 1543 1544 |
# File 'lib/discordrb/data.rb', line 1542 def (overwrites) update_channel_data(permission_overwrites: overwrites) end |
#pins ⇒ Array<Message>
Requests all pinned messages in a channel.
1838 1839 1840 1841 |
# File 'lib/discordrb/data.rb', line 1838 def pins msgs = API::Channel.(@bot.token, @id) JSON.parse(msgs).map { |msg| Message.new(msg, @bot) } end |
#pm? ⇒ true, false
Returns whether or not this channel is a PM channel.
1410 1411 1412 |
# File 'lib/discordrb/data.rb', line 1410 def pm? @type == 1 end |
#private? ⇒ true, false
Returns whether or not this channel is a PM or group channel.
1353 1354 1355 |
# File 'lib/discordrb/data.rb', line 1353 def private? pm? || group? end |
#prune(amount, strict = false) {|message| ... } ⇒ Integer
Delete the last N messages on this channel.
1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 |
# File 'lib/discordrb/data.rb', line 1852 def prune(amount, strict = false, &block) raise ArgumentError, 'Can only delete between 1 and 100 messages!' unless amount.between?(1, 100) = if block_given? history(amount).select(&block).map(&:id) else history_ids(amount) end case .size when 0 0 when 1 API::Channel.(@bot.token, @id, .first) 1 else bulk_delete(, strict) end end |
#recipient ⇒ Recipient?
Returns the recipient of the private messages, or nil if this is not a PM channel.
1363 1364 1365 |
# File 'lib/discordrb/data.rb', line 1363 def recipient @recipients.first if pm? end |
#remove_group_users(user_ids) ⇒ Channel Also known as: remove_group_user
Removes a user from a group channel.
1961 1962 1963 1964 1965 1966 1967 1968 1969 |
# File 'lib/discordrb/data.rb', line 1961 def remove_group_users(user_ids) raise 'Attempted to remove a user from a non-group channel!' unless group? user_ids = [user_ids] unless user_ids.is_a? Array user_ids.each do |user_id| API::Channel.remove_group_user(@bot.token, @id, user_id.resolve_id) end self end |
#role_overwrites ⇒ Overwrite
Returns any role-type permission overwrites on this channel.
1604 1605 1606 |
# File 'lib/discordrb/data.rb', line 1604 def role_overwrites :role end |
#send_embed(message = '', embed = nil) {|embed| ... } ⇒ Message
Convenience method to send a message with an embed.
1651 1652 1653 1654 1655 |
# File 'lib/discordrb/data.rb', line 1651 def ( = '', = nil) ||= Discordrb::Webhooks::Embed.new yield() if block_given? (, false, ) end |
#send_file(file, caption: nil, tts: false) ⇒ Object
Sends a file to this channel. If it is an image, it will be embedded.
1675 1676 1677 |
# File 'lib/discordrb/data.rb', line 1675 def send_file(file, caption: nil, tts: false) @bot.send_file(@id, file, caption: , tts: tts) end |
#send_message(content, tts = false, embed = nil) ⇒ Message Also known as: send
Sends a message to this channel.
1625 1626 1627 |
# File 'lib/discordrb/data.rb', line 1625 def (content, tts = false, = nil) @bot.(@id, content, tts, ) end |
#send_multiple(content) ⇒ Object
Sends multiple messages to a channel
1659 1660 1661 |
# File 'lib/discordrb/data.rb', line 1659 def send_multiple(content) content.each { |e| (e) } end |
#send_temporary_message(content, timeout, tts = false, embed = nil) ⇒ Object
Sends a temporary message to this channel.
1636 1637 1638 |
# File 'lib/discordrb/data.rb', line 1636 def (content, timeout, tts = false, = nil) @bot.(@id, content, timeout, tts, ) end |
#slowmode? ⇒ true, false
Returns whether or not this channel has slowmode enabled.
1616 1617 1618 |
# File 'lib/discordrb/data.rb', line 1616 def slowmode? @rate_limit_per_user != 0 end |
#sort_after(other = nil, lock_permissions = false) ⇒ Object
Sorts this channel's position to follow another channel.
1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 |
# File 'lib/discordrb/data.rb', line 1453 def sort_after(other = nil, = false) raise TypeError, 'other must be one of Channel, NilClass, or #resolve_id' unless other.is_a?(Channel) || other.nil? || other.respond_to?(:resolve_id) other = @bot.channel(other.resolve_id) if other # Container for the API request payload move_argument = [] if other raise ArgumentError, 'Can only sort a channel after a channel of the same type!' unless other.category? || (@type == other.type) raise ArgumentError, 'Can only sort a channel after a channel in the same server!' unless other.server == server # Store `others` parent (or if `other` is a category itself) parent = if category? && other.category? # If we're sorting two categories, there is no new parent nil elsif other.category? # `other` is the category this channel will be moved into other else # `other`'s parent is the category this channel will be # moved into (if it exists) other.parent end end # Collect and sort the IDs within the context (category or not) that we # need to form our payload with ids = if parent parent.children else @server.channels.reject(&:parent_id).select { |c| c.type == @type } end.sort_by(&:position).map(&:id) # Move our channel ID after the target ID by deleting it, # getting the index of `other`, and inserting it after. ids.delete(@id) if ids.include?(@id) index = other ? (ids.index { |c| c == other.id } || -1) + 1 : 0 ids.insert(index, @id) # Generate `move_argument`, making the positions in order from how # we have sorted them in the above logic ids.each_with_index do |id, pos| # These keys are present in each element hash = { id: id, position: pos } # Conditionally add `lock_permissions` and `parent_id` if we're # iterating past ourself if id == @id hash[:lock_permissions] = true if hash[:parent_id] = parent.nil? ? nil : parent.id end # Add it to the stack move_argument << hash end API::Server.update_channel_positions(@bot.token, @server.id, move_argument) end |
#split_send(content) ⇒ Object
Splits a message into chunks whose length is at most the Discord character limit, then sends them individually. Useful for sending long messages, but be wary of rate limits!
1665 1666 1667 |
# File 'lib/discordrb/data.rb', line 1665 def split_send(content) send_multiple(Discordrb.(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)
1927 1928 1929 |
# File 'lib/discordrb/data.rb', line 1927 def start_typing API::Channel.start_typing(@bot.token, @id) end |
#sync_overwrites ⇒ Object Also known as: sync
Syncs this channels overwrites with its parent category
1559 1560 1561 1562 1563 |
# File 'lib/discordrb/data.rb', line 1559 def sync_overwrites raise 'Cannot sync overwrites on a channel with no parent category' unless parent self. = parent. end |
#synchronized? ⇒ true, ... Also known as: synced?
Returns whether this channels permissions match the permission overwrites of the category that it's in, or nil if it is not in a category.
1568 1569 1570 1571 1572 |
# File 'lib/discordrb/data.rb', line 1568 def synchronized? return unless parent == parent. end |
#text? ⇒ true, false
Returns whether or not this channel is a text channel.
1405 1406 1407 |
# File 'lib/discordrb/data.rb', line 1405 def text? @type.zero? end |
#text_channels ⇒ Array<Channel>
Returns the text channels in this category, if it is a category channel. Otherwise returns an empty array.
1588 1589 1590 |
# File 'lib/discordrb/data.rb', line 1588 def text_channels children.select(&:text?) end |
#users ⇒ Array<Member>
The list of users currently in this channel. For a voice channel, it will return all the members currently in that channel. For a text channel, it will return all online members that have permission to read it.
1790 1791 1792 1793 1794 1795 1796 |
# File 'lib/discordrb/data.rb', line 1790 def users if text? @server.online_members(include_idle: true).select { |u| u. self } elsif voice? @server.voice_states.map { |id, voice_state| @server.member(id) if !voice_state.voice_channel.nil? && voice_state.voice_channel.id == @id }.compact end end |
#voice? ⇒ true, false
Returns whether or not this channel is a voice channel.
1415 1416 1417 |
# File 'lib/discordrb/data.rb', line 1415 def voice? @type == 2 end |
#voice_channels ⇒ Array<Channel>
Returns the voice channels in this category, if it is a category channel. Otherwise returns an empty array.
1594 1595 1596 |
# File 'lib/discordrb/data.rb', line 1594 def voice_channels children.select(&:voice?) end |
#webhooks ⇒ Array<Webhook>
Requests a list of Webhooks on the channel.
1984 1985 1986 1987 1988 1989 |
# File 'lib/discordrb/data.rb', line 1984 def webhooks raise 'Tried to request webhooks from a non-server channel' unless server webhooks = JSON.parse(API::Channel.webhooks(@bot.token, @id)) webhooks.map { |webhook_data| Webhook.new(webhook_data, @bot) } end |