Need help for ContextMenuCommand

I have the below code:
import { PaginatedMessage } from "@sapphire/discord.js-utilities";
import { Command } from "@sapphire/framework";
import { config } from "../../utils/config";
import { ApplicationCommandType, Colors } from "discord.js";

export class UserinfoCommand extends Command {
public constructor(context: Command.LoaderContext, options: Command.Options) {
super(context, { ...options });
}

public override registerApplicationCommands(registry: Command.Registry) {
registry.registerContextMenuCommand((builder) =>
builder //
.setName('Userinfo')
.setType(ApplicationCommandType.User)
);
}

public async contextMenuRun(interaction: Command.ContextMenuCommandInteraction) {
const User = interaction.user
let Botted = "No"
if(User.bot) Botted = "Yes"
console.log(User.hexAccentColor)

new PaginatedMessage()
.addPageEmbed((embed) => {
embed
.setAuthor({ name: User.displayName, iconURL: User.displayAvatarURL({ forceStatic: true }), url: `https://discord.com/users/${User.id}` })
.setColor(User.hexAccentColor)
.setTitle("General Userinfo")
.addFields([
{
name: "DisplayName",
value: User.displayName,
inline: true
},
{
name: "Username",
value: User.username,
inline: true
},
{
name: "Botted User?",
value: Botted,
inline: true
},
{
name: "Created Time",
value: `<t:${User.createdTimestamp}> (<t:${User.createdTimestamp}:R>)`,
inline: true
},
])

return embed;
})
.addPageEmbed((embed) => {
embed
.setColor(Colors.Blurple)
.setTitle("Information")
.setDescription(``);

return embed;
})
.addPageEmbed((embed) => {
embed
.setColor(Colors.Blurple)
.setTitle("Command List")
.setDescription(``);

return embed;
})
.addPageEmbed((embed) => {
embed
.setColor(Colors.Blurple)
.setTitle("Important Links")
.setDescription(``);

return embed;
})
.run(interaction, interaction.user);
}
};
import { PaginatedMessage } from "@sapphire/discord.js-utilities";
import { Command } from "@sapphire/framework";
import { config } from "../../utils/config";
import { ApplicationCommandType, Colors } from "discord.js";

