Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot add user option when using localizations #10347

Closed
feenko opened this issue Jun 12, 2024 · 3 comments
Closed

Cannot add user option when using localizations #10347

feenko opened this issue Jun 12, 2024 · 3 comments
Labels

Comments

@feenko
Copy link

feenko commented Jun 12, 2024

Which package is this bug report for?

discord.js

Issue description

  1. Create a SlashCommandBuilder with a subcommand and user option.
  2. Add localization to name and description
  3. See this error:
error: Invalid Form Body
2.options[0][TAG_FIELD_MISSING]: Field "type" is required to determine the model type.

Code sample

new SlashCommandBuilder()
    .setName('info')
    .setDescription('Shows information')
    .setDescriptionLocalizations({
        pl: 'Pokazuje informacje',
    })
    .addSubcommand((subcommand) =>
        subcommand
            .setName('user')
            .setDescription('Shows information about the user')
            .setDescriptionLocalizations({
                pl: 'Pokazuje informacje o użytkowniku',
            })
            .addUserOption((option) =>
                option
                    .setName('user')
                    .setNameLocalizations({ // This errors
                        pl: 'użytkownik',
                    })
                    .setDescription(
                        'The user to show information about',
                    )
                    .setDescriptionLocalizations({ // This errors as well
                        pl: 'Użytkownik, o którym chcesz zobaczyć informacje',
                    }),
            ),
    )

Versions

  • discord.js 14.15.3
  • bun 1.1.12

Issue priority

Medium (should be fixed soon)

Which partials do you have configured?

User, Channel, GuildMember, Message, Reaction, GuildScheduledEvent, ThreadMember

Which gateway intents are you subscribing to?

Guilds, GuildMembers, GuildModeration, GuildEmojisAndStickers, GuildIntegrations, GuildWebhooks, GuildInvites, GuildVoiceStates, GuildPresences, GuildMessages, GuildMessageReactions, GuildMessageTyping, DirectMessages, DirectMessageReactions, DirectMessageTyping, MessageContent, GuildScheduledEvents, AutoModerationConfiguration, AutoModerationExecution, GuildMessagePolls, DirectMessagePolls

I have tested this issue on a development release

No response

@Jiralite
Copy link
Member

Please show what you are doing with this builder (what you did with this builder to get that error).

@feenko
Copy link
Author

feenko commented Jun 12, 2024

Please show what you are doing with this builder (what you did with this builder to get that error).

I just load it, everything works fine until i add translations for a user option

    private async loadCommands() {
        const commandFiles = this.findCommandFiles();

        for (const file of commandFiles) {
            const command = await import(`../commands/${file}`);
            const commandInstance = new command.default();
            const commandCategory = (file as string).split('/')[0];

            const commandData = {
                ...commandInstance.data,
                category: commandCategory,
            };

            commandInstance.data = commandData;

            client.commands.set(commandInstance.data.name, commandInstance);
        }

        client.on('ready', () => {
            client.application?.commands.set(
                client.commands.map((c) => c.data),
            );
        });
    }

@Jiralite
Copy link
Member

This is a code sample from your comments. It works:

import { Client, SlashCommandBuilder } from "discord.js";

const client = new Client({ intents: 0 });

client.on("ready", async () => {
	const command = new SlashCommandBuilder()
		.setName("info")
		.setDescription("Shows information")
		.setDescriptionLocalizations({
			pl: "Pokazuje informacje",
		})
		.addSubcommand((subcommand) =>
			subcommand
				.setName("user")
				.setDescription("Shows information about the user")
				.setDescriptionLocalizations({
					pl: "Pokazuje informacje o użytkowniku",
				})
				.addUserOption((option) =>
					option
						.setName("user")
						.setNameLocalizations({
							pl: "użytkownik",
						})
						.setDescription("The user to show information about")
						.setDescriptionLocalizations({
							pl: "Użytkownik, o którym chcesz zobaczyć informacje",
						}),
				),
		);

	await client.application!.commands.set([command]); // No error.
});

client.login();

So, you seem to have flawed logic in your code and this is not a discord.js issue. You can head to our support server where you'll get support much quicker.

@Jiralite Jiralite closed this as not planned Won't fix, can't repro, duplicate, stale Jun 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants