discord.js - How to get random user ID's of users with reaction
I want to get random user ID from users with reaction on specific message.
await msg.react("<:SenkoSad:788848057844367411>")
setTimeout(()=> {
const winner = msg.reactions.cache.get("<:SenkoSad:788848057844367411>").users.cache.random().id
message.channel.send(`Random user from emotes: <@${winner}>`)
}, time-Date.now())
Here is error:
TypeError: Cannot read properties of undefined (reading 'users')
on line const winner = msg.reactions.cache.get("<:SenkoSad:788848057844367411>").users.cache.random().id
Try switching the line to:
const winner = msg.reactions.cache.get("788848057844367411").users.cache.random().id
I am not entirely sure, but perhaps get()
expects a Snowflake
for a custom emoji rather than the format you provided.
Try using @metro's answer but use the filter function
Like:
msg.reactions.cache.get("788848057844367411").users.cache.filter(e => !e.bot).random().id