S-IAF
Join ServerSapphire - Imagine a framework
sapphire-support
Interaction Handlers
Nnet-tech-3/6/2023
Am I required to specify to sapphire where my interaction handlers directory is? A
interaction-handlers
directory doesn't seem to be detected. - ├─ Loaded 0 interaction-handlers.
FFavna3/6/2023
no, the
interaction-handlers
directory is correct. It should be in the same directory as things like commands
and listeners
Nnet-tech-3/6/2023
and it is

Nnet-tech-3/6/2023
Nnet-tech-3/6/2023
Maybe its the handler itself
FFavna3/6/2023
did you rebuild your code
Nnet-tech-3/6/2023
I ran
tsc
yesFFavna3/6/2023
idk then... needs full code ig
FFavna3/6/2023
but it works for many other bots
Nnet-tech-3/6/2023
.
FFavna3/6/2023
for example check @Dragonite's source code
FFavna3/6/2023
full code as in the full repo
Nnet-tech-3/6/2023
wait i need to have sub folders for every type of interaction? E.g.
interactions-handlers => modals => modal.ts
interactions-handlers => modals => modal.ts
FFavna3/6/2023
no that's optional
Nnet-tech-3/6/2023
okay so i copied the example from the guide at https://www.sapphirejs.dev/docs/Guide/interaction-handlers/modals and it still doesn't seem to be detecting
Nnet-tech-3/6/2023
import { InteractionHandler, InteractionHandlerTypes, PieceContext } from '@sapphire/framework';
import { ActionRowBuilder, ButtonBuilder, ButtonStyle, ModalSubmitInteraction } from 'discord.js';
import { startBenchmark } from '../services/benchmarkRunner';
export class ModalHandler extends InteractionHandler {
public constructor(ctx: PieceContext, options: InteractionHandler.Options) {
super(ctx, {
...options,
interactionHandlerType: InteractionHandlerTypes.ModalSubmit
});
}
public override parse(interaction: ModalSubmitInteraction) {
if (interaction.customId !== 'benchmark') return this.none();
return this.some();
}
public async run(interaction: ModalSubmitInteraction) {
console.log('1');
const controlRow = new ActionRowBuilder<ButtonBuilder>().addComponents(
new ButtonBuilder().setCustomId('abort').setLabel('Abort').setStyle(ButtonStyle.Danger)
);
const iterations = interaction.fields.getTextInputValue('iterations') ?? '1000';
const case1 = interaction.fields.getTextInputValue('case-1');
const case2 = interaction.fields.getTextInputValue('case-2');
// If we cannot parse a number, we abort.
if (isNaN(Number(iterations))) return interaction.reply({ content: 'Unable to parse number of iterations. Please provide a valid number.' });
// If the code is empty, we abort.
if (!(case1 && case2)) return interaction.reply({ content: 'Please provide code for both test cases.' });
const startedTimestamp = `<t:${Math.floor(Date.now() / 1000)}:R>`;
await interaction.reply({
content: `Benchmark with ${iterations} iterations in progress - Started ${startedTimestamp}.`,
components: [controlRow]
});
await startBenchmark(Number(iterations), case1, case2);
interaction.reply({
content: `Benchmark finished - Started ${startedTimestamp}.`
});
}
}
Nnet-tech-3/6/2023
I already checked the custom id in the command trigger the modal, it has the custom id of
benchmark
the same as the listenerNnet-tech-3/6/2023
i gave up
Nnet-tech-3/6/2023
Alright so uh it seems node wont detect any new files
FFavna3/6/2023
something is seriously wrong with your setup then
FFavna3/6/2023
consider all the base factors of using sapphire
Nnet-tech-3/6/2023
yeah im trying to figure it out
Nnet-tech-3/6/2023
@Favna just getting the issue from #1053123174012813362, is there any alternative to switching to yarn? switching to yarn is more of a workaround than a solution
Nnet-tech-3/6/2023
Is parse required for interaction handlers? If not I'm happy to remove it and to it directly in
run
FFavna3/6/2023
yes
FFavna3/6/2023
switching to pnpm, idk.
Solution
Nnet-tech-3/6/2023
For AnswerOverflow: sapphire auto detects the interaction-handlers directory