Options missing from slash command.

const interaction = {
interaction: {
type: ApplicationCommandType.ChatInput,
description: "some description",
options: [
{
name: "question",
description: "poll question",
type: ApplicationCommandOptionType.String,
required: true,
},
],
},

helpData: undefined,

async execute(execution) {
console.log("awd");
},
} satisfies InteractionDefinition<ChatInputApplicationCommandData, true>;
const interaction = {
interaction: {
type: ApplicationCommandType.ChatInput,
description: "some description",
options: [
{
name: "question",
description: "poll question",
type: ApplicationCommandOptionType.String,
required: true,
},
],
},

helpData: undefined,

async execute(execution) {
console.log("awd");
},
} satisfies InteractionDefinition<ChatInputApplicationCommandData, true>;
The options are just missing.
10 Replies
d.js toolkit
d.js toolkit11mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
Frosttide
FrosttideOP11mo ago
[email protected] , node v21.5.0 Heres a picture of the command being used rn
No description
Frosttide
FrosttideOP11mo ago
another slash command that has working options
No description
Frosttide
FrosttideOP11mo ago
heres how its setup
interaction: {
type: ApplicationCommandOptionType.Subcommand,
description: "Create a poll.",
options: [
{
name: "question",
description: "poll question",
type: ApplicationCommandOptionType.String,
required: true,
},
//removed the other options for brevity
] as NonNullable<InteractionDefinition<ApplicationCommandSubCommandData, true>["interaction"]["options"]>,
},
interaction: {
type: ApplicationCommandOptionType.Subcommand,
description: "Create a poll.",
options: [
{
name: "question",
description: "poll question",
type: ApplicationCommandOptionType.String,
required: true,
},
//removed the other options for brevity
] as NonNullable<InteractionDefinition<ApplicationCommandSubCommandData, true>["interaction"]["options"]>,
},
treble/luna
treble/luna11mo ago
and how are you importing that into the builder, and have you redeployed
Frosttide
FrosttideOP11mo ago
My collegue wrote the import script, its kinda long I run the bot locally on my machine
treble/luna
treble/luna11mo ago
make sure you're actually deploying the options, and that you're deploying anything at all
Frosttide
FrosttideOP10mo ago
well I changed giveaway to giveawayawd and the change was reflected in discord so I assume the file is being parsed correctly console.log statements work aswell but options just dont show
const interactionsObj = await interactions;
const interactionsToSet = await rawInteractions;

if (interactionsToSet.global)
client.application?.commands.set(interactionsToSet.global);

if (interactionsToSet.guilds)
for (const guild in interactionsToSet.guilds){
console.log(`Setting guild ${guild} commands...`);
client.guilds.fetch(guild)
.then((g) => g.commands.set(interactionsToSet.guilds[guild]!) )
.catch((e) => console.error(`Error while setting guild ${guild} commands`, e));
}
const interactionsObj = await interactions;
const interactionsToSet = await rawInteractions;

if (interactionsToSet.global)
client.application?.commands.set(interactionsToSet.global);

if (interactionsToSet.guilds)
for (const guild in interactionsToSet.guilds){
console.log(`Setting guild ${guild} commands...`);
client.guilds.fetch(guild)
.then((g) => g.commands.set(interactionsToSet.guilds[guild]!) )
.catch((e) => console.error(`Error while setting guild ${guild} commands`, e));
}
async function sendInteraction(interaction: Interaction) {
const isChat = interaction.isChatInputCommand();
const isUser = interaction.isUserContextMenuCommand();
const isMessage = interaction.isMessageContextMenuCommand();

const isCommand = isChat || isUser || isMessage;

if (!isCommand) return; // Don't handle these types of interactions here

const command = isChat ? interactionsObj.chat[interaction.commandName]
: isUser ? interactionsObj.user[interaction.commandName]
: isMessage ? interactionsObj.message[interaction.commandName]
: null;
try {
if (command)
await command.execute(interaction as any); // Cast to `any` here because TypeScript can't figure out the correct parameter type for `execute`
else {
console.warn(new Error("Unbound Interaction"), { interaction });
await interaction[
interaction.deferred ? "editReply"
: interaction.replied ? "followUp"
: "reply"
]({
content: `ERROR: Unbound interaction (we can't seem to find code to handle what you asked for!)`,
ephemeral: true,
files: [{
attachment: Buffer.from(stringifyJson(interaction, 4)),
name: "interaction.json",
}],
});
}
} catch (error) {
await catchInteractionErrors(error, interaction);
}
}

