GuildMemberAdded not working
whenever I ask someone to join, it doesnt run and I cannot trace why
16 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!Why is this
once
?
Does your client have the GuildMembers intent?cuz its only supposed to run once, is that the incorrect behaviour
yes
it'll only run in the first user that joins though
then the listener would be unregistered, so further joins wouldn't call that
pretty sure that's not what you want
you don't want to run the event only once, you want it to run once per user
you could either code that or change your db logic to use an upsert
which is basically a "create, but if it exists update with this" call
you wouldn't update with anything though so just pass nothing on that
check prisma's docs on upsert
for each command there's a once param so ill tr changing that first cuz the create logic will only push new data to the database, while im here is it possible to check if someone bought a SKU?
for each command there's a once paramwe get that, and we're assuming it behaves like EventEmitter#once(), which unregisters the listener after it's called once
the create logic will only push new datayou don't want to create the same member twice though, that's why I recommended an upsert, which will first try to find if there's a row that matches some data
are we assuming case of "Leave & Rejoining"?
on my second answer yes
I'm assuming you have an autoincremented id field
nope, its cuid
which would be your primary key
well, I mostly meant about it being autogenerated
ok, yea
the point I'm trying to make is that duplicate records are possible in that setup
if they rejoin
assuming that GuildMemberRemove detects when a user is removed ffrom the server, I handle deleting the data
ah, that should solve it then
your only issue would be that once in that case
ok, i just thought about this before making the change, so If i run my bot, it still doesnt detect a user joining, I can run a sim join, but whenever i have a friend join it still doesnt detect
I can double check without the once, but its seems like weird behavior
it should only run for the first join it detects
which is exactly what once does
or well EventEmitter#once()
if your once works in some other way we don't have any way to tell, but using EventEmitter's would be the reasonable way