thenorthsolution / Reciple

⚡Discord.js framework that just works
https://reciple.js.org
GNU General Public License v3.0
12 stars 1 forks source link

[BUG] - `ApplicationCommandType.Message` is not assignable to parameter of type `ContextMenuCommandType | "Message" | "User"` #67

Open PAdventures opened 1 month ago

PAdventures commented 1 month ago

Which package is this bug report for?

@reciple/core & create-reciple

Issue description

  1. Run npm create reciple@latest
  2. Use TypeScript and all add-ons
  3. Don't select decorators
  4. Navigate to src/commands/PingCommand.ts

Exact error:

Argument of type 'ApplicationCommandType.Message' is not assignable to parameter of type 'ContextMenuCommandType | "Message" | "User"'.ts(2345)

Code sample

import { ApplicationCommandType } from 'discord.js';
import { AnyCommandExecuteData, CommandType, ContextMenuCommandBuilder, MessageCommandBuilder, RecipleModuleData, SlashCommandBuilder, type AnyCommandResolvable } from "reciple";

export class PingCommand implements RecipleModuleData {
    public commands: AnyCommandResolvable[] = [
        new ContextMenuCommandBuilder()
            .setName('ping')
            .setType(ApplicationCommandType.Message)
            .setExecute(data => this.handleCommandExecute(data)),
        new MessageCommandBuilder()
            .setName('ping')
            .setDescription('Replies with pong!')
            .setExecute(data => this.handleCommandExecute(data)),
        new SlashCommandBuilder()
        .setName('ping')
        .setDescription('Replies with pong!')
        .setExecute(data => this.handleCommandExecute(data)),
    ];

    /**
     * Executed when module is started (Bot is not logged in).
     */
    async onStart(): Promise<boolean> {
        return true;
    }

    /**
     * Executes when the module is loaded (Bot is logged in).
     */
    async onLoad(): Promise<void> {}

    /**
     * Executes when the module is unloaded (Bot is pre log out).
     */
    async onUnload(): Promise<void> {}

    /**
     * Sets the commands
     */
    async handleCommandExecute(data: AnyCommandExecuteData): Promise<void> {
        switch (data.type) {
            case CommandType.ContextMenuCommand:
            case CommandType.SlashCommand:
                await data.interaction.reply('Pong!');
                return;
            case CommandType.MessageCommand:
                await data.message.reply('Pong!');
                return;
        }
    }
}

export default new PingCommand();

Versions

Dependencies

Dev Dependencies

Runtime

deno 2.0.2 (stable, release, aarch64-apple-darwin)
v8 12.9.202.13-rusty
typescript 5.6.2

OS MacBook Air: 15.0.1

catplvsplus commented 1 month ago

This is a discord.js bug. This will be fixed after the next discord.js release. For now, use the string types:

new ContextMenuCommandBuilder()
    .setType('Message') // 'Message'|'User'

https://github.com/discordjs/discord.js/issues/10535 https://github.com/discordjs/discord.js/issues/10533 https://github.com/discordjs/discord.js/pull/10524

Ultimate-Destroyer commented 1 month ago

This is a discord.js bug. This will be fixed after the next discord.js release. For now, use the string types:

new ContextMenuCommandBuilder()
    .setType('Message') // 'Message'|'User'

discordjs/discord.js#10535 discordjs/discord.js#10533 discordjs/discord.js#10524

typescript complains on that method

Argument of type '"User"' is not assignable to parameter of type 'ContextMenuCommandType'.
catplvsplus commented 1 month ago

This is a discord.js bug. This will be fixed after the next discord.js release. For now, use the string types:

new ContextMenuCommandBuilder()
    .setType('Message') // 'Message'|'User'

discordjs/discord.js#10535 discordjs/discord.js#10533 discordjs/discord.js#10524

typescript complains on that method

Argument of type '"User"' is not assignable to parameter of type 'ContextMenuCommandType'.

That will only occur when using the builder from discord.js instead of reciple's context menu builder class which extends discord.js's

Docs: ContextMenuCommandBuilder#setType

catplvsplus commented 1 month ago

A temporary fix is either using "Message"|"User" or import ApplicationCommandType from discord-api-types/v10