export class UserinfoCommand extends Command {
public constructor(context: Command.LoaderContext, options: Command.Options) {
super(context, { ...options });
}

public override registerApplicationCommands(registry: Command.Registry) {
registry.registerContextMenuCommand((builder) =>
builder //
.setName('Userinfo')
.setType(ApplicationCommandType.User)
);
}

public async contextMenuRun(interaction: Command.ContextMenuCommandInteraction) {
const User = interaction.user
let Botted = "No"
if(User.bot) Botted = "Yes"
console.log(User.hexAccentColor)

new PaginatedMessage()
.addPageEmbed((embed) => {
embed
.setAuthor({ name: User.displayName, iconURL: User.displayAvatarURL({ forceStatic: true }), url: `https://discord.com/users/${User.id}` })
.setColor(User.hexAccentColor)
.setTitle("General Userinfo")
.addFields([
{
name: "DisplayName",
value: User.displayName,
inline: true
},
{
name: "Username",
value: User.username,
inline: true
},
{
name: "Botted User?",
value: Botted,
inline: true
},
{
name: "Created Time",
value: `<t:${User.createdTimestamp}> (<t:${User.createdTimestamp}:R>)`,
inline: true
},
])

return embed;
})
.addPageEmbed((embed) => {
embed
.setColor(Colors.Blurple)
.setTitle("Information")
.setDescription(``);

return embed;
})
.addPageEmbed((embed) => {
embed
.setColor(Colors.Blurple)
.setTitle("Command List")
.setDescription(``);

return embed;
})
.addPageEmbed((embed) => {
embed
.setColor(Colors.Blurple)
.setTitle("Important Links")
.setDescription(``);

return embed;
})
.run(interaction, interaction.user);
}
};
And it errors on the
.run(interaction, interaction.user)
.run(interaction, interaction.user)
part. What's the cause and how to fix it?
Solution:
@Jarvo
- public override async contextMenuRun(interaction: Command.ContextMenuCommandInteraction) {
+ public override async contextMenuRun(interaction: UserContextMenuCommandInteraction) {
- public override async contextMenuRun(interaction: Command.ContextMenuCommandInteraction) {
+ public override async contextMenuRun(interaction: UserContextMenuCommandInteraction) {
...
Jump to solution
28 Replies
Favna
Favna10mo ago
What's the error?
Jarvo
Jarvo10mo ago
Let me grab it real quick
[{
"resource": "/src/commands/ContextMenuCommands/userinfo.ts",
"owner": "_generated_diagnostic_collection_name_#0",
"code": "2345",
"severity": 8,
"message": "Argument of type 'ContextMenuCommandInteraction<CacheType>' is not assignable to parameter of type 'Message<boolean> | AnyInteractableInteraction'.\n Type 'ContextMenuCommandInteraction<CacheType>' is not assignable to type 'ChatInputCommandInteraction<CacheType> | MessageContextMenuCommandInteraction<CacheType> | UserContextMenuCommandInteraction<...>'.\n Type 'ContextMenuCommandInteraction<CacheType>' is missing the following properties from type 'UserContextMenuCommandInteraction<CacheType>': targetUser, targetMember",
"source": "ts",
"startLineNumber": 80,
"startColumn": 12,
"endLineNumber": 80,
"endColumn": 23
}]
[{
"resource": "/src/commands/ContextMenuCommands/userinfo.ts",
"owner": "_generated_diagnostic_collection_name_#0",
"code": "2345",
"severity": 8,
"message": "Argument of type 'ContextMenuCommandInteraction<CacheType>' is not assignable to parameter of type 'Message<boolean> | AnyInteractableInteraction'.\n Type 'ContextMenuCommandInteraction<CacheType>' is not assignable to type 'ChatInputCommandInteraction<CacheType> | MessageContextMenuCommandInteraction<CacheType> | UserContextMenuCommandInteraction<...>'.\n Type 'ContextMenuCommandInteraction<CacheType>' is missing the following properties from type 'UserContextMenuCommandInteraction<CacheType>': targetUser, targetMember",
"source": "ts",
"startLineNumber": 80,
"startColumn": 12,
"endLineNumber": 80,
"endColumn": 23
}]
That's all It still doesn't runs.
Favna
Favna10mo ago
@Helpers
Solution
Favna
Favna10mo ago
@Jarvo
- public override async contextMenuRun(interaction: Command.ContextMenuCommandInteraction) {
+ public override async contextMenuRun(interaction: UserContextMenuCommandInteraction) {
- public override async contextMenuRun(interaction: Command.ContextMenuCommandInteraction) {
+ public override async contextMenuRun(interaction: UserContextMenuCommandInteraction) {
And you also have this error:
- .setColor(User.hexAccentColor)
+ .setColor(User.hexAccentColor ?? null)
- .setColor(User.hexAccentColor)
+ .setColor(User.hexAccentColor ?? null)
Favna
Favna10mo ago
As an aside, what makes your errors formatted like that if I might ask? That's not how tsc formats its errors
No description
Jarvo
Jarvo10mo ago
Ooohhh. Damn. Thanks
vladdy
vladdy10mo ago
thats literally tsc
Favna
Favna10mo ago
why is it json Thonkang
vladdy
vladdy10mo ago
oh shrug looks like LSP response ngl
Jarvo
Jarvo10mo ago
And you also have this error: - .setColor(User.hexAccentColor) + .setColor(User.hexAccentColor ?? null)
I already got that fixed. And from where do I import UserContextMenuCommandInteraction @vladdy?
vladdy
vladdy10mo ago
discord.js
Jarvo
Jarvo10mo ago
Okay It's saying Application did not respond
Jarvo
Jarvo10mo ago
This is the current code.
Favna
Favna10mo ago
Defer before doing anything else. You're likely not responding within 3 seconds. Also the second parameter is superfluous, interaction.user is the default. Constructor is also superfluous, you're not changing anything versus the base constructor.
Jarvo
Jarvo10mo ago
Okay I am not that good, but I don't understand what you're saying. I have to defer it... Why? Because at other commands I also work with the same PaginationEmbed
Favna
Favna10mo ago
presumably you're not responding within 3 seconds between fetching a member and all the fields you're adding with all the data you're adding that can easily run into the few seconds.
vladdy
vladdy10mo ago
(not really but when you add all latencies up, it can happen)
Jarvo
Jarvo10mo ago
Ah. How to register handlers? Like the buttonhandler? I have the buttonhandler in a file. The content is:
import { InteractionHandler, InteractionHandlerTypes } from '@sapphire/framework';
import { EmbedBuilder, Colors } from "discord.js";
import type { ButtonInteraction } from 'discord.js';
import { config } from "../../../utils/config";

export class ButtonHandler extends InteractionHandler {
public constructor(ctx: InteractionHandler.LoaderContext, options: InteractionHandler.Options) {
super(ctx, {
...options,
interactionHandlerType: InteractionHandlerTypes.Button
});
}

public override parse(interaction: ButtonInteraction) {
if (interaction.customId !== 'cancel-setup') return this.none();

return this.some();
}

public async run(interaction: ButtonInteraction) {
if (!interaction.isButton()) return;
const embed = new EmbedBuilder()
.setTitle("❌ Setup Cancelled")
.setColor(Colors.Red)
.setFooter({text: `${config.general.MessageEmbedItems.footer.text}`});

await interaction.editReply({ embeds: [embed], components: [] });
}
}
import { InteractionHandler, InteractionHandlerTypes } from '@sapphire/framework';
import { EmbedBuilder, Colors } from "discord.js";
import type { ButtonInteraction } from 'discord.js';
import { config } from "../../../utils/config";

export class ButtonHandler extends InteractionHandler {
public constructor(ctx: InteractionHandler.LoaderContext, options: InteractionHandler.Options) {
super(ctx, {
...options,
interactionHandlerType: InteractionHandlerTypes.Button
});
}

public override parse(interaction: ButtonInteraction) {
if (interaction.customId !== 'cancel-setup') return this.none();

return this.some();
}

public async run(interaction: ButtonInteraction) {
if (!interaction.isButton()) return;
const embed = new EmbedBuilder()
.setTitle("❌ Setup Cancelled")
.setColor(Colors.Red)
.setFooter({text: `${config.general.MessageEmbedItems.footer.text}`});

await interaction.editReply({ embeds: [embed], components: [] });
}
}
Favna
Favna10mo ago
https://www.sapphirejs.dev/docs/Guide/interaction-handlers/what-are-they Also please create new threads for proper question tracking.
Sapphire Framework
What are they? | Sapphire
These are interaction handlers! A simple class you can extend to handle almost all the interactions you may receive in
Jarvo
Jarvo10mo ago
Thx Okay I am gonna re-open this because it still won't send... I have the .run(interaction) at the bottom and I don't why it still won't send. @Favna
Jarvo
Jarvo10mo ago
Here's the code again:
Favna
Favna10mo ago
You're returning early, as helpfully stated by ESLint as well
No description
Jarvo
Jarvo10mo ago
What's with the first line of code?
Favna
Favna10mo ago
it's where the eslint warning shows up because it's the function
Jarvo
Jarvo10mo ago
Not all code paths return a value?
Jarvo
Jarvo10mo ago
Sapphire Framework
Creating a basic context menu command | Sapphire
This section covers the absolute minimum for setting up a message context menu command. We have an entire
Favna
Favna10mo ago
I don't know how I can explain this in another way mate Thonkang returning from the function before you call new PaginatedMessage etc that code never gets executed You either shouldn't return at all there, or you should analyze which return is being triggered and make sure it doesnt this really is JavaScript for beginners teritory
Jarvo
Jarvo10mo ago
Got it fixed.
Want results from more Discord servers?
Add your server