Cold
Cold
SIASapphire - Imagine a framework
Created by Cold on 5/26/2024 in #sapphire-support
How do I force a user to specify at least one input?
I'm working on a bot, and at the moment the bot errors out if the user does not specify any argument. For reference, this is how my command is structured:
public override registerApplicationCommands(registry: Command.Registry) {
registry.registerChatInputCommand((builder) =>
builder
.setName("about")
.setDescription(
"Find details regarding a user's account on the server list.",
)
.addUserOption((option) =>
option
.setName("by_mention")
.setDescription("User to find by mention."),
)
.addStringOption((option) =>
option
.setName("by_uuid")
.setDescription("User to find by UUID."),
)
.setDMPermission(false)
.setDefaultMemberPermissions(PermissionFlagsBits.KickMembers),
);
}
public override registerApplicationCommands(registry: Command.Registry) {
registry.registerChatInputCommand((builder) =>
builder
.setName("about")
.setDescription(
"Find details regarding a user's account on the server list.",
)
.addUserOption((option) =>
option
.setName("by_mention")
.setDescription("User to find by mention."),
)
.addStringOption((option) =>
option
.setName("by_uuid")
.setDescription("User to find by UUID."),
)
.setDMPermission(false)
.setDefaultMemberPermissions(PermissionFlagsBits.KickMembers),
);
}
This is how I'm validating whether or not an argument has been specified; but strangely this kicks out an error:
const mention = interaction.options.getUser("by_mention");
const uuid = interaction.options.getString("by_uuid");

if (!mention && !uuid)
return interaction.reply({
embeds: [
embedBuilder(
this.container.client,
"You must either specify a user mention, or a UUID to find the user by.",
),
],
ephemeral: true,
});
const mention = interaction.options.getUser("by_mention");
const uuid = interaction.options.getString("by_uuid");

if (!mention && !uuid)
return interaction.reply({
embeds: [
embedBuilder(
this.container.client,
"You must either specify a user mention, or a UUID to find the user by.",
),
],
ephemeral: true,
});
How do I fix this?
6 replies
SIASapphire - Imagine a framework
Created by Cold on 5/7/2024 in #sapphire-support
Help with slash commands
Hello, I'm trying to work on a project that involves doing some type of user lookup in a database. My current code looks like this:
public override registerApplicationCommands(registry: Command.Registry) {
registry.registerChatInputCommand((builder) =>
builder
.setName("find")
.setDescription("Find a user on the server list.")
.addStringOption((option) =>
option
.setName("user")
.setDescription("User to find.")
.setRequired(true),
)
.setDMPermission(false)
.setDefaultMemberPermissions(PermissionFlagsBits.KickMembers),
);
}
public override registerApplicationCommands(registry: Command.Registry) {
registry.registerChatInputCommand((builder) =>
builder
.setName("find")
.setDescription("Find a user on the server list.")
.addStringOption((option) =>
option
.setName("user")
.setDescription("User to find.")
.setRequired(true),
)
.setDMPermission(false)
.setDefaultMemberPermissions(PermissionFlagsBits.KickMembers),
);
}
Ideally, I want the user to be able to provide either a user @mention, or a user ID, or even a username. What would be the best way to approach this?
7 replies