client.on("interactionCreate", sendInteraction);
async function sendInteraction(interaction: Interaction) {
const isChat = interaction.isChatInputCommand();
const isUser = interaction.isUserContextMenuCommand();
const isMessage = interaction.isMessageContextMenuCommand();

const isCommand = isChat || isUser || isMessage;

if (!isCommand) return; // Don't handle these types of interactions here

const command = isChat ? interactionsObj.chat[interaction.commandName]
: isUser ? interactionsObj.user[interaction.commandName]
: isMessage ? interactionsObj.message[interaction.commandName]
: null;
try {
if (command)
await command.execute(interaction as any); // Cast to `any` here because TypeScript can't figure out the correct parameter type for `execute`
else {
console.warn(new Error("Unbound Interaction"), { interaction });
await interaction[
interaction.deferred ? "editReply"
: interaction.replied ? "followUp"
: "reply"
]({
content: `ERROR: Unbound interaction (we can't seem to find code to handle what you asked for!)`,
ephemeral: true,
files: [{
attachment: Buffer.from(stringifyJson(interaction, 4)),
name: "interaction.json",
}],
});
}
} catch (error) {
await catchInteractionErrors(error, interaction);
}
}

client.on("interactionCreate", sendInteraction);
Im not the one who wrote the code, but I believe this is how they are being used Sorry , its written in TS and I know almost nothing about TS.
export async function getAllInteractions() {
const [chat, user, message] = await Promise.all([
getInteractionsOfType("chat"),
getInteractionsOfType("user"),
getInteractionsOfType("message"),
]);

return { chat, user, message };
}

const thisFile = fileURLToPath(import.meta.url);
const interactionsDir = path.dirname(thisFile);
const extension = path.extname(thisFile);
export async function getAllInteractions() {
const [chat, user, message] = await Promise.all([
getInteractionsOfType("chat"),
getInteractionsOfType("user"),
getInteractionsOfType("message"),
]);

return { chat, user, message };
}

const thisFile = fileURLToPath(import.meta.url);
const interactionsDir = path.dirname(thisFile);
const extension = path.extname(thisFile);
export async function getInteractionsOfType<
TType extends keyof BackendInteractionType
>(type: TType): Promise<Record<string, BackendInteractionType[TType]>> {
const interactionTypeDir = path.join(interactionsDir, type);
console.log(
`Processing ${type} commands...\nDirectory: ${interactionTypeDir}`
);

try {
await fs.access(interactionTypeDir);
} catch (e) {
if (e instanceof Error && "code" in e && e.code === "ENOENT") {
console.log(`No ${type} commands found.`);
return {};
} else throw e;
}

const files = (await fs.readdir(interactionTypeDir, { withFileTypes: true }))
.map((file) =>
file.isFile()
? file.name.endsWith(extension) && file.name
: file.isDirectory() && file.name
)
.filter((file) => file) as string[];
const interactions = await Promise.all(
files.map((file) => getSingleInteraction(type, file))
);

const interactionsObj: Record<string, BackendInteractionType[TType]> = {};
for (const interaction of interactions)
interactionsObj[interaction.interaction.name] = interaction;

return interactionsObj;
}
export async function getInteractionsOfType<
TType extends keyof BackendInteractionType
>(type: TType): Promise<Record<string, BackendInteractionType[TType]>> {
const interactionTypeDir = path.join(interactionsDir, type);
console.log(
`Processing ${type} commands...\nDirectory: ${interactionTypeDir}`
);

try {
await fs.access(interactionTypeDir);
} catch (e) {
if (e instanceof Error && "code" in e && e.code === "ENOENT") {
console.log(`No ${type} commands found.`);
return {};
} else throw e;
}

const files = (await fs.readdir(interactionTypeDir, { withFileTypes: true }))
.map((file) =>
file.isFile()
? file.name.endsWith(extension) && file.name
: file.isDirectory() && file.name
)
.filter((file) => file) as string[];
const interactions = await Promise.all(
files.map((file) => getSingleInteraction(type, file))
);

const interactionsObj: Record<string, BackendInteractionType[TType]> = {};
for (const interaction of interactions)
interactionsObj[interaction.interaction.name] = interaction;

return interactionsObj;
}
is this what youre looking for? I did , I did ;x he just gave me this template
interaction: {
type: ApplicationCommandType.ChatInput,
description: 'Show a list of commands',
options: [
{
name: 'command',
description: 'The command to get help for',
type: ApplicationCommandOptionType.String,
required: false,
},
{
name: 'type',
description: 'The type of command to get help for (slash, user, message) - defaults to slash',
type: ApplicationCommandOptionType.String,
choices: [
{name: 'slash', value: 'chat'},
{name: 'user', value: 'user'},
{name: 'message', value: 'message'},
],
required: false,

}
],
},
interaction: {
type: ApplicationCommandType.ChatInput,
description: 'Show a list of commands',
options: [
{
name: 'command',
description: 'The command to get help for',
type: ApplicationCommandOptionType.String,
required: false,
},
{
name: 'type',
description: 'The type of command to get help for (slash, user, message) - defaults to slash',
type: ApplicationCommandOptionType.String,
choices: [
{name: 'slash', value: 'chat'},
{name: 'user', value: 'user'},
{name: 'message', value: 'message'},
],
required: false,

}
],
},
but it looks similar to what i did
Frosttide
FrosttideOP10mo ago
No description
Frosttide
FrosttideOP10mo ago
i thought idk, maybe im doing something stupid that im not seeing since all the other commands work
Want results from more Discord servers?
Add your server