#Buttons in NestJS

3 messages · Page 1 of 1 (latest)

verbal nacelle

Hello everyone,

  @Handler()
  @IsDiscordTeam()
  async onAskQuestionImage(@InteractionEvent() interaction: CommandInteraction, @IA(SlashCommandPipe) options: QuestionImageDto): Promise<InteractionResponse<boolean>> {
    try {
      const channel = this.client.channels.cache.get(options.channel) as TextChannel;

      const embed = new EmbedBuilder().setTitle("New Image Question").setDescription(options.text).setImage(options.image);

      const confirm = new ButtonBuilder().setCustomId("confirm").setLabel("Confirm Ban").setStyle(ButtonStyle.Danger);

      const cancel = new ButtonBuilder().setCustomId("cancel").setLabel("Cancel").setStyle(ButtonStyle.Secondary);

      const row = new ActionRowBuilder().addComponents(cancel, confirm);

      await channel.send({
        embeds: [embed.toJSON()],
        components: [row],
      });

      return interaction.reply({ content: "Question with buttons has been posted! ✅", ephemeral: true });
    } catch (err) {
      console.error("Error", err);
      return interaction.reply({ content: "An error has occurred. ⚠️", ephemeral: true });
    }
  }
}

Error

src/discord-bot/commands/questions-image.ts:34:22 - error TS2322: Type 'ActionRowBuilder<AnyComponentBuilder>' is not assignable to type 'APIActionRowComponent<APIMessageActionRowComponent> | JSONEncodable<APIActionRowComponent<APIMessageActionRowComponent>> | ActionRowData<...>'.
  Property 'type' is missing in type 'ActionRowBuilder<AnyComponentBuilder>' but required in type 'ActionRowData<MessageActionRowComponentBuilder | MessageActionRowComponentData>'.

34         components: [row],
                        ~~~

  ../../node_modules/discord.js/typings/index.d.ts:268:3
    268   type: ComponentType;
          ~~~~
    'type' is declared here.

[09:37:00] Found 1 error. Watching for file changes.

I am unable to send the buttons.
Cna anyone help out? please

faint trailBOT
  • Consider reading #how-to-get-help to improve your question!
  • Explain what exactly your issue is.
  • Post the full error stack trace, not just the top part!
  • Show your code!
  • Issue solved? Press the button!
stable ospreyBOT

Tag suggestion for @verbal nacelle:
In TypeScript the ActionRowBuilder class has a generic type parameter that specifies the type of component the action row holds:

const row = new ActionRowBuilder<ButtonBuilder>().addComponents(button)
const row = new ActionRowBuilder<StringSelectMenuBuilder>().addComponents(selectMenu)
const row = new ActionRowBuilder<TextInputBuilder>().addComponents(textInput)