Validation Error in Mongoose/djs
Hello! I am trying to write a command called
/moderator
with a sub-command /moderator add
which adds a user's ID to a moderator database (MongoDB/Mongoose) which is then checked anytime someone wants to run a moderator command.
Here is my related code (djs v14.16.2):
moderator.js
ModeratorSchema.js
Thanks in advance for any help!4 Replies
- What's your exact discord.js
npm list discord.js
and node node -v
version?
- Not a discord.js issue? Check out #other-js-ts.
- Consider reading #how-to-get-help to improve your question!
- Explain what exactly your issue is.
- Post the full error stack trace, not just the top part!
- Show your code!
- Issue solved? Press the button!
- ✅
Marked as resolved by OPI made it so the code does add moderators (username, user_id, type) to a database, but I can't seem to get validation checks to work to make sure people don't add a user id multiple times. I am using mongoose for schemas, and made user_id unique, so while the system won't add a user document multiple times, the discord output isn't working still.
A) as this is more related to your DB, #other-js-ts is more appropriate
B) your user_id option would be better suited as a UserOption instead of a string option - it would validate the input to make sure it's a valid user and also simplify your code - target would much be just the options.getUser(...) and get the username and id from target
C) probably better to search by the id instead of the username, as they are unique and can't be changed, that's why d.js keys the cache by them
D) troubleshoot the result of your DB query and see what it's returning
It's returning a full output of what it seems like is the entire schema... but when I do the following to cover everything it could output:
It just doesn't respond at all, no error output either, I'm not sure why
I updated target to be a User like you said
Okay, thanks!