Search code examples
discord.jscommandbots

Discord JS - Message Command in User Bot


I want to make a Discord bot (in node js) that has a context menu command. Only thing is that it's for a user bot (Discord's new feature - installing an app on a discord account).

I currently use this:

await client.application.commands.set([
    new ContextMenuCommandBuilder()
        .setName('transcript')
        .setType(ApplicationCommandType.Message),
]);

And in servers it works perfectly, but in DM nothing shows up... I added the bot on my account using this link: https://discord.com/oauth2/authorize?client_id=MY_ACTUAL_CLIENT_ID and then clicking on the install on my account button. I checked in the authorised apps and it is there with "create commands".

Thank you.


Solution

  • discord.js does not currently support creating user install commands with their builders. To enable user install commands, when posting the command set integration_types to [1] or [0, 1] for guild install as well. You can read more about them here and here.

    You can try posting it directly using the rest. Import routes from discord.js.

    client.once('ready', ready => {
        ready.rest.post(Routes.applicationCommands(ready.user.id), {
            body: {
                name: "transcript",
                type: ApplicationCommandType.Message,
                integration_types: [1],
            }
        });
    });