Method: Discordrb::Bot#invite_url

Defined in:
lib/discordrb/bot.rb

#invite_url(server: nil, permission_bits: nil) ⇒ String

Creates an OAuth invite URL that can be used to invite this bot to a particular server. Requires the application ID to have been set during initialization.

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 (Integer, String) (defaults to: nil)

    Permission bits that should be appended to invite url.

Returns:

  • (String)

    the OAuth invite URL.



267
268
269
270
271
272
273
# File 'lib/discordrb/bot.rb', line 267

def invite_url(server: nil, permission_bits: nil)
  raise 'No application ID has been set during initialization! Add one as the `application_id` named parameter while creating your bot.' unless @client_id

  server_id_str = server ? "&guild_id=#{server.id}" : ''
  permission_bits_str = permission_bits ? "&permissions=#{permission_bits}" : ''
  "https://discordapp.com/oauth2/authorize?&client_id=#{@client_id}#{server_id_str}#{permission_bits_str}&scope=bot"
end