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 ........
}
}
Solution:
As for firestore, you can either put it into client's container store Or initialise firestore in seperate file, export the firestore object/database. Then import it where you need...
Jump to solution
3 Replies
MRDGH2821
MRDGH282112mo ago
You will need to set options inside subcommand Which you can access by interaction.options.getString('option_name') (this is just an example)
Solution
MRDGH2821
MRDGH282112mo ago
As for firestore, you can either put it into client's container store Or initialise firestore in seperate file, export the firestore object/database. Then import it where you need
Goosy
Goosy12mo ago
Works perfectly thanks :D