Reputation: 83
I recently noticed that interactions can still be made even if a user is not in a guild this is the case in for example the server preview mode
This is causing a few issues for me
does anyone know if there is a convinient way to detect if the user who created the interaction is a guild member? Or could I block all interactions from non guild members ?
Upvotes: 2
Views: 4213
Reputation: 656
You can use Guild.members.cache.some
to determine if the user exists.
const exists = interaction.guild.members.cache.some(x => x.id == interaction.user.id)
Upvotes: 1
Reputation: 33
You can try the following piece of code:
const user_exists = (<interaction>.guild.users.cache.find(user => user.id === <interaction>.user.id)) ? true : false
This will return true if the user exists and false if not, so you can run a check:
if(!user_exists) // Tell the person they cannot run the command
Upvotes: 0
Reputation: 546
you can search user in the guild and return if it's null.
var user = guild.users.cache.find(user => user.id === 'USER-ID')
if(!user) return
Upvotes: 2