Class: Discordrb::Server

Inherits:
Object
  • Object
show all
Includes:
IDObject, ServerAttributes
Defined in:
lib/discordrb/data.rb

Overview

A server on Discord

Constant Summary collapse

VERIFICATION_LEVELS =

A map of possible server verification levels to symbol names

{
  none: 0,
  low: 1,
  medium: 2,
  high: 3,
  very_high: 4
}.freeze
NOTIFICATION_LEVELS =

A map of possible message notification levels to symbol names

{
  all_messages: 0,
  only_mentions: 1
}.freeze
FILTER_LEVELS =

A map of possible content filter levels to symbol names

{
  disabled: 0,
  members_without_roles: 1,
  all_members: 2
}.freeze

Instance Attribute Summary collapse

Attributes included from ServerAttributes

#icon_id, #name

Attributes included from IDObject

#id

Instance Method Summary collapse

Methods included from ServerAttributes

#icon_url

Methods included from IDObject

#==, #creation_time, synthesise

Instance Attribute Details

#afk_timeoutInteger

Returns the amount of time after which a voice user gets moved into the AFK channel, in seconds.

Returns:

  • (Integer)

    the amount of time after which a voice user gets moved into the AFK channel, in seconds.


2614
2615
2616
# File 'lib/discordrb/data.rb', line 2614

def afk_timeout
  @afk_timeout
end

#channelsArray<Channel> (readonly)

Returns an array of all the channels (text and voice) on this server.

Returns:

  • (Array<Channel>)

    an array of all the channels (text and voice) on this server.


2583
2584
2585
# File 'lib/discordrb/data.rb', line 2583

def channels
  @channels
end

#default_message_notificationsSymbol

Returns the default message notifications settings of the server (:all = 'All messages', :mentions = 'Only @mentions').

Returns:

  • (Symbol)

    the default message notifications settings of the server (:all = 'All messages', :mentions = 'Only @mentions').


2611
2612
2613
# File 'lib/discordrb/data.rb', line 2611

def default_message_notifications
  @default_message_notifications
end

#emojiHash<Integer => Emoji> (readonly) Also known as: emojis

Returns a hash of all the emoji available on this server.

Returns:

  • (Hash<Integer => Emoji>)

    a hash of all the emoji available on this server.


2589
2590
2591
# File 'lib/discordrb/data.rb', line 2589

def emoji
  @emoji
end

#explicit_content_filterSymbol Also known as: content_filter_level

