Skip to content
Advertisement

How to find a discord.js user’s permissions from a message mention?

I’m making a ban command and I need to check if the target user has administrator permissions. I’ve tried:

const user = message.mentions.users.first();
const userMember = message.guild.members.fetch(user)

But I’m getting an error: TypeError: userMember.hasPermission is not a function

Is there a way to fix this?

Advertisement

Answer

.fetch() returns a promise so you need to await the results:

const userMember = await message.guild.members.fetch(user)
userMember.hasPermission()

You could also get the member instead of the user from the mentions:

const member = message.mentions.members.first()
member.hasPermission()
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement