Can not pass a string var into a `option.setName()` function in discord.js

Viewed 20

Hello this is my code for some reason when I pass optName into option.setName() on line 22 I get this error.

enter image description here

How ever when I pass something like "test" into option.setName() everything works fine so does any one have any idea what is wrong?

import { SlashCommandBuilder } from "discord.js";
import { optionsI } from "./interfaces";

function initOptions(
    slashCommandBuild: SlashCommandBuilder,
    options: optionsI,
) {
    for (const [keys, values] of Object.entries(options) as [
        keys: keyof typeof options,
        values: Map<string, string>,
    ][]) {
        slashCommandBuild[keys]((option: any) => {
            const optName: string = values.keys().next().value;
            const optDesc: string | undefined = values.get(
                values.keys().next().value,
            );
            if (optName === undefined || optName === null) {
                throw new Error(
                    `Please make sure that the command has a name.`,
                );
            }
            option.setName(optName);

            if (optDesc === null || optDesc === undefined) return option;
            option.setDescription(optDesc);

            return option;
        });
    }
}

export { initOptions };
0 Answers
Related