Returns the explicit content filter level of the server (:none = 'Don't scan any messages.', :exclude_roles = 'Scan messages for members without a role.', :all = 'Scan messages sent by all members.').

Returns:

  • (Symbol)

    the explicit content filter level of the server (:none = 'Don't scan any messages.', :exclude_roles = 'Scan messages for members without a role.', :all = 'Scan messages sent by all members.').


2607
2608
2609
# File 'lib/discordrb/data.rb', line 2607

def explicit_content_filter
  @explicit_content_filter
end

#featuresArray<Symbol> (readonly)

Returns the features of the server (eg. "INVITE_SPLASH").

Returns:

  • (Array<Symbol>)

    the features of the server (eg. "INVITE_SPLASH")


2598
2599
2600
# File 'lib/discordrb/data.rb', line 2598

def features
  @features
end

#largetrue, false (readonly) Also known as: large?

it means the members list may be inaccurate for a couple seconds after starting up the bot.

Returns:

  • (true, false)

    whether or not this server is large (members > 100). If it is,


2594
2595
2596
# File 'lib/discordrb/data.rb', line 2594

def large
  @large
end

#member_countInteger (readonly)

Returns the absolute number of members on this server, offline or not.

Returns:

  • (Integer)

    the absolute number of members on this server, offline or not.


2601
2602
2603
# File 'lib/discordrb/data.rb', line 2601

def member_count
  @member_count
end

#ownerMember

Returns The server owner.

Returns:

  • (Member)

    The server owner.


2580
2581
2582
# File 'lib/discordrb/data.rb', line 2580

def owner
  @owner
end

#region_idString (readonly)

Returns the ID of the region the server is on (e.g. amsterdam).

Returns:

  • (String)

    the ID of the region the server is on (e.g. amsterdam).


2577
2578
2579
# File 'lib/discordrb/data.rb', line 2577

def region_id
  @region_id
end

#rolesArray<Role> (readonly)

Returns an array of all the roles created on this server.

Returns:

  • (Array<Role>)

    an array of all the roles created on this server.


2586
2587
2588
# File 'lib/discordrb/data.rb', line 2586

def roles
  @roles
end

#verification_levelSymbol

Returns the verification level of the server (:none = none, :low = 'Must have a verified email on their Discord account', :medium = 'Has to be registered with Discord for at least 5 minutes', :high = 'Has to be a member of this server for at least 10 minutes', :very_high = 'Must have a verified phone on their Discord account').

Returns:

  • (Symbol)

    the verification level of the server (:none = none, :low = 'Must have a verified email on their Discord account', :medium = 'Has to be registered with Discord for at least 5 minutes', :high = 'Has to be a member of this server for at least 10 minutes', :very_high = 'Must have a verified phone on their Discord account').


2604
2605
2606
# File 'lib/discordrb/data.rb', line 2604

def verification_level
  @verification_level
end

#voice_statesHash<Integer => VoiceState> (readonly)

Returns the hash (user ID => voice state) of voice states of members on this server.

Returns:

  • (Hash<Integer => VoiceState>)

    the hash (user ID => voice state) of voice states of members on this server


2617
2618
2619
# File 'lib/discordrb/data.rb', line 2617

def voice_states
  @voice_states
end

Instance Method Details

#add_member_using_token(user, access_token, nick: nil, roles: [], deaf: false, mute: false) ⇒ Member

Note:

Your bot must be present in this server, and have permission to create instant invites for this to work.

Adds a member to this guild that has granted this bot's application an OAuth2 access token with the guilds.join scope. For more information about Discord's OAuth2 implementation, see: https://discordapp.com/developers/docs/topics/oauth2

Parameters:

  • user (Integer, User, #resolve_id)

    the user, or ID of the user to add to this server

  • access_token (String)

    the OAuth2 Bearer token that has been granted the guilds.join scope

  • nick (String) (defaults to: nil)

    the nickname to give this member upon joining

  • roles (Role, Array<Integer, Role, #resolve_id>) (defaults to: [])

    the role (or roles) to give this member upon joining

  • deaf (true, false) (defaults to: false)

    whether this member will be server deafened upon joining

  • mute (true, false) (defaults to: false)

    whether this member will be server muted upon joining

Returns:

  • (Member)

    the created member


2748
2749
2750
2751
2752
2753
# File 'lib/discordrb/data.rb', line 2748

def add_member_using_token(user, access_token, nick: nil, roles: [], deaf: false, mute: false)
  user_id = user.resolve_id
  roles = roles.is_a?(Array) ? roles.map(&:resolve_id) : [roles.resolve_id]
  response = JSON.parse(API::Server.add_member(@bot.token, @id, user_id, access_token, nick, roles, deaf, mute))
  add_member Member.new(response, self, @bot)
end

#afk_channelChannel?

Returns the AFK voice channel of this server, or nil if none is set.

Returns:

  • (Channel, nil)

    the AFK voice channel of this server, or nil if none is set


3155
3156
3157
# File 'lib/discordrb/data.rb', line 3155

def afk_channel
  @bot.channel(@afk_channel_id) if @afk_channel_id
end

#afk_channel=(afk_channel) ⇒ Object

Sets the server's AFK channel.

Parameters:

  • afk_channel (Channel, nil)

    The new AFK channel, or nil if there should be none set.


3044
3045
3046
# File 'lib/discordrb/data.rb', line 3044

def afk_channel=(afk_channel)
  update_server_data(afk_channel_id: afk_channel.resolve_id)
end

#any_emoji?true, false Also known as: has_emoji?, emoji?

Returns whether this server has any emoji or not.

Returns:

  • (true, false)

    whether this server has any emoji or not.


3115
3116
3117
# File 'lib/discordrb/data.rb', line 3115

def any_emoji?
  @emoji.any?
end

#available_voice_regionsArray<VoiceRegion>

Returns collection of available voice regions to this guild.

Returns:

  • (Array<VoiceRegion>)

    collection of available voice regions to this guild


3009
3010
3011
3012
3013
3014
3015
3016
# File 'lib/discordrb/data.rb', line 3009

def available_voice_regions
  return @available_voice_regions if @available_voice_regions

  @available_voice_regions = {}

  data = JSON.parse API::Server.regions(@bot.token, @id)
  @available_voice_regions = data.map { |e| VoiceRegion.new e }
end

#ban(user, message_days = 0, reason: nil) ⇒ Object

Bans a user from this server.

Parameters:

  • user (User, #resolve_id)

    The user to ban.

  • message_days (Integer) (defaults to: 0)

    How many days worth of messages sent by the user should be deleted.

  • reason (String) (defaults to: nil)

    The reason the user is being banned.


2961
2962
2963
# File 'lib/discordrb/data.rb', line 2961

def ban(user, message_days = 0, reason: nil)
  API::Server.ban_user(@bot.token, @id, user.resolve_id, message_days, reason)
end

#bansArray<ServerBan>

Returns a list of banned users on this server and the reason they were banned.

Returns:

  • (Array<ServerBan>)

    a list of banned users on this server and the reason they were banned.


2950
2951
2952
2953
2954
2955
# File 'lib/discordrb/data.rb', line 2950

def bans
  response = JSON.parse(API::Server.bans(@bot.token, @id))
  response.map do |e|
    ServerBan.new(self, User.new(e['user'], @bot), e['reason'])
  end
end

#begin_prune(days, reason = nil) ⇒ Integer Also known as: prune

Prunes (kicks) an amount of members for inactivity

Parameters:

  • days (Integer)

    the number of days to consider for inactivity (between 1 and 30)

  • reason (String) (defaults to: nil)

    The reason the for the prune.

Returns:

  • (Integer)

    the number of members removed at the end of the operation

Raises:

  • (ArgumentError)

    if days is not between 1 and 30 (inclusive)


2771
2772
2773
2774
2775
2776
# File 'lib/discordrb/data.rb', line 2771

def begin_prune(days, reason = nil)
  raise ArgumentError, 'Days must be between 1 and 30' unless days.between?(1, 30)

  response = JSON.parse API::Server.begin_prune(@bot.token, @id, days, reason)
  response['pruned']
end

#create_channel(name, type = 0, bitrate: nil, user_limit: nil, permission_overwrites: [], nsfw: false, reason: nil) ⇒ Channel

Creates a channel on this server with the given name.

Parameters:

  • name (String)

    Name of the channel to create

  • type (Integer) (defaults to: 0)

    Type of channel to create (0: text, 2: voice)

  • bitrate (Integer) (defaults to: nil)

    the bitrate of this channel, if it will be a voice channel

  • user_limit (Integer) (defaults to: nil)

    the user limit of this channel, if it will be a voice channel

  • permission_overwrites (Array<Hash>, Array<Overwrite>) (defaults to: [])

    permission overwrites for this channel

  • nsfw (true, false) (defaults to: false)

    whether this channel should be created as nsfw

  • reason (String) (defaults to: nil)

    The reason the for the creation of this channel.

Returns:

  • (Channel)

    the created channel.

Raises:

  • (ArgumentError)

    if type is not 0 or 2


2914
2915
2916
2917
2918
2919
# File 'lib/discordrb/data.rb', line 2914

def create_channel(name, type = 0, bitrate: nil, user_limit: nil, permission_overwrites: [], nsfw: false, reason: nil)
  raise ArgumentError, 'Channel type must be either 0 (text) or 2 (voice)!' unless [0, 2].include?(type)
  permission_overwrites.map! { |e| e.is_a?(Overwrite) ? e.to_hash : e }
  response = API::Server.create_channel(@bot.token, @id, name, type, bitrate, user_limit, permission_overwrites, nsfw, reason)
  Channel.new(JSON.parse(response), @bot)
end

#create_role(name: 'new role', colour: 0, hoist: false, mentionable: false, permissions: 104_324_161, reason: nil) ⇒ Role

Creates a role on this server which can then be modified. It will be initialized with the regular role defaults the client uses unless specified, i.e. name is "new role", permissions are the default, colour is the default etc.

Parameters:

  • name (String) (defaults to: 'new role')

    Name of the role to create

  • colour (Integer, ColourRGB, #combined) (defaults to: 0)

    The roles colour

  • hoist (true, false) (defaults to: false)
  • mentionable (true, false) (defaults to: false)
  • permissions (Integer, Array<Symbol>, Permissions, #bits) (defaults to: 104_324_161)

    The permissions to write to the new role.

  • reason (String) (defaults to: nil)

    The reason the for the creation of this role.

Returns:

  • (Role)

    the created role.


2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
# File 'lib/discordrb/data.rb', line 2931

def create_role(name: 'new role', colour: 0, hoist: false, mentionable: false, permissions: 104_324_161, reason: nil)
  colour = colour.respond_to?(:combined) ? colour.combined : colour

  permissions = if permissions.is_a?(Array)
                  Permissions.bits(permissions)
                elsif permissions.respond_to?(:bits)
                  permissions.bits
                else
                  permissions
                end

  response = API::Server.create_role(@bot.token, @id, name, colour, hoist, mentionable, permissions, reason)

  role = Role.new(JSON.parse(response), @bot, self)
  @roles << role
  role
end

#default_channelChannel? Also known as: general_channel

The default channel is the text channel on this server with the highest position that the client has Read Messages permission on.

Returns:

  • (Channel, nil)

    The default channel on this server, or nil if there are no channels that the bot can read


2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
# File 'lib/discordrb/data.rb', line 2653

def default_channel
  text_channels.sort_by { |e| [e.position, e.id] }.find do |e|
    overwrite = e.permission_overwrites[id]
    if overwrite
      overwrite.allow.read_messages || overwrite.allow.read_messages == overwrite.deny.read_messages
    else
      everyone_role.permissions.read_messages
    end
  end
end

#deleteObject

Deletes this server. Be aware that this is permanent and impossible to undo, so be careful!


2987
2988
2989
# File 'lib/discordrb/data.rb', line 2987

def delete
  API::Server.delete(@bot.token, @id)
end

#embed_channelChannel? Also known as: widget_channel

Returns the channel the server embed will make a invite for.

Returns:

  • (Channel, nil)

    the channel the server embed will make a invite for.


2720
2721
2722
2723
# File 'lib/discordrb/data.rb', line 2720

def embed_channel
  update_data if @embed_enabled.nil?
  @bot.channel(@embed_channel_id) if @embed_channel_id
end

#embed_enabled?true, false Also known as: widget_enabled, widget?, embed?

Returns whether or not the server has widget enabled.

Returns:

  • (true, false)

    whether or not the server has widget enabled


2711
2712
2713
2714
# File 'lib/discordrb/data.rb', line 2711

def embed_enabled?
  update_data if @embed_enabled.nil?
  @embed_enabled
end

#everyone_roleRole

Returns The @everyone role on this server.

Returns:

  • (Role)

    The @everyone role on this server


2667
2668
2669
# File 'lib/discordrb/data.rb', line 2667

def everyone_role
  role(@id)
end

#icon=(icon) ⇒ Object

Sets the server's icon.

Parameters:

  • icon (String, #read)

    The new icon, in base64-encoded JPG format.


3032
3033
3034
3035
3036
3037
3038
3039
3040
# File 'lib/discordrb/data.rb', line 3032

def icon=(icon)
  if icon.respond_to? :read
    icon_string = 'data:image/jpg;base64,'
    icon_string += Base64.strict_encode64(icon.read)
    update_server_data(icon: icon_string)
  else
    update_server_data(icon: icon)
  end
end

#inspectObject

The inspect method is overwritten to give more useful output


3213
3214
3215
# File 'lib/discordrb/data.rb', line 3213

def inspect
  "<Server name=#{@name} id=#{@id} large=#{@large} region=#{@region} owner=#{@owner} afk_channel_id=#{@afk_channel_id} system_channel_id=#{@system_channel_id} afk_timeout=#{@afk_timeout}>"
end

#integrationsArray<Integration>

Returns an array of all the integrations connected to this server.

Returns:

  • (Array<Integration>)

    an array of all the integrations connected to this server.


2705
2706
2707
2708
# File 'lib/discordrb/data.rb', line 2705

def integrations
  integration = JSON.parse(API::Server.integrations(@bot.token, @id))
  integration.map { |element| Integration.new(element, @bot, self) }
end

#invitesArray<Invite>

Requests a list of Invites to the server

Returns:

  • (Array<Invite>)

    invites to the server.


3131
3132
3133
3134
# File 'lib/discordrb/data.rb', line 3131

def invites
  invites = JSON.parse(API::Server.invites(@bot.token, @id))
  invites.map { |invite| Invite.new(invite, @bot) }
end

#kick(user, reason = nil) ⇒ Object

Kicks a user from this server.

Parameters:

  • user (User, #resolve_id)

    The user to kick.

  • reason (String) (defaults to: nil)

    The reason the user is being kicked.


2975
2976
2977
# File 'lib/discordrb/data.rb', line 2975

def kick(user, reason = nil)
  API::Server.remove_member(@bot.token, @id, user.resolve_id, reason)
end

#leaveObject

Leave the server


2992
2993
2994
# File 'lib/discordrb/data.rb', line 2992

def leave
  API::User.leave_server(@bot.token, @id)
end

#member(id, request = true) ⇒ Object

Gets a member on this server based on user ID

Parameters:

  • id (Integer)

    The user ID to look for

  • request (true, false) (defaults to: true)

    Whether the member should be requested from Discord if it's not cached


2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
# File 'lib/discordrb/data.rb', line 2681

def member(id, request = true)
  id = id.resolve_id
  return @members[id] if member_cached?(id)
  return nil unless request

  member = @bot.member(self, id)
  @members[id] = member
rescue
  nil
end

#membersArray<Member> Also known as: users

Returns an array of all the members on this server.

Returns:

  • (Array<Member>)

    an array of all the members on this server.


2693
2694
2695
2696
2697
2698
2699
2700
# File 'lib/discordrb/data.rb', line 2693

def members
  return @members.values if @chunked

  @bot.debug("Members for server #{@id} not chunked yet - initiating")
  @bot.request_chunks(@id)
  sleep 0.05 until @chunked
  @members.values
end

#move(user, channel) ⇒ Object

Forcibly moves a user into a different voice channel. Only works if the bot has the permission needed.

Parameters:


2982
2983
2984
# File 'lib/discordrb/data.rb', line 2982

def move(user, channel)
  API::Server.update_member(@bot.token, @id, user.resolve_id, channel_id: channel.resolve_id)
end

#name=(name) ⇒ Object

Sets the server's name.

Parameters:

  • name (String)

    The new server name.


3004
3005
3006
# File 'lib/discordrb/data.rb', line 3004

def name=(name)
  update_server_data(name: name)
end

#online_members(include_idle: false, include_bots: true) ⇒ Array<Member> Also known as: online_users

Returns an array of online members on this server.

Parameters:

  • include_idle (true, false) (defaults to: false)

    Whether to count idle members as online.

  • include_bots (true, false) (defaults to: true)

    Whether to include bot accounts in the count.

Returns:

  • (Array<Member>)

    an array of online members on this server.


2729
2730
2731
2732
2733
# File 'lib/discordrb/data.rb', line 2729

def online_members(include_idle: false, include_bots: true)
  @members.values.select do |e|
    ((include_idle ? e.idle? : false) || e.online?) && (include_bots ? true : !e.bot_account?)
  end
end

#prune_count(days) ⇒ Integer

Returns the amount of members that are candidates for pruning

Parameters:

  • days (Integer)

    the number of days to consider for inactivity

Returns:

  • (Integer)

    number of members to be removed

Raises:

  • (ArgumentError)

    if days is not between 1 and 30 (inclusive)


2759
2760
2761
2762
2763
2764
# File 'lib/discordrb/data.rb', line 2759

def prune_count(days)
  raise ArgumentError, 'Days must be between 1 and 30' unless days.between?(1, 30)

  response = JSON.parse API::Server.prune_count(@bot.token, @id, days)
  response['pruned']
end

#regionVoiceRegion?

Note:

This may return nil if this server's voice region is deprecated.

Returns voice region data for this server's region.

Returns:

  • (VoiceRegion, nil)

    voice region data for this server's region


3020
3021
3022
# File 'lib/discordrb/data.rb', line 3020

def region
  available_voice_regions.find { |e| e.id == @region_id }
end

#region=(region) ⇒ Object

Moves the server to another region. This will cause a voice interruption of at most a second.

Parameters:

  • region (String)

    The new region the server should be in.


3026
3027
3028
# File 'lib/discordrb/data.rb', line 3026

def region=(region)
  update_server_data(region: region.to_s)
end

#role(id) ⇒ Object

Gets a role on this server based on its ID.

Parameters:


2673
2674
2675
2676
# File 'lib/discordrb/data.rb', line 2673

def role(id)
  id = id.resolve_id
  @roles.find { |e| e.id == id }
end

#splash=(splash_hash) ⇒ Object

Sets the server splash

Parameters:

  • splash_hash (String)

    The splash hash


3095
3096
3097
# File 'lib/discordrb/data.rb', line 3095

def splash=(splash_hash)
  update_server_data(splash: splash_hash)
end

#splash_idString

Returns the hexadecimal ID used to identify this server's splash image for their VIP invite page.

Returns:

  • (String)

    the hexadecimal ID used to identify this server's splash image for their VIP invite page.


2813
2814
2815
# File 'lib/discordrb/data.rb', line 2813

def splash_id
  @splash_id ||= JSON.parse(API::Server.resolve(@bot.token, @id))['splash']
end

#splash_urlString?

Returns the splash image URL for the server's VIP invite page. nil if there is no splash image.

Returns:

  • (String, nil)

    the splash image URL for the server's VIP invite page. nil if there is no splash image.


2819
2820
2821
2822
2823
# File 'lib/discordrb/data.rb', line 2819

def splash_url
  splash_id if @splash_id.nil?
  return nil unless @splash_id
  API.splash_url(@id, @splash_id)
end

#system_channelChannel?

Returns the system channel (used for automatic welcome messages) of a server, or nil if none is set.

Returns:

  • (Channel, nil)

    the system channel (used for automatic welcome messages) of a server, or nil if none is set


3160
3161
3162
# File 'lib/discordrb/data.rb', line 3160

def system_channel
  @bot.channel(@system_channel_id) if @system_channel_id
end

#system_channel=(system_channel) ⇒ Object

Sets the server's system channel.

Parameters:


3050
3051
3052
# File 'lib/discordrb/data.rb', line 3050

def system_channel=(system_channel)
  update_server_data(system_channel_id: system_channel.resolve_id)
end

#text_channelsArray<Channel>

Returns an array of text channels on this server.

Returns:

  • (Array<Channel>)

    an array of text channels on this server


2781
2782
2783
# File 'lib/discordrb/data.rb', line 2781

def text_channels
  @channels.select(&:text?)
end

#unban(user, reason = nil) ⇒ Object

Unbans a previously banned user from this server.

Parameters:

  • user (User, #resolve_id)

    The user to unban.

  • reason (String) (defaults to: nil)

    The reason the user is being unbanned.


2968
2969
2970
# File 'lib/discordrb/data.rb', line 2968

def unban(user, reason = nil)
  API::Server.unban_user(@bot.token, @id, user.resolve_id, reason)
end

#voice_channelsArray<Channel>

Returns an array of voice channels on this server.

Returns:

  • (Array<Channel>)

    an array of voice channels on this server


2786
2787
2788
# File 'lib/discordrb/data.rb', line 2786

def voice_channels
  @channels.select(&:voice?)
end

#webhooksArray<Webhook>

Requests a list of Webhooks on the server

Returns:

  • (Array<Webhook>)

    webhooks on the server.


3124
3125
3126
3127
# File 'lib/discordrb/data.rb', line 3124

def webhooks
  webhooks = JSON.parse(API::Server.webhooks(@bot.token, @id))
  webhooks.map { |webhook| Webhook.new(webhook, @bot) }
end

#widget_banner_url(style) ⇒ String?

Returns the widget banner URL to the server that displays the amount of online members, server icon and server name in a stylish way. nil if the widget is not enabled.

Parameters:

  • style (Symbol)

    The style the picture should have. Possible styles are:

    • :banner1 creates a rectangular image with the server name, member count and icon, a "Powered by Discord" message on the bottom and an arrow on the right.
    • :banner2 creates a less tall rectangular image that has the same information as banner1, but the Discord logo on the right - together with the arrow and separated by a diagonal separator.
    • :banner3 creates an image similar in size to banner1, but it has the arrow in the bottom part, next to the Discord logo and with a "Chat now" text.
    • :banner4 creates a tall, almost square, image that prominently features the Discord logo at the top and has a "Join my server" in a pill-style button on the bottom. The information about the server is in the same format as the other three banner styles.
    • :shield creates a very small, long rectangle, of the style you'd find at the top of GitHub README.md files. It features a small version of the Discord logo at the left and the member count at the right.

Returns:

  • (String, nil)

    the widget banner URL to the server that displays the amount of online members, server icon and server name in a stylish way. nil if the widget is not enabled.


2806
2807
2808
2809
2810
# File 'lib/discordrb/data.rb', line 2806

def widget_banner_url(style)
  update_data if @embed_enabled.nil?
  return unless @embed_enabled
  API.widget_url(@id, style)
end

#widget_urlString?

Returns the widget URL to the server that displays the amount of online members in a stylish way. nil if the widget is not enabled.

Returns:

  • (String, nil)

    the widget URL to the server that displays the amount of online members in a stylish way. nil if the widget is not enabled.


2792
2793
2794
2795
2796
# File 'lib/discordrb/data.rb', line 2792

def widget_url
  update_data if @embed_enabled.nil?
  return unless @embed_enabled
  API.widget_url(@id)
end