FM
FM
how to pass variables from one interaction into the next?
no apologies needed. i'm super grateful these packages exist, and these conversations help identify potential improvements. thank you for your efforts, kyra 🙏
46 replies
how to pass variables from one interaction into the next?
took a little tweaking, but this works, thank you!
46 replies
how to pass variables from one interaction into the next?
hi kyra! is there an update on this? i perused the #GitHub Logs and didn't see anything. with regard to how the framework currently handles things, should i just build the button logic directly in the modal interaction-handler for the time being? i don't want to export the variable as that just seems ... messy. open to suggestions though.
46 replies
how to pass variables from one interaction into the next?
okay cool. i'm glad i'm not missing something stupid lol
46 replies
how to pass variables from one interaction into the next?
what do i use for the parse string for the button handler to pick up the interaction? i pass the variable into the .setCustomId method, but i'm stuck getting the button handler to pick it up:
const stripeAccountEmailStore = stripeStore.serialize(Id.Email, { email: stripeEmail }).toString();

const stripeAccountCreate = new ButtonBuilder()
.setCustomId(stripeAccountEmailStore)
.setLabel('Create Account')
.setStyle(ButtonStyle.Primary);
const stripeAccountEmailStore = stripeStore.serialize(Id.Email, { email: stripeEmail }).toString();

const stripeAccountCreate = new ButtonBuilder()
.setCustomId(stripeAccountEmailStore)
.setLabel('Create Account')
.setStyle(ButtonStyle.Primary);
and in the button handler:
parse(interaction) {
// Log.info(interaction.customId);
if (interaction.customId !== 'stripeAccountEmailStore') return this.none();
return this.some();
}
parse(interaction) {
// Log.info(interaction.customId);
if (interaction.customId !== 'stripeAccountEmailStore') return this.none();
return this.some();
}
it wants a normal string so bad. i feel like i'm missing something totally rookie.
46 replies
how to pass variables from one interaction into the next?
🤔 interesting. thank you for the insight. i'll try the jsdoc way first.
46 replies
how to pass variables from one interaction into the next?
gotcha. i shall give that a go. i'm using js.
46 replies
how to pass variables from one interaction into the next?
I may be doing something wrong. This is my store, StripeSchemaStore.js:
import { SchemaStore, Schema, t } from '@sapphire/string-store';

const Id = {
Email: 0
}

export const stripeStore = new SchemaStore()
.add(new Schema(Id.Email).string('email'));
import { SchemaStore, Schema, t } from '@sapphire/string-store';

const Id = {
Email: 0
}

export const stripeStore = new SchemaStore()
.add(new Schema(Id.Email).string('email'));
and i use it in the modal interaction handler, StripeModalSubmit.js:
import { stripeStore } from '../service/stripe/StripeSchemaStore.js';

// a bunch of other logic

// email is captured

const stripeEmail = interaction.fields.getTextInputValue('stripeModalEmailEntry');

// time to bundle it up and send it
// to the button handler

const stripeAccountEmailStore = stripeStore
.serialize(**Id**.Email, { email: stripeEmail })
.toString();
import { stripeStore } from '../service/stripe/StripeSchemaStore.js';

// a bunch of other logic

// email is captured

const stripeEmail = interaction.fields.getTextInputValue('stripeModalEmailEntry');

// time to bundle it up and send it
// to the button handler

const stripeAccountEmailStore = stripeStore
.serialize(**Id**.Email, { email: stripeEmail })
.toString();
except now when i run it, i get an error that comes back saying Id is not defined. if this works like i'm understanding from your example, i should be able to use the store anywhere necessary, correct? i shouldn't have to define the store every time, i just need to pass in values to the store and serialize them as needed. do i understand this correctly?
46 replies
how to pass variables from one interaction into the next?
i'm not moving around a whole lot of data, but this is insanely useful even for the little bit i'm moving around. this is the first bot i've built that makes use of modals and buttons, tbh.
46 replies
how to pass variables from one interaction into the next?
holy fuck. well then!
46 replies
how to pass variables from one interaction into the next?
that's impressive. even more so in its simplicity.
46 replies
how to pass variables from one interaction into the next?
thank you so much @Ben @kyra 🩵🩷🤍🩷🩵 🙏
46 replies
how to pass variables from one interaction into the next?
that's perfect. this is going to simplify things so much for me.
46 replies
how to pass variables from one interaction into the next?
nice.
46 replies
how to pass variables from one interaction into the next?
i see. and then i just deserialize in the button handler?
46 replies
how to pass variables from one interaction into the next?
interesting. so i create the store, save it to a variable, and pass that variable as the .setCustomId argument?
46 replies
how to pass variables from one interaction into the next?
oh no way. how does that work? is it something like
new ButtonBuilder()
.setCustomId('myButton', 'myVar')
new ButtonBuilder()
.setCustomId('myButton', 'myVar')
i went to look at the sapphire docs, but not sure if I was looking in the right spot for this.
46 replies
[ERROR] Encountered error on event listener "CorePreChatInputCommandRun"
🤦‍♂️ Why is it that the things I struggle with the most have such a simple--and often overlooked--solution? Thank you. That fixed it.
7 replies
[ERROR] Encountered error on event listener "CorePreChatInputCommandRun"
This is the OwnerOnly precondition, very close to what's demonstrated in the guide:
import { Precondition } from "@sapphire/framework";

