#context menus not working

17 messages · Page 1 of 1 (latest)

true belfry
#

code:

const { ContextMenuCommandBuilder, ApplicationCommandType } = require("discord.js")

module.exports = {
    data: new ContextMenuCommandBuilder()
    .setName("Test")
    .setType(ApplicationCommandType.User),
    async run (interaction) {
        await interaction.reply({ content: "This worked", ephemeral: true })
    }
}```

interactionCreate event:
```js
client.on('interactionCreate', async (interaction) => {
    if (!interaction.isUserContextMenuCommand()) return;
    const { commands } = client
    const { commandName } = interaction
    const contextCommand = commands.get(commandName)
    if(!contextCommand) return;
    console.log(interaction.commandId)

    try {
        await contextCommand.run(interaction)
    } catch (e) {
        console.log(e)
    }
});```

Issue:
bot returns `The application did not respond`

For some reason `console.log(contextCommand)` doesn't return anything
icy aurora
#

• What's your exact discord.js npm list discord.js and node node -v version?
• Post the full error stack trace, not just the top part!
• Show your code!
• Explain what exactly your issue is.
• Not a discord.js issue? Check out #useful-servers.

true belfry
#

someone?

hardy pagoda
#

if console.log(interaction.commandId) didn't log anything, then it did not execute
this means that either this listener didn't execute due to it not being registered properly, or it was unable to find a command in your commands collection with that key

weary riverBOT
#

If you aren't getting any errors, try to place console.log checkpoints throughout your code to find out where execution stops.
• Once you do, log relevant values and if-conditions
• More sophisticated debugging methods are breakpoints and runtime inspections: learn more

true belfry
# hardy pagoda if `console.log(interaction.commandId)` didn't log anything, then it did not exe...

got this

client.on('interactionCreate', async (interaction) => {
    if (!interaction.isUserContextMenuCommand()) return;
    const { commands } = client
    const { commandName } = interaction
    console.log(commandName)
    const contextCommand = commands.get(commandName)
    console.log(contextCommand)
    if(!contextCommand) return;

    try {
        console.log(contextCommand.run(interaction))
        await contextCommand.run(interaction)
    } catch (e) {
        console.log(e)
    }
});```
hardy pagoda
true belfry
#

yes

hardy pagoda
#

then it was unable to find a command with the key Test in your commands collection

true belfry
#

what could be the reason

hardy pagoda
#

not setting it properly, since that's your collection that you created

true belfry
hardy pagoda
#

since the issue is that it wasn't set properly, the issue will be where you set the commands in the commands collection 🙂

true belfry
hardy pagoda
#

yep

#

command in this context will be the object exported by your command files, so that means it has data and run

#

likely you wanted to access command.data.name for the command's name, rather than command.name