Context Menu

Hey, I'm trying to register context menu commands but not sure how.
I've a command handler that sending a put request to discord with a set of comamnds, and it does work well, but im not sure how to do that with the context menus..

example of a menu event file:
import type { ContextMenu } from '@/types/discord'
import { ApplicationCommandType, ContextMenuCommandBuilder } from 'discord.js'

const ClearCommand: ContextMenu = {
    command: new ContextMenuCommandBuilder().setName('Profile').setType(ApplicationCommandType.User),

    execute: (interaction) => {
        console.log(interaction)
    },

    description: 'Gets the user profile in the website',
    cooldown: 5,
    staff: false,
}

export default ClearCommand


And this is my menu handler, which doesnt work.
sometimes it does work for 2 seconds and then doesnt for a few minutes, but im not even think it should work like that..

        const dir = readdirp(menusDir, { fileFilter: ['*.ts', '*.js'] })

        for await (const file of dir) {
            let contextMenu: ContextMenu = (await import(`${pathToFileURL(file.fullPath)}`)).default
            contextMenus.push(contextMenu.command)
            client.contextMenus.set(contextMenu.command.name, contextMenu)
        }

        const rest = new REST({ version: '10' }).setToken(process.env.BOT_TOKEN!)

        const isDev = process.env.MODE === 'dev'

        const route = isDev
            ? Routes.applicationGuildCommands(process.env.BOT_CLIENT_ID!, process.env.GUILD_ID!)
            : Routes.applicationCommands(process.env.BOT_CLIENT_ID!)

        // Should I do that?
        const data: any = await rest.put(route, {
            body: contextMenus,
            headers: { 'Content-Type': 'application/json' },
        })
...


Thanks!
Was this page helpful?