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

Type typo for CommandInteractionOptionResolver #7311

Closed H01001000 closed 2 years ago

H01001000 commented 2 years ago

Which package is this bug report for?

discord.js

Issue description

(all getter I mention below is not a real getter but a function to get something) when using interaction, getting the following

on interaction.options will throw a TypeError This is due to getting them will involve _getTypedOption which check if the type is correct

when the interaction is created, the options will be transformed using transformOption, which it will add a type property that is typed using discord-api-types v9

The issue is the type passed by the getter and the discord-api-types v9 are different, the type name in the getter is all cap, while discord-api-types are cap only for the first letter. USER (discord-api-types) User (getter)

This issue will make all interactions using the above getter will not work and throw a type error

Code sample

Deploy following command (example from discordjs guide https://github.com/discordjs/guide/blob/main/code-samples/creating-your-bot/command-handling/commands/avatar.js)

new SlashCommandBuilder()
        .setName('avatar')
        .setDescription('Get the avatar URL of the selected user, or your own avatar.')
        .addUserOption((option) => option.setName('target').setDescription('The user\'s avatar to show'))

Run the following

client.on('interactionCreate', async (interaction) => {
    if (!interaction.isCommand()) return;
    interaction.options.getUser('target');
});

Package version

14.0.0-dev

Node.js version

v16.13.1

Operating system

Windows 10 Pro 19042.1466

Priority this issue should have

High (immediate attention needed)

Which partials do you have configured?

No Partials

Which gateway intents are you subscribing to?

GUILDS, GUILD_MEMBERS, GUILD_INTEGRATIONS, GUILD_MESSAGES

ImRodry commented 2 years ago

This should be fixed as of #7290 but dev releases are currently unusable so I recommend waiting until a builders release to use the latest versions