class Discorb::WelcomeScreen::Channel
Represents a channel to display the welcome screen.
Attributes
@return [String] The channel's name.
Public Class Methods
Initialize a new welcome screen channel.
@param [Discorb::TextChannel] channel The channel to display the welcome screen. @param [String] description The channel's name. @param [Discorb::Emoji] emoji The emoji to display.
# 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
Public Instance Methods
# File lib/discorb/guild.rb, line 1210 def channel @screen.guild.channels[@channel_id] end
Edits the welcome screen. @macro async @macro http @macro edit
@param [Boolean] enabled Whether the welcome screen is enabled. @param [Array<Discorb::WelcomeScreen::Channel>] channels The channels to display the welcome screen. @param [String] description The description of the welcome screen. @param [String] reason The reason for editing the welcome screen.
# 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.http.patch("/guilds/#{@guild.id}/welcome-screen", payload, audit_log_reason: reason).wait end end
# File lib/discorb/guild.rb, line 1214 def emoji if @emoji_id.nil? UnicodeEmoji.new(@emoji_name) else @screen.guild.emojis[@emoji_id] end end
Converts the channel to a hash.
@return [Hash] The hash. @see discord.com/developers/docs/resources/guild#welcome-screen-object
# 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