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?
Solution:
instead of adding a string option, add a user option. You can see this in action with many of @Spinel 's commands for the target option
Jump to solution
3 Replies
Solution
Favna
Favna7mo ago
instead of adding a string option, add a user option. You can see this in action with many of @Spinel 's commands for the target option
Favna
Favna7mo ago
then you dont even need to parse it at all anymore because you always get the user
Cold
ColdOP7mo ago
What about in events where I just want to search for a username? Actually, there is a way I could implement it.. nevermind, thanks
Want results from more Discord servers?
Add your server