class Discordrb::Invite

A Discord invite to a channel

Attributes

channel[R]

@return [InviteChannel] the channel this invite references.

code[R]

@return [String] this invite's code

created_at[R]

@return [Time, nil] when this invite was created, or nil if it's unknown

inviter[R]

@return [User, nil] the user that made this invite. May also be nil if the user can't be determined.

max_age[R]

@return [Integer, nil] the invites max age before it expires, or nil if it's unknown. If the max age is 0, the invite will never expire unless it's deleted.

max_uses[R]

@return [Integer] the amount of uses left on this invite.

member_count[R]

@return [Integer, nil] the amount of members in the server. Will be nil if it has not been resolved.

online_member_count[R]

@return [Integer, nil] the amount of online members in the server. Will be nil if it has not been resolved.

online_user_count[R]

@return [Integer, nil] the amount of online members in the server. Will be nil if it has not been resolved.

revoked[R]

@return [true, false] whether this invite is still valid.

revoked?[R]

@return [true, false] whether this invite is still valid.

server[R]

@return [InviteServer] the server this invite references.

temporary[R]

@return [true, false] whether or not this invite grants temporary membership. If someone joins a server with this invite, they will be removed from the server when they go offline unless they've received a role.

temporary?[R]

@return [true, false] whether or not this invite grants temporary membership. If someone joins a server with this invite, they will be removed from the server when they go offline unless they've received a role.

user[R]

@return [User, nil] the user that made this invite. May also be nil if the user can't be determined.

user_count[R]

@return [Integer, nil] the amount of members in the server. Will be nil if it has not been resolved.

uses[R]

@return [Integer] the amount of uses left on this invite.

Public Class Methods

new(data, bot) click to toggle source

@!visibility private

# File lib/discordrb/data.rb, line 1161
def initialize(data, bot)
  @bot = bot

  @channel = InviteChannel.new(data['channel'], bot)
  @server = InviteServer.new(data['guild'], bot)
  @uses = data['uses']
  @inviter = data['inviter'] ? (@bot.user(data['inviter']['id'].to_i) || User.new(data['inviter'], bot)) : nil
  @temporary = data['temporary']
  @revoked = data['revoked']
  @online_member_count = data['approximate_presence_count']
  @member_count = data['approximate_member_count']
  @max_age = data['max_age']
  @created_at = data['created_at']

  @code = data['code']
end

Public Instance Methods

==(other) click to toggle source

Code based comparison

# File lib/discordrb/data.rb, line 1179
def ==(other)
  other.respond_to?(:code) ? (@code == other.code) : (@code == other)
end
delete(reason = nil) click to toggle source

Deletes this invite @param reason [String] The reason the invite is being deleted.

# File lib/discordrb/data.rb, line 1185
def delete(reason = nil)
  API::Invite.delete(@bot.token, @code, reason)
end
Also aliased as: revoke
inspect() click to toggle source

The inspect method is overwritten to give more useful output

# File lib/discordrb/data.rb, line 1192
def inspect
  "<Invite code=#{@code} channel=#{@channel} uses=#{@uses} temporary=#{@temporary} revoked=#{@revoked} created_at=#{@created_at} max_age=#{@max_age}>"
end
revoke(reason = nil)
Alias for: delete
url() click to toggle source

Creates an invite URL.

# File lib/discordrb/data.rb, line 1197
def url
  "https://discord.gg/#{@code}"
end