class Discorb::GuildChannel

Represents a channel in guild. @abstract

Attributes

permission_overwrites[R]

@return [Hash{Discorb::Role, Discorb::Member => PermissionOverwrite}] The permission overwrites of the channel.

position[R]

@return [Integer] The position of the channel as integer.

Public Instance Methods

<=>(other) click to toggle source

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
==(other) click to toggle source

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
category()
Alias for: parent
close!(reason: nil)
Alias for: delete!
delete!(reason: nil) click to toggle source

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
Also aliased as: close!, destroy!
destroy!(reason: nil)
Alias for: delete!
guild() click to toggle source
# File lib/discorb/channel.rb, line 159
def guild
  @client.guilds[@guild_id]
end
inspect() click to toggle source
# File lib/discorb/channel.rb, line 163
def inspect
  "#<#{self.class} \"##{@name}\" id=#{@id}>"
end
mention() click to toggle source
# File lib/discorb/channel.rb, line 147
def mention
  "<##{@id}>"
end
move(position, lock_permissions: false, parent: :unset, reason: nil) click to toggle source

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
parent() click to toggle source
# File lib/discorb/channel.rb, line 151
def parent
  return nil unless @parent_id

  @client.channels[@parent_id]
end
Also aliased as: category
to_s() click to toggle source

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

_set_data(data) click to toggle source
Calls superclass method Discorb::Channel#_set_data
# 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