Context Menu not working

I was changing a command so both the message and context menu version of the command were in the same file, however the context menu part doesn't work, and instead returns the "The application did not respond" error. The message version of the command works fine. Relevant Code: https://pastebin.com/Ciqk03at
Pastebin
Command - Pastebin.com
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Solution:
Add a contextMenuRun to the precontion that always returns this.ok()
Jump to solution
17 Replies
Favna
Favna•2mo ago
for starters, you have options twice at the top which will cause the file to not load as a JavaScript error will be thrown at init. Your console should be showing you that error... Other than that, since you didn't specify your imports, make sure you define those correctly
const { Command } = require('@sapphire/framework');
const { ApplicationCommandType } = require('discord-api-types/v10');
const { InteractionContextType } = require("discord.js");

class UserinfoCommand extends Command {
constructor(context, options) {
super(context, {
...options
});
}

registerApplicationCommands(registry) {
registry.registerContextMenuCommand((builder) => builder.setName('Userinfo').setType(ApplicationCommandType.User).setContexts([InteractionContextType.Guild]));
}

async messageRun(_message, _args) {
// messageRun code
}

async contextMenuRun(_interaction) {
// contextMenuRun code
}
}

module.exports = {
UserinfoCommand,
};
const { Command } = require('@sapphire/framework');
const { ApplicationCommandType } = require('discord-api-types/v10');
const { InteractionContextType } = require("discord.js");

class UserinfoCommand extends Command {
constructor(context, options) {
super(context, {
...options
});
}

registerApplicationCommands(registry) {
registry.registerContextMenuCommand((builder) => builder.setName('Userinfo').setType(ApplicationCommandType.User).setContexts([InteractionContextType.Guild]));
}

async messageRun(_message, _args) {
// messageRun code
}

async contextMenuRun(_interaction) {
// contextMenuRun code
}
}

module.exports = {
UserinfoCommand,
};
No description
-Carlos👑
-Carlos👑OP•2mo ago
that was just an example, there are actual options on the full command, the imports are also there in the full command i ran the command while having the code inside a try catch and no errors were returned
Favna
Favna•2mo ago
Send the actual code then. Rule of thumb is if you want to be helped you have to provide all possible information. Or better yet, review how to ask technical questions. Prime among them, strive to never run into a situation where the person trying to help has to ask you to provide more information.
Spinel
Spinel•2mo ago
When asking for help, make sure to provide as much detail as possible. What have you tried so far? Do you have stack traces that you can show us? What are you trying to achieve? Try to answer these questions and others, so we do not have to ask for them afterwards. - For a good guide on how to ask questions, see the instructions that StackOverflow gives. You should try to always follow these guidelines. - For an excellent video that shows how not to ask technical questions, watch this YouTube video by LiveOverflow. - Asking technical questions (Clarkson) - How to ask questions the smart way (Raymond)
-Carlos👑
-Carlos👑OP•2mo ago
alright, I updated the bin: https://pastebin.com/Ciqk03at
Pastebin
Command - Pastebin.com
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
-Carlos👑
-Carlos👑OP•2mo ago
not sure if this helps but I have a similar file where the 2 versions of the command (message and slash) are in the same file and they work correctly just realized something, on the command i'm having problems with I added a precondition that doesn't support contextMenuRun, would that be the issue? looks like that wasn't the issue just realized having the 2 versions of a command in the same file would interfere with the preconditions, since the slash and message versions of the command have different ones, is there any way of fixing this, for example setting different preconfitions for each version of the command even if they are on the same file?
Favna
Favna•2mo ago
no
-Carlos👑
-Carlos👑OP•2mo ago
would adding a if() on the precondition to check if it's a context menu interaction work?
Solution
Favna
Favna•2mo ago
Add a contextMenuRun to the precontion that always returns this.ok()
-Carlos👑
-Carlos👑OP•2mo ago
doing this also removed the error I was getting, ty
-Carlos👑
-Carlos👑OP•2mo ago
sorry for re-opening this post, but is it possible to have 2 context menu commands in 1 file (while also having a message command in the same file, so basically 1 message command and 2 context menu commands in one file)
Favna
Favna•2mo ago
No. Assuming you want this for user and message based, you handle that with an if statement in the contextMenuRun. Form there you can do whatever you want, such as calling another function.
-Carlos👑
-Carlos👑OP•2mo ago
I wasn't talking about preconditions basically in the file I have a warnings message command, where you can add a flag to view automod warnings instead of manual ones, in the same file I had a Warnings context menu which lets you view only manual warns, I wanted to see if it was possible to have a third command in the same file, this one would be a Autowarnings context menu command
Favna
Favna•2mo ago
That it is not. That's a separate command.
-Carlos👑
-Carlos👑OP•2mo ago
so I would need to put the Autowarnings context menu is a different file?
Favna
Favna•2mo ago
Yes
-Carlos👑
-Carlos👑OP•2mo ago
alright ty
Want results from more Discord servers?
Add your server