let returnMessageObj = {
content: 'gotta be the server owner to use this, my friend.',
ephemeral: true
};

export class OwnerOnlyPrecondition extends Precondition {

async chatInputRun(interaction) {
// for Slash Commands
return this.checkOwner(interaction.user.id, interaction);
}

async checkOwner(userID, interaction) {
if (process.env.DISCORD_BOT_OWNER === userID) {
return this.ok();
} else {
interaction.reply(returnMessageObj);
this.error({ message: 'Only the bot owner can use this command!' });
}
}
}
import { Precondition } from "@sapphire/framework";

let returnMessageObj = {
content: 'gotta be the server owner to use this, my friend.',
ephemeral: true
};

export class OwnerOnlyPrecondition extends Precondition {

async chatInputRun(interaction) {
// for Slash Commands
return this.checkOwner(interaction.user.id, interaction);
}

async checkOwner(userID, interaction) {
if (process.env.DISCORD_BOT_OWNER === userID) {
return this.ok();
} else {
interaction.reply(returnMessageObj);
this.error({ message: 'Only the bot owner can use this command!' });
}
}
}
Everything works ... just, as mentioned before, the error spits when the command this is currently used with (Ping) is executed by a not-owner. This leaves me scratching my head. I've poured over the docs, glanced at the source. I don't know what I'm missing. Any help is appreciated!
7 replies
[ERROR] Encountered error on event listener "CorePreChatInputCommandRun"
I'm getting this error on an OwnerOnly precondition check:
[ERROR] Encountered error on event listener "CorePreChatInputCommandRun" for event "preChatInputCommandRun" at path "/home/effem/effem.dev/COREBot/node_modules/@sapphire/framework/dist/listeners/application-commands/chat-input/CorePreChatInputCommandRun.js" TypeError: Cannot read properties of undefined (reading 'isErr')
at Object.chatInputSequential (/home/effem/effem.dev/COREBot/node_modules/@sapphire/framework/dist/lib/utils/preconditions/conditions/PreconditionConditionAnd.js:22:18)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async CoreListener.run (/home/effem/effem.dev/COREBot/node_modules/@sapphire/framework/dist/listeners/application-commands/chat-input/CorePreChatInputCommandRun.js:19:25)
at async Object.fromAsync (/home/effem/effem.dev/COREBot/node_modules/@sapphire/result/dist/index.js:613:22)
at async CoreListener._run (/home/effem/effem.dev/COREBot/node_modules/@sapphire/framework/dist/lib/structures/Listener.js:48:22)
[ERROR] Encountered error on event listener "CorePreChatInputCommandRun" for event "preChatInputCommandRun" at path "/home/effem/effem.dev/COREBot/node_modules/@sapphire/framework/dist/listeners/application-commands/chat-input/CorePreChatInputCommandRun.js" TypeError: Cannot read properties of undefined (reading 'isErr')
at Object.chatInputSequential (/home/effem/effem.dev/COREBot/node_modules/@sapphire/framework/dist/lib/utils/preconditions/conditions/PreconditionConditionAnd.js:22:18)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async CoreListener.run (/home/effem/effem.dev/COREBot/node_modules/@sapphire/framework/dist/listeners/application-commands/chat-input/CorePreChatInputCommandRun.js:19:25)
at async Object.fromAsync (/home/effem/effem.dev/COREBot/node_modules/@sapphire/result/dist/index.js:613:22)
at async CoreListener._run (/home/effem/effem.dev/COREBot/node_modules/@sapphire/framework/dist/lib/structures/Listener.js:48:22)
The precondition works, but this error populates when a not-owner uses the command. Precondition code in the following reply.
7 replies