Class: Discorb::WelcomeScreen::Channel

Inherits:
DiscordModel show all
Defined in:
lib/discorb/guild.rb

Overview

Represents a channel to display the welcome screen.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from DiscordModel

#==, #eql?, #inspect

Constructor Details

#initialize(channel, description, emoji) ⇒ Channel

Initialize a new welcome screen channel.

Parameters:

  • channel (Discorb::TextChannel)

    The channel to display the welcome screen.

  • description (String)

    The channel's name.

  • emoji (Discorb::Emoji)

    The emoji to display.



2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
# File 'lib/discorb/guild.rb', line 2025

def initialize(channel, description, emoji)
  if description.is_a?(Hash)
    @screen = channel
    data = description
    @channel_id = Snowflake.new(data[:channel_id])
    @description = data[:description]
    @emoji_id = Snowflake.new(data[:emoji_id])
    @emoji_name = data[:emoji_name]
  else
    @channel_id = channel.id
    @description = description
    if emoji.is_a?(UnicodeEmoji)
      @emoji_id = nil
      @emoji_name = emoji.value
    else
      @emoji_id = emoji.id
      @emoji_name = emoji.name
    end
  end
end

Instance Attribute Details

#channelnil, Discorb::Channel (readonly)

Note:

This method returns an object from client cache. it will return nil if the object is not in cache.

Returns:

  • (nil)

    The object wasn't cached.

  • (Discorb::Channel)

    The channel to display the welcome screen.



# File 'lib/discorb/guild.rb', line 2012

#descriptionString (readonly)

Returns The channel's name.

Returns:

  • (String)

    The channel's name.



2010
2011
2012
# File 'lib/discorb/guild.rb', line 2010

def description
  @description
end

#emojiDiscorb::Emoji (readonly)

Returns The emoji to display.

Returns:



# File 'lib/discorb/guild.rb', line 2012

Instance Method Details

#edit(enabled: Discorb::Unset, channels: Discorb::Unset, description: Discorb::Unset, reason: nil) ⇒ Async::Task<void>

Note:

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 welcome screen.

Parameters:

  • enabled (Boolean) (defaults to: Discorb::Unset)

    Whether the welcome screen is enabled.

  • channels (Array<Discorb::WelcomeScreen::Channel>) (defaults to: Discorb::Unset)

    The channels to display the welcome screen.

  • description (String) (defaults to: Discorb::Unset)

    The description of the welcome screen.

  • reason (String) (defaults to: nil)

    The reason for editing the welcome screen.

Returns:

  • (Async::Task<void>)

    The task.



2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
# File 'lib/discorb/guild.rb', line 2085

def edit(
  enabled: Discorb::Unset,
  channels: Discorb::Unset,
  description: Discorb::Unset,
  reason: nil
)
  Async do
    payload = {}
    payload[:enabled] = enabled unless enabled == Discorb::Unset
    payload[:welcome_channels] = channels.map(
      &:to_hash
    ) unless channels == Discorb::Unset
    payload[:description] = description unless description ==
      Discorb::Unset
    @client
      .http
      .request(
        Route.new(
          "/guilds/#{@guild.id}/welcome-screen",
          "//guilds/:guild_id/welcome-screen",
          :patch
        ),
        payload,
        audit_log_reason: reason
      )
      .wait
  end
end

#to_hashHash

Converts the channel to a hash.



2052
2053
2054
2055
2056
2057
2058
2059
# File 'lib/discorb/guild.rb', line 2052

def to_hash
  {
    channel_id: @channel_id,
    description: @description,
    emoji_id: @emoji_id,
    emoji_name: @emoji_name
  }
end