ppauel / typescript-discord-bot

A TypeScript Discord bot template (discord.js v14)
MIT License
17 stars 4 forks source link

[Bug]: Type 'SlashCommandOptionsOnlyBuilder' is not assignable to type #19

Closed ShkourBashtawi closed 1 month ago

ShkourBashtawi commented 1 month ago

Contact Details

No response

What happened?

When use addStringOption or any options expect addSubComamnd,addSubCommandGroup it will return error

// Error:
Type 'SlashCommandOptionsOnlyBuilder' is not assignable to type 'SlashCommandBuilder | SlashCommandSubcommandsOnlyBuilder | Omit<SlashCommandBuilder, "addSubcommand" | "addSubcommandGroup">'.
  Type 'SlashCommandOptionsOnlyBuilder' is not assignable to type 'Omit<SlashCommandBuilder, "addSubcommand" | "addSubcommandGroup">'.
    The types returned by 'setName(...)' are incompatible between these types.
      Type 'SlashCommandOptionsOnlyBuilder' is missing the following properties from type 'SlashCommandBuilder': addSubcommandGroup, addSubcommand

// Emit Command:
import { PermissionsBitField, SlashCommandBuilder } from 'discord.js';
import { ChatInputCommand } from '../../interfaces';

const command: ChatInputCommand = {
    options: new SlashCommandBuilder()
        .setName('emit')
        .setDescription('Emit an event')
        .setDMPermission(false)
        .setDefaultMemberPermissions(PermissionsBitField.Flags.Administrator)
        .addStringOption((option) =>
            option
                .setName('event')
                .setDescription('The event to emit')
                .setRequired(true),
        )
        .addStringOption((option) =>
            option
                .setName('data')
                .setDescription('The data to emit')
                .setRequired(true),
        ),
    global: true,
    execute: async (_client, interaction) => {
        const event = interaction.options.getString('event', true);
        const data = interaction.options.getString('data', true);
        _client.emit(event, data);
        await interaction.reply({ content: `Emitted event \`${event}\``, ephemeral: true });
    },
};
export default command;

Version

discord.js v14.16.2 Nodejs v18.20.4

What engine are you seeing the problem on?

No response

Relevant log output

No response

ppauel commented 1 month ago

Hey there @ShkourBashtawi! Thank you for reporting this bug. This issue should be fixed in https://github.com/ppauel/typescript-discord-bot/commit/d9b97855f16bf7e94ba64bf3725aeeb05199336f. I moved from a rest instance to using the client's application class.

Edit: The issue was caused by the Command Interface (https://github.com/ppauel/typescript-discord-bot/commit/61732fcf21fff96b5896b9ac2bd335565bccb2ff).

ShkourBashtawi commented 1 month ago

Hey bro @ppauel thx for response The problem has been solved. Thank you