Error: Unable to execute map() function on commands.options? while configuring slash commands

discord js v13.3.1

I have configured my bot to update and deploy slash commands using a specific command called "deploy". The structure of the deploy command is as follows:

module.exports = {
    name: "deploy",
    description: "deploys slash commands",
    disabled: false,
    async execute(interaction, args, client) {
        if (interaction.author.id !== process.env.OWNERID) return interaction.reply('You must be the owner to use this!');

        const cmds = client.commands
            .filter(command => command.slash)
            .map(command => {
                let {
                    name,
                    description = "missing description",
                    options = [],
                    slash = false,
                    defaultPermission = true,
                    slashPermissions = [],
                } = command;
                if (typeof name === "string") name = [name];
                const cmd = { name: name[0], description, options, defaultPermission, permissions: slashPermissions };
                return cmd;
            });

            await setCommands(interaction.guild?.commands)
                .then(interaction.reply(`Registered ${cmds.length} commands to this guild!`));


        async function setCommands(commandManager) {
            const appCommands = await commandManager.set(
                commandManager?.guild ? cmds : cmds.filter(cmd => !cmd.permissions.length)
            );
            if (commandManager?.guild) {
                const fullPermissions = appCommands
                    .map(appCommand => {
                        const permissions = cmds.find(cmd => cmd.name === appCommand.name).permissions;
                        return { id: appCommand.id, permissions };
                    })
                    .filter(appCommand => appCommand.permissions.length);
                await commandManager.permissions.set({ fullPermissions });
            }
        }
    }
}

I took a break from working on my bot for some time, and now I am attempting to add slash functionality to the remaining commands. I had previously registered slash commands in my guild successfully with this command. However, when I try to deploy my new slash commands now, I encounter an error in the console:

main\node_modules\discord.js\src\managers\ApplicationCommandManager.js:246
      options: command.options?.map(o => ApplicationCommand.transformOption(o)),
                                ^

TypeError: command.options?.map is not a function
    at Function.transformCommand (main\node_modules\discord.js\src\managers\ApplicationCommandManager.js:246:33)
    at main\node_modules\discord.js\src\managers\ApplicationCommandManager.js:163:48
    at Array.map (<anonymous>)
    at GuildApplicationCommandManager.set (main\node_modules\discord.js\src\managers\ApplicationCommandManager.js:163:22)
    at setCommands (main\commands\admin\deploy.js:34:54)
    at Object.execute (main\commands\admin\deploy.js:29:19)
    at module.exports (main\events\guild\messageCreate.js:28:51)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

Just to provide more context, one of my command structures looks like this:

module.exports = {
    name: "move",
    description: "Move all users from one vc to another",
    usage: `\`${process.env.PREFIX}move <vc1> <vc2>\``,
    alias: ["mv"],
    disabled: false,
    slash: true,
    options: [
        {
            name: 'target',
            type: 'CHANNEL',
            channelTypes: ['GUILD_VOICE'],
            description: 'Channel to move users from',
            required: true
        },
        {
            name: 'destination',
            type: 'CHANNEL',
            channelTypes: ['GUILD_VOICE'],
            description: 'Channel to move users into',
            required: true
        }
    ],
    permission: ['MOVE_MEMBERS'],
    async execute(interaction, args){ 
    }
}

Could this error be due to how I'm constructing the options blocks within my commands or how I'm passing them to guildCommandManager? I suspect it's the former since the TypeError points to that direction, but dealing with maps and objects has always been challenging for me. It's especially tricky because the error originates from the discord.js module rather than my own code.

Answer №1

To implement this, simply utilize the rest method as outlined in the discord.js guide code reference provided.

For creating global commands, use applicationCommands, and for local server-specific commands, use applicationGuildCommands.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Development of a custom waterfall toolbar design using MUI framework

I've been working with a setup similar to the one found here: https://codesandbox.io/s/1op5mqq9oq By clicking on the checkboxes, the <Toolbar /> is displayed. As you scroll down the page, the <Toolbar /> remains fixed at the top and even ...

Simple code styling tool

Seeking guidance to create a basic syntax highlighter using JavaScript or ClojureScript. While aware of existing projects like Codemirror and rainbow.js, I'm interested in understanding how they are constructed and looking for a simple example. Do th ...

Solution to bypass JavaScript PHP login system

Creating a login/register system with JavaScript to display specific divs for the system: 1st div = menu option to either log in or register 2nd div = shows login form or register form depending on what was clicked (login or register) 3rd div = displays ...

