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?, #hash

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.



1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
# File 'lib/discorb/guild.rb', line 1174

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

#channel -> nil, 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 1161

#description -> String (readonly)

Returns The channel's name.

Returns:

  • (String)

    The channel's name.



1159
1160
1161
# File 'lib/discorb/guild.rb', line 1159

def description
  @description
end

#emoji -> Discorb::Emoji (readonly)

Returns The emoji to display.

Returns:



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

Instance Method Details

#edit(enabled: :unset, channels: :unset, description: :unset, reason: nil) -> Object

Note:

This is an asynchronous method, it will return a Async::Task object. Use Async::Task#wait to get the result.

Note:

This method calls HTTP request.

Note:

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

Edits the welcome screen.

Parameters:

  • enabled (Boolean) (defaults to: :unset)

    Whether the welcome screen is enabled.

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

    The channels to display the welcome screen.

  • description (String) (defaults to: :unset)

    The description of the welcome screen.

  • reason (String) (defaults to: nil)

    The reason for editing the welcome screen.

Raises:



1233
1234
1235
1236
1237
1238
1239
1240
1241
# File 'lib/discorb/guild.rb', line 1233

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

#to_hash -> Hash

Converts the channel to a hash.

Returns:

  • (Hash)

    The hash.

See Also:



1201
1202
1203
1204
1205
1206
1207
1208
# File 'lib/discorb/guild.rb', line 1201

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