Goosy
Goosy
Explore posts from servers
SIASapphire - Imagine a framework
Created by Goosy on 6/11/2023 in #sapphire-support
Passing down arguments of Commands to the Interaction Handlers
I have a command that takes a user argument like /clan member @MindLabor and this command creates a message with Buttons. I also have a button interaction handler which runs when the button is clicked. But in that interaction handler I cannot find the arguments of my original command that created the message. Is there a good way of "passing" the data from where the buttons are built to the handler? Button Message Creation:
return interaction.reply({
content: `Choose the action you want to perform on this user/member:`,
ephemeral: true,
components: [
new ActionRowBuilder<ButtonBuilder>().addComponents(
new ButtonBuilder().setCustomId('add-member').setLabel('Add').setStyle(ButtonStyle.Primary),
new ButtonBuilder().setCustomId('promote-member').setLabel('Promote').setStyle(ButtonStyle.Primary),
new ButtonBuilder().setCustomId('demote-member').setLabel('Demote').setStyle(ButtonStyle.Danger),
new ButtonBuilder().setCustomId('kick-member').setLabel('Kick').setStyle(ButtonStyle.Danger),
new ButtonBuilder().setCustomId('remove-member').setLabel('Remove').setStyle(ButtonStyle.Danger)
)
]
});
return interaction.reply({
content: `Choose the action you want to perform on this user/member:`,
ephemeral: true,
components: [
new ActionRowBuilder<ButtonBuilder>().addComponents(
new ButtonBuilder().setCustomId('add-member').setLabel('Add').setStyle(ButtonStyle.Primary),
new ButtonBuilder().setCustomId('promote-member').setLabel('Promote').setStyle(ButtonStyle.Primary),
new ButtonBuilder().setCustomId('demote-member').setLabel('Demote').setStyle(ButtonStyle.Danger),
new ButtonBuilder().setCustomId('kick-member').setLabel('Kick').setStyle(ButtonStyle.Danger),
new ButtonBuilder().setCustomId('remove-member').setLabel('Remove').setStyle(ButtonStyle.Danger)
)
]
});
Button Handler
public async run(interaction: ButtonInteraction) {
// const clanName = interaction.options.getString('name'); // DOESNT WORK
const memberId = interaction.message.interaction?.user.id;
console.log(memberId);
console.log(interaction);
switch (interaction.customId) {
case "add-member":
console.log("add-member"); // WORKS
}
// AHHHHHHHahgdjgha ajks ja!!
}
public async run(interaction: ButtonInteraction) {
// const clanName = interaction.options.getString('name'); // DOESNT WORK
const memberId = interaction.message.interaction?.user.id;
console.log(memberId);
console.log(interaction);
switch (interaction.customId) {
case "add-member":
console.log("add-member"); // WORKS
}
// AHHHHHHHahgdjgha ajks ja!!
}
7 replies
SIASapphire - Imagine a framework
Created by Goosy on 6/11/2023 in #sapphire-support
Node Heap Allocation Issue
I don't know why this keeps happening but sometimes when I try to build I get an out of memory issue. I tried giving node 16gb but it just took all of it and threw out of memory again. So I assume this is a memory leak when I run tsc. I dont know why somtimes it worked and other times not but now its not working anymore and I have no clue why or how to fix it. ChatGPT just says well give it more memory. Has anybody an idea? Here is my package.json and tsconfig: (I never had this before and my tsc works fine with other projects)
11 replies
SIASapphire - Imagine a framework
Created by Goosy on 6/11/2023 in #sapphire-support
Triggering a Modal, Message With Buttons, ...
I want to make a command that sends a message with buttons and when a button is clicked it gives a popup with something like "Are you sure that you want to delete X?". Now I looked at the guide but it only says how to handle these interactions. But how can I trigger them in the first place? https://www.sapphirejs.dev/docs/Guide/interaction-handlers/modals
3 replies
SIASapphire - Imagine a framework
Created by Goosy on 6/10/2023 in #sapphire-support
Passing down from the index.ts and arguments to subcommands
I have two Issues: 1. I want to use Firestore which I'm initilizing in the index.ts but I dont know how to access variables from the index.ts in my command folders. 2. How do I access arguments for subcommands? Here is my code for the second issue:
import { Subcommand } from '@sapphire/plugin-subcommands';
import { Command, Args, type ChatInputCommand } from '@sapphire/framework';
import type { Message } from 'discord.js';

export class ClanCommand extends Subcommand {
public constructor(context: Subcommand.Context, options: Subcommand.Options) {
super(context, {
...options,
name: 'clan',
subcommands: [
{
name: 'create',
chatInputRun: 'createClan',
default: true,
},
],
});
}

public override registerApplicationCommands(registry: ChatInputCommand.Registry) {
registry.registerChatInputCommand((builder) =>
builder
.setName('clan')
.setDescription('All clan specific commands')
.addSubcommand((subcommand) => subcommand.setName('create').setDescription('Create a new clan'))
);
}

public async createClan(interaction: Subcommand.ChatInputCommandInteraction) {
console.log('Create Clan command received');
const userID = interaction.options.getUser('user')?.id ?? interaction.user.id;
if (userID !== "488324471657332736") {
await interaction.reply({ content: `https://media.tenor.com/x8v1oNUOmg4AAAAd/rickroll-roll.gif` });
return;
}

console.log('Creating clan'); // MISSING ARGUMENTS HERE ........
}
}
import { Subcommand } from '@sapphire/plugin-subcommands';
import { Command, Args, type ChatInputCommand } from '@sapphire/framework';
import type { Message } from 'discord.js';

export class ClanCommand extends Subcommand {
public constructor(context: Subcommand.Context, options: Subcommand.Options) {
super(context, {
...options,
name: 'clan',
subcommands: [
{
name: 'create',
chatInputRun: 'createClan',
default: true,
},
],
});
}

public override registerApplicationCommands(registry: ChatInputCommand.Registry) {
registry.registerChatInputCommand((builder) =>
builder
.setName('clan')
.setDescription('All clan specific commands')
.addSubcommand((subcommand) => subcommand.setName('create').setDescription('Create a new clan'))
);
}

public async createClan(interaction: Subcommand.ChatInputCommandInteraction) {
console.log('Create Clan command received');
const userID = interaction.options.getUser('user')?.id ?? interaction.user.id;
if (userID !== "488324471657332736") {
await interaction.reply({ content: `https://media.tenor.com/x8v1oNUOmg4AAAAd/rickroll-roll.gif` });
return;
}

console.log('Creating clan'); // MISSING ARGUMENTS HERE ........
}
}
6 replies