Best practices for declaring variables in ReactJS

I need help understanding how to declare a variable in a React JS class so that it is accessible in different functions. Here is my code snippet: class MyContainer extends Component { constructor(props) { super(props); this.testVariable ...

WebGL Tips: Resizing an object using vector multiplication, achievement showcased (see image)

I'm currently exploring methods to scale an object without taking into consideration its local rotation. While I have achieved some success using morph animation, I am searching for a more dependable solution. ...

Unfamiliar function detected in the updated Vue Composition API

I am currently in the process of converting a basic SFC to utilize the new Vue CompositionAPI. The original code functions perfectly: export default { data() { return { miniState: true } }, methods: { setMiniState(state) { if ...

Unable to allocate a second item to an existing one

Encountering an unusual issue while trying to assign an item a second time. Initial scenario: I am working with a jqxTree containing various items as shown below: - apple - oracle - microsoft When I drag and drop one item into another, the structure loo ...

Tips for preventing the inheritance of .css styles in React

I'm facing an issue with my react application. The App.js fragment is displayed below: import ServiceManual from './components/pages/ServiceManual' import './App.css'; const App = () => { return ( <> ...

"Troubleshooting: Sending null values through Jquery ajax to an MVC controller

The issue: I am facing a challenge with saving events in a calendar through ajax by sending the content to my controller function. Despite my efforts, I constantly see null values being passed to my database. Upon inspecting the Network tools console log ...

Trigger Function on Input Change in Angular 2

Key aspects of component nesting: export class Child { @Input() public value: string; public childFunction(){...} } Main component responsibilities: export class Parent { public value2: string; function1(){ value2 = "a" } function2( ...

The attempt to access a Spring Boot webservice using AngularJS and the GET method resulted in a 500 status error, indicating that the operation

I have successfully developed a webservice using springboot and angularjs to download an excel file from the server to my local machine. The URL is being generated correctly, however, I am encountering a 500 error. Below is the code snippet: My Springboot ...

What could be causing my CSS transitions to fail when using jQuery to add classes?

I'm currently working on a website and I'm facing an issue with the transition not functioning as expected. The problem persists even when the 7.css stylesheet is removed and interestingly, the transition works fine when using window:hover. My a ...

Preventing the page from scrolling to the top while utilizing an Angular-bootstrap modal and a window position:fixed workaround on an iPad

It's common knowledge that there is a bug in bootstrap modals on certain devices, causing the page behind the modal to scroll instead of the modal itself (http://getbootstrap.com/getting-started/#support-fixed-position-keyboards) An easy fix for this ...

Making changes to an object using a different object

Is it possible to merge one object with another object? For instance master = { name: "John", email: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e389a389cd808c8e">[email protected]</a>" } child = { phone: ...

Utilizing the jQuery slideToggle method on the specified target element

I'm encountering an issue with jQuery slideToggle, and here's the code I have: $(".dropdownmainmenu").click(function(){ $(this).children(".showmenu").slideToggle(); $(this).toggleClass("activemainmenu"); $(this).find(".showarrowmainmen ...

I'm having trouble with my Typescript file in Vscode - every time I try to edit the css code, all the text turns red. Can someone

Check out this visual representation: [1]: https://i.stack.imgur.com/9yXUJ.png Followed by the corresponding code snippet. export const GlobalStyle = createGlobalStyle` html { height: 100%; } body { background-image: url(${BGImage}); ba ...

I'm having trouble getting my button to work with addEventListener while using Ejs and Express. What could

Creating a Twitter-like platform where I can post tweets and have them display on the same page has been quite challenging. I've set up each post to have an Edit button initially hidden with 'display:none'. However, when I try to click on th ...

What is the best way to prevent useEffect from triggering when a modal is being rendered?

I'm currently developing a react movie application. I am facing an issue with the hero picture feature that displays a random popular movie or show. Whenever I click the button to open a modal, the useEffect function is triggered and changes the movie ...

Managing HTML5 Video in a slider

I've designed a unique video slider that cycles through 4 videos. Each video has a custom play button and additional overlay content. Once the video starts playing, the overlay content and play button fade out to reveal the default video controls. The ...

The installation of the material ui package was unsuccessful

C:\Users\User\Desktop\client4>npm i @material-ui/icons npm ERR! code ERESOLVE npm ERR! ERESOLVE unable to resolve dependency tree npm ERR! npm ERR! While resolving: [email protected] npm ERR! Found: [email protected] ...