class Discorb::Guild::Widget
Represents a guild widget.
Attributes
channel_id[R]
@return [Discorb::Snowflake] The channel ID.
enable?[R]
@return [Boolean] Whether the widget is enabled.
enabled[R]
@return [Boolean] Whether the widget is enabled.
enabled?[R]
@return [Boolean] Whether the widget is enabled.
guild_id[R]
@return [Discorb::Snowflake] The guild ID.
Public Class Methods
new(client, guild_id, data)
click to toggle source
@!visibility private
# File lib/discorb/guild.rb, line 959 def initialize(client, guild_id, data) @client = client @enabled = data[:enabled] @guild_id = Snowflake.new(guild_id) @channel_id = Snowflake.new(data[:channel_id]) end
Public Instance Methods
channel()
click to toggle source
# File lib/discorb/guild.rb, line 966 def channel @client.channels[@channel_id] end
edit(enabled: nil, channel: nil, reason: nil)
click to toggle source
Edit the widget. @macro async @macro http @macro edit
@param [Boolean] enabled Whether the widget is enabled. @param [Discorb::GuildChannel] channel The channel. @param [String] reason The reason for editing the widget.
# File lib/discorb/guild.rb, line 980 def edit(enabled: nil, channel: nil, reason: nil) Async do payload = {} payload[:enabled] = enabled unless enabled.nil? payload[:channel_id] = channel.id if channel_id @client.http.patch("/guilds/#{@guild_id}/widget", payload, audit_log_reason: reason).wait end end
Also aliased as: modify
iframe(theme: "dark", width: 350, height: 500)
click to toggle source
Return iframe HTML of the widget.
@param [“dark”, “light”] theme The theme of the widget. @param [Integer] width The width of the widget. @param [Integer] height The height of the widget.
@return [String] The iframe HTML.
# File lib/discorb/guild.rb, line 1004 def iframe(theme: "dark", width: 350, height: 500) [ %(<iframe src="https://canary.discord.com/widget?id=#{@guild_id}&theme=#{theme}" width="#{width}" height="#{height}"), %(allowtransparency="true" frameborder="0" sandbox="allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts"></iframe>), ].join end
json_url()
click to toggle source
# File lib/discorb/guild.rb, line 991 def json_url "#{Discorb::API_BASE_URL}/guilds/#{@guild_id}/widget.json" end