Interaction Handlers

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.
Solution:
For AnswerOverflow: sapphire auto detects the interaction-handlers directory
F
Favna438d ago
no, the interaction-handlers directory is correct. It should be in the same directory as things like commands and listeners
N
net-tech-438d ago
and it is
N
net-tech-438d ago
https://hst.sh/rupiduyoti.typescript Maybe its the handler itself
F
Favna438d ago
did you rebuild your code
N
net-tech-438d ago
I ran tsc yes
F
Favna438d ago
idk then... needs full code ig but it works for many other bots
N
net-tech-438d ago
.
F
Favna438d ago
for example check @Dragonite's source code full code as in the full repo
N
net-tech-438d ago
wait i need to have sub folders for every type of interaction? E.g. interactions-handlers => modals => modal.ts
F
Favna438d ago
no that's optional
N
net-tech-438d ago
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
Sapphire Framework
Modals | Sapphire
Modals are like your annoying pop-ups, but cooler! These interactions will display a pop-up window on the user's client,
N
net-tech-438d ago
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}.`
});
}
}
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}.`
});
}
}
I already checked the custom id in the command trigger the modal, it has the custom id of benchmark the same as the listener i gave up Alright so uh it seems node wont detect any new files
F
Favna438d ago
something is seriously wrong with your setup then consider all the base factors of using sapphire
N
net-tech-438d ago
yeah im trying to figure it out @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 Is parse required for interaction handlers? If not I'm happy to remove it and to it directly in run
F
Favna438d ago
yes switching to pnpm, idk.
Solution
N
net-tech-438d ago
For AnswerOverflow: sapphire auto detects the interaction-handlers directory
Want results from more Discord servers?
Add your server
More Posts
bot won't get on and connect to discord.hi, my bot won't turn on. i've coded a lot of bots before with sapphire and they worked just fine, dHow Do I Make a Project in my current Directory?I want to make the proj in `workspaces/DashMate` not like `workspaces/DashMate/${ProjName}`Bot wont go onlinewhen I try to run the script `yarn dev` I get this problemGuildDelete Event somehow gets triggered when I restart my BotI have no idea whats happening but if my bot (docker container) restarts, this notification gets senTypeError: Class extends value undefined is not a constructor or nullHey, newbie here in both TypeScript and Sapphire, and I'm trying to build a command but I'm getting THREAD_CREATE event Listener run method argumentsWhat I want to do: I want to inspect the id of the parent channel where the thread was created. TheCommand info command issueI have a command info command, but when I try to get information on a command called "flags" it retuawait args.pick("member");how to enable this? https://discord.com/channels/737141877803057244/737142071319855105/107804884825Command info command issueI have a command info command, but when I try to get information on a command called "flags" it retuRunning in productionHey! What's the recommended method for starting up a node app in production? Specifically for DiscorspeakerName translation in FFXIVIpcChatHello everyone, I'm using ffxiv-pcap to read chat messages using the Sapphire Struct for chat messagClearing registered slash commandsHello 👋 I would like to know if there's a system provided by Sapphire to automatically clear previDocker being goofyI have no idea why Docker is being all goofy, it's saying that my discord token is invalid, but it'sReferenceError: [ENV] BOT_OWNER_IDS - The key must be an array, but is empty or undefined.I am using `@skyra/env-utilities` and when I start up my bot, I get the error reported in the title How can I turn a joinedTimestamp into this Discord TimestampThe one that automatically shows you like how long ago this timestamp wasHow to use `@sapphire/shapeshift ` dateValid & stringRegexI have a slash command that needs to take in a date input in the format of `YYYY-MM-DD`. I want to Access extended sapphire clientFollowing usecase: I extended the sapphire client in order to create custom collections etc. Is thVersion mismatch between Sapphire and dapi-typesHi, I was updating my dependencies when I encountered Discord.js' dapi-types error. I copy/pasted thWhats the syntax to require Permission X AND Y OR Z when using requiredUserPermissionswhen using `requiredUserPermissions`. Its an array so Im not sureGetting modalSubmit error over the weekendDid discord change something???