Sapphire - Imagine a framework
Sapphire - Imagine a framework

sapphire-support

Root Question Message

AleMartinelli
AleMartinelli2/10/2023
piece.aliases is not iterable

Hi everybody, I was just coding a simple bot, it has only a few, basic commands like ping-pong. I just keep getting this error, and I can't figure out where it comes out from. I got it first when I created a class which extends InteractionHandler, and now even by removing that class I keep getting it.
Any help is welcome.

This is the class I am talking about. Don't know if I'm missing something or doing something wrong.
import {Awaitable, InteractionHandler, InteractionHandlerTypes, Listener, Option} from "@sapphire/framework";
import {ButtonInteraction} from "discord.js";
import Context = Listener.Context;
import {prisma} from "../db/db.js";


export default class ShowTeacherInteraction extends InteractionHandler {
    public constructor(ctx: Context, options: InteractionHandler.Options) {
        super(ctx, {
            ...options,
            interactionHandlerType: InteractionHandlerTypes.Button,
        });
    }

    parse(_interaction: ButtonInteraction): Awaitable<Option<any>> {
        if (!_interaction.id.startsWith("show-teacher-")) return this.none();

        return this.some(_interaction.id.split('-')[2]);
    }

    public async run(interaction: ButtonInteraction, teacher_id: number) {
        const teacher = await prisma.teacher.findUnique({
            where: {
                id: teacher_id
            }
        });

        if (!teacher || teacher.guild_id != interaction.guildId) {
            await interaction.reply("Teacher not found!");
            return;
        }

        await interaction.reply({content: teacher.full_name, ephemeral: true});
    }
}

Solution Message

Favna
Favna2/10/2023
You put the InteractionHandler in the commands folder. It should go in the interaction-handlers folder instead.
ContactFrequently Asked QuestionsJoin The DiscordBugs & Feature RequestsTerms & Privacy