Class: RubyCord::Guild::WelcomeScreen::Channel

Inherits:
DiscordModel
  • Object
show all
Defined in:
lib/rubycord/guild/welcome_screen.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:



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/rubycord/guild/welcome_screen.rb', line 68

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, RubyCord::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.

  • (RubyCord::Channel)

    The channel to display the welcome screen.



# File 'lib/rubycord/guild/welcome_screen.rb', line 55


#descriptionString (readonly)

Returns The channel's name.

Returns:

  • (String)

    The channel's name.



53
54
55
# File 'lib/rubycord/guild/welcome_screen.rb', line 53

def description
  @description
end

#emojiRubyCord::Emoji (readonly)

Returns The emoji to display.

Returns:



# File 'lib/rubycord/guild/welcome_screen.rb', line 55


Instance Method Details

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

Note:

The arguments of this method are defaultly set to RubyCord::Unset. Specify value to set the value, if not don't specify or specify RubyCord::Unset.

Edits the welcome screen.

Parameters:

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

    Whether the welcome screen is enabled.

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

    The channels to display the welcome screen.

  • description (String) (defaults to: RubyCord::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.



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/rubycord/guild/welcome_screen.rb', line 128

def edit(
  enabled: RubyCord::Unset,
  channels: RubyCord::Unset,
  description: RubyCord::Unset,
  reason: nil
)
  Async do
    payload = {}
    payload[:enabled] = enabled unless enabled == RubyCord::Unset
    payload[:welcome_channels] = channels.map(
      &:to_hash
    ) unless channels == RubyCord::Unset
    payload[:description] = description unless description ==
      RubyCord::Unset
    @client
      .http
      .request(
        RubyCord::Internal::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.



95
96
97
98
99
100
101
102
# File 'lib/rubycord/guild/welcome_screen.rb', line 95

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