Hi, I'm trying to make a command to ban a user when they type a filtered word 3 times. If they do they get banned. I've done this logic however I've set up a count variable to track the amount of times the user has made the offence. However it just stays at one every time causing for the condition to never be met. Any help will be appreciated 🙂
#Banning a user after 3 attempts
23 messages · Page 1 of 1 (latest)
• What's your exact discord.js npm list discord.js and node node -v version?
• Post the full error stack trace, not just the top part!
• Show your code!
• Explain what exactly your issue is.
• Not a discord.js issue? Check out #useful-servers.
node version: v18.12.1
npm version:
9.1.2
first of all, upon very detection count is being reset to 0 then adding 1 to it
which would keep it at 1 forever
secondly, this would apply to all users and if it worked correctly user 1 says bad word, 2 says bad word, and 3 says bad word, but 3 will get banned
even tho they only said it once
What would be the best way of going about doing this? Or is it not worth the hassle?
Id say work with a database, cuz it’s possible that the bot will restart in the middle of a count
but u don’t necessarily have to
u can utilize javascript maps and store counts with user ids as a key
Map
The Map object holds key-value pairs and remembers the original insertion order of the keys. Any value (both objects and primitive values) may be used as either a key or a value.
or u can use djs collections
something like this?
yea, tho u really shouldn’t be making a new map entry for every message
you should check for an existing entry on detected and if@not make one
for some reason my brain is working propely today would you mind giving me an example?
@frail blaze
this is another version of the code ive came up with
Still haven't been able to increment the value. All the ways I've tried dont seem to work
You make a new Map with every message received. This is not djs related but rather basic JS/coding logic