class Discorb::GuildChannel
Represents a channel in guild. @abstract
Attributes
@return [Hash{Discorb::Role, Discorb::Member
=> PermissionOverwrite}] The permission overwrites of the channel.
@return [Integer] The position of the channel as integer.
Public Instance Methods
Compares position of two channels.
@param [Discorb::GuildChannel] other The channel to compare.
@return [-1, 1] -1 if the channel is at lower than the other, 1 if the channel is at highter than the other.
# File lib/discorb/channel.rb, line 119 def <=>(other) return 0 unless other.respond_to?(:position) @position <=> other.position end
Checks if the channel is same as another.
@param [Discorb::GuildChannel] other The channel to check.
@return [Boolean] `true` if the channel is same as another.
# File lib/discorb/channel.rb, line 132 def ==(other) return false unless other.respond_to?(:id) @id == other.id end
Deletes the channel. @macro async @macro http
@param [String] reason The reason of deleting the channel.
@return [self] The deleted channel.
# File lib/discorb/channel.rb, line 176 def delete!(reason: nil) Async do @client.http.delete(base_url.wait.to_s, audit_log_reason: reason).wait @deleted = true self end end
# File lib/discorb/channel.rb, line 159 def guild @client.guilds[@guild_id] end
# File lib/discorb/channel.rb, line 163 def inspect "#<#{self.class} \"##{@name}\" id=#{@id}>" end
# File lib/discorb/channel.rb, line 147 def mention "<##{@id}>" end
Moves the channel to another position. @macro async @macro http
@param [Integer] position The position to move the channel. @param [Boolean] lock_permissions Whether to lock the permissions of the channel. @param [Discorb::CategoryChannel] parent The parent of channel. @param [String] reason The reason of moving the channel.
@return [self] The moved channel.
# File lib/discorb/channel.rb, line 199 def move(position, lock_permissions: false, parent: :unset, reason: nil) Async do payload = { position: position, } payload[:lock_permissions] = lock_permissions payload[:parent_id] = parent&.id if parent != :unset @client.http.patch("/guilds/#{@guild_id}/channels", payload, audit_log_reason: reason).wait end end
# File lib/discorb/channel.rb, line 151 def parent return nil unless @parent_id @client.channels[@parent_id] end
Stringifies the channel.
@return [String] The name of the channel with `#`.
# File lib/discorb/channel.rb, line 143 def to_s "##{@name}" end
Private Instance Methods
# File lib/discorb/channel.rb, line 212 def _set_data(data) @guild_id = data[:guild_id] @position = data[:position] @permission_overwrites = if data[:permission_overwrites] data[:permission_overwrites].map do |ow| [(ow[:type] == 1 ? guild.roles : guild.members)[ow[:id]], PermissionOverwrite.new(ow[:allow], ow[:deny])] end.to_h else {} end @parent_id = data[:parent_id] super end