Context Menu Commands Lowercase Name

Hello, I have noticed when creating a context menu command, despite me writing "Warn" as the command name in the code, it appears as "warn" on the actual context menu.
Solution:
Huh. I don't recall that we lowercase it internally. Anyway, you can just change this.name to "Warn"
Jump to solution
4 Replies
b1nzee
b1nzee13mo ago
import { Command, ApplicationCommandRegistry } from "@sapphire/framework";
import { ApplyOptions } from "@sapphire/decorators";
import {
ModalBuilder,
TextInputBuilder,
TextInputStyle,
ActionRowBuilder,
} from "discord.js";
import { ApplicationCommandType } from "discord-api-types/v10";

@ApplyOptions<Command.Options>({
name: "Warn",
})
export class WarnCommand extends Command {
public async contextMenuRun(
interaction: Command.ContextMenuCommandInteraction
) {
// Fetch Members
const member = await interaction.guild.members.fetch(interaction.user.id);
const target = await interaction.guild.members.fetch(interaction.targetId);

// Check if the user is a moderator
if (member.roles.highest.position <= target.roles.highest.position) {
return interaction.reply({
content: "You cannot warn this member due to role hierarchy.",
ephemeral: true,
});
}

// Create Modal
const modal = new ModalBuilder()
.setCustomId(`warn_${interaction.targetId}`)
.setTitle(`Warn | ${target.user.tag}`)
.addComponents(
new ActionRowBuilder<TextInputBuilder>().addComponents(
new TextInputBuilder()
.setCustomId("warn_reason")
.setLabel("Public Reason")
.setStyle(TextInputStyle.Paragraph)
.setRequired(true)
.setMinLength(10)
.setMaxLength(250)
),
new ActionRowBuilder<TextInputBuilder>().addComponents(
new TextInputBuilder()
.setCustomId("warn_moderation_note")
.setLabel("Moderation Note (Private)")
.setStyle(TextInputStyle.Paragraph)
.setRequired(false)
.setMaxLength(500)
)
);

// Send Modal
return await interaction.showModal(modal);
}

public override registerApplicationCommands(
registry: ApplicationCommandRegistry
) {
registry.registerContextMenuCommand(
(c) => {
c.setName(this.name)
.setType(ApplicationCommandType.User)
.setDefaultMemberPermissions(8192); // Manage Messages
},
{
idHints: ["1110540630091890789"],
}
);
}
}
import { Command, ApplicationCommandRegistry } from "@sapphire/framework";
import { ApplyOptions } from "@sapphire/decorators";
import {
ModalBuilder,
TextInputBuilder,
TextInputStyle,
ActionRowBuilder,
} from "discord.js";
import { ApplicationCommandType } from "discord-api-types/v10";

@ApplyOptions<Command.Options>({
name: "Warn",
})
export class WarnCommand extends Command {
public async contextMenuRun(
interaction: Command.ContextMenuCommandInteraction
) {
// Fetch Members
const member = await interaction.guild.members.fetch(interaction.user.id);
const target = await interaction.guild.members.fetch(interaction.targetId);

// Check if the user is a moderator
if (member.roles.highest.position <= target.roles.highest.position) {
return interaction.reply({
content: "You cannot warn this member due to role hierarchy.",
ephemeral: true,
});
}

// Create Modal
const modal = new ModalBuilder()
.setCustomId(`warn_${interaction.targetId}`)
.setTitle(`Warn | ${target.user.tag}`)
.addComponents(
new ActionRowBuilder<TextInputBuilder>().addComponents(
new TextInputBuilder()
.setCustomId("warn_reason")
.setLabel("Public Reason")
.setStyle(TextInputStyle.Paragraph)
.setRequired(true)
.setMinLength(10)
.setMaxLength(250)
),
new ActionRowBuilder<TextInputBuilder>().addComponents(
new TextInputBuilder()
.setCustomId("warn_moderation_note")
.setLabel("Moderation Note (Private)")
.setStyle(TextInputStyle.Paragraph)
.setRequired(false)
.setMaxLength(500)
)
);

// Send Modal
return await interaction.showModal(modal);
}

public override registerApplicationCommands(
registry: ApplicationCommandRegistry
) {
registry.registerContextMenuCommand(
(c) => {
c.setName(this.name)
.setType(ApplicationCommandType.User)
.setDefaultMemberPermissions(8192); // Manage Messages
},
{
idHints: ["1110540630091890789"],
}
);
}
}
Solution
Favna
Favna13mo ago
Huh. I don't recall that we lowercase it internally. Anyway, you can just change this.name to "Warn"
b1nzee
b1nzee13mo ago
That worked, thank you