Skip to content

Commit

Permalink
feat: Bot#invite_url - scope & redirect_uri params (#241)
Browse files Browse the repository at this point in the history
Co-authored-by: Birdie <Birdie0@users.noreply.github.com>
  • Loading branch information
Birdie0 and Birdie0 committed Oct 16, 2023
1 parent a873d4e commit 57c1f5c
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions lib/discordrb/bot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -307,13 +307,21 @@ def accept_invite(invite)
# Creates an OAuth invite URL that can be used to invite this bot to a particular server.
# @param server [Server, nil] The server the bot should be invited to, or nil if a general invite should be created.
# @param permission_bits [String, Integer] Permission bits that should be appended to invite url.
# @param redirect_uri [String] Redirect URI that should be appended to invite url.
# @param scopes [Array<String>] Scopes that should be appended to invite url.
# @return [String] the OAuth invite URL.
def invite_url(server: nil, permission_bits: nil)
def invite_url(server: nil, permission_bits: nil, redirect_uri: nil, scopes: ['bot'])
@client_id ||= bot_application.id

server_id_str = server ? "&guild_id=#{server.id}" : ''
permission_bits_str = permission_bits ? "&permissions=#{permission_bits}" : ''
"https://discord.com/oauth2/authorize?&client_id=#{@client_id}#{server_id_str}#{permission_bits_str}&scope=bot"
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

# @return [Hash<Integer => VoiceBot>] the voice connections this bot currently has, by the server ID to which they are connected.
Expand Down

0 comments on commit 57c1f5c

Please sign in to comment.