discordjs / discord.js

A powerful JavaScript library for interacting with the Discord API
https://discord.js.org
Apache License 2.0
25.44k stars 3.97k forks source link

OAuth2API.generateAuthorizationURL type error when generating bot installation URL #10507

Closed boylett closed 3 weeks ago

boylett commented 2 months ago

Which package is this bug report for?

core

Issue description

  1. Create REST instance and set bot token
  2. Create OAuth2API instance and provide rest instance
  3. Call generateAuthorizationURL on the OAuth2API instance, supplying a permissions parameter for bot installation
  4. Observe TypeScript error: Object literal may only specify known properties, and 'permissions' does not exist in type 'RESTOAuth2AuthorizationQuery'.

Additionally, RESTOAuth2BotAuthorizationQuery is available in the documentation, but is not exported by rest/v10/oauth2.ts.

Code sample

import { OAuth2API } from "@discordjs/core";
import { REST } from "@discordjs/rest";

// Set up the Discord REST client
const rest = discord_bot_token && (
  new REST().setToken(discord_bot_token)
);

// Bot installation link
const bot_install_url = rest && (
  new OAuth2API(rest).generateAuthorizationURL({
    permissions: "8", // TypeError: Object literal may only specify known properties, and 'permissions' does not exist in type 'RESTOAuth2AuthorizationQuery'.
    client_id: discord_client_id || "",
    response_type: "code",
    scope: [
      "bot",
      "guilds",
      "guilds.members.read",
      "identify",
      "messages.read",
    ].join(" "),
  })
);

Versions

Issue priority

Low (slightly annoying)

Which partials do you have configured?

No Partials

Which gateway intents are you subscribing to?

No Intents

I have tested this issue on a development release

Jiralite commented 2 months ago

The method you are using is generating an authorisation URL (code grant) which you can see by visiting the documentation associated with the method.

It seems what you want is an application invite URL. That is governed by the RESTOAuth2BotAuthorizationQuery type and is not in the core package as it is not an API method.

Jiralite commented 2 months ago

Sorry—closed by accident. Leaving open to see if anyone else has any thoughts just in case.

boylett commented 3 weeks ago

I made a mistake here so happy to close this issue. Sorry to waste your time.

FFR: To generate an authorization URL we should create it manually as per documentation. (Docs for bot link generation)