discordjs / discord.js

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

Types incompatible with `discord.js` in `SlashCommandBuilder` #7962

Closed Mighty683 closed 2 years ago

Mighty683 commented 2 years ago

Which package is this bug report for?

builders

Issue description

Client.application.commands.set is using RESTPostAPIApplicationCommandsJSONBody type from discord-api-types/rest/v9 but SlashCommandBuilder.toJSON is using RESTPostAPIApplicationCommandsJSONBody from discord-api-types/rest/v10, which is causing type errors when I try to use SlashCommandBuilder to build an command for application.

Packages versions which I use:

"discord-api-types": "0.33.0",
"discord.js": "13.7.0",
"@discordjs/rest": "0.4.1",

Code sample

const client = new Discord.Client({...});
// configure client
const commandBuilder = new SlashCommandBuilder();
// build command
const commandBody = commandBuilder.toJSON();

client.application.commands.set([commandBody]); // Typescript will throw 
// workaround for typescript throwing error
client.application.commands.set([commandBody as ApplicationCommandDataResolvable]);

Package version

13.7.0

Node.js version

16.13

Operating system

Alpine Linux Docker Container

Priority this issue should have

Medium (should be fixed soon)

Which partials do you have configured?

Not applicable (subpackage bug), No Partials

Which gateway intents are you subscribing to?

Guilds

I have tested this issue on a development release

No response

kyranet commented 2 years ago

discord.js v13.7.0 works best with discord-api-types 0.30.0, see here, and you must as well use discord-api-types/v9 instead of discord-api-types/v10 as well, since it's the version both its http and ws handlers use by default. @discordjs/rest v4.0.1 uses discord-api-types 0.29.0, which is a mismatching version.

To get around this version conflict, you can use npm's overrides or Yarn's resolutions to set the version of discord-api-types to 0.30.0.

Warning @discordjs/rest v4.0.1 uses /v10, not /v9 like discord.js v13.7.0 does. This means that you cannot use types interchangeably. Please keep this in mind when building your bot.

If you desire to use discord-api-types 0.33.0 (and by extension, also latest /rest and /builders), please switch to the development versions. At the time of writing, the very latest versions you can get (which I can confirm they work) are:

To help updating to the development version (named v14), we also have a migration guide PR, you can also see the preview here.

I'll close this as wontfix because it's not an issue the library can resolve, but rather an issue with conflicting versions, which you as a user can fix.