Module: OnyxCord::Bot::Invites

Included in:
OnyxCord::Bot
Defined in:
lib/onyxcord/core/bot/invites.rb

Instance Method Summary collapse

Instance Method Details

#accept_invite(invite) ⇒ Object

Makes the bot join an invite to a server.

Parameters:



8
9
10
11
# File 'lib/onyxcord/core/bot/invites.rb', line 8

def accept_invite(invite)
  resolved = invite(invite).code
  REST::Invite.accept(token, resolved)
end

#delete_invite(code) ⇒ Object

Revokes an invite to a server. Will fail unless you have the Manage Server permission. It is recommended that you use Invite#delete instead.

Parameters:



36
37
38
39
# File 'lib/onyxcord/core/bot/invites.rb', line 36

def delete_invite(code)
  invite = resolve_invite_code(code)
  REST::Invite.delete(token, invite)
end

#invite_url(server: nil, permission_bits: nil, redirect_uri: nil, scopes: ['bot']) ⇒ String

Creates an OAuth invite URL that can be used to invite this bot to a particular server.

Parameters:

  • server (Server, nil) (defaults to: nil)

    The server the bot should be invited to, or nil if a general invite should be created.

  • permission_bits (String, Integer) (defaults to: nil)

    Permission bits that should be appended to invite url.

  • redirect_uri (String) (defaults to: nil)

    Redirect URI that should be appended to invite url.

  • scopes (Array<String>) (defaults to: ['bot'])

    Scopes that should be appended to invite url.

Returns:

  • (String)

    the OAuth invite URL.



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/onyxcord/core/bot/invites.rb', line 19

def invite_url(server: nil, permission_bits: nil, redirect_uri: nil, scopes: ['bot'])
  @client_id ||= bot_application.id

  query = URI.encode_www_form({
    client_id: @client_id,
    guild_id: server&.id,
    permissions: permission_bits,
    redirect_uri: redirect_uri,
    scope: scopes.join(' ')
  }.compact)

  "https://discord.com/oauth2/authorize?#{query}"
end