Home > Back-end >  Ignoring an Admin with specific command
Ignoring an Admin with specific command

Time:12-16

I have created a anti-abuse command where I want to ignore Administrators of the server and I have used this like const permission = [PermissionFlagsBits.Administrator]; if (message.member.permissions.has(permission)) return; And it gives this error.

TypeError: Cannot read properties of null ( reading "permissions)

It would be great if someone helps me!

I was expecting that it would ignore Administrators and take action though the members..

CodePudding user response:

If you want to use it with an message this would be the solution:

const permission = "ADMINISTRATOR"
if(message.member.permissions.has(permission)){

}

But in your case the problem seems to be that your "member" has no "permissions" in his attributes. You would need to make sure to get a whole GuildMember Object

CodePudding user response:

It looks like the message.member property is null. This means that the message doesn't have any information about the member that sent it, which could be because the message is from a user that is not in the server, or because the message was sent by a bot.

To fix this issue, you can add a check to make sure that message.member is not null before trying to access its permissions property. You can do this with an if statement:

const permission = [PermissionFlagsBits.Administrator];
if (message.member && message.member.permissions.has(permission)) return;

This will only try to check the permissions of the member if message.member is not null, and will do nothing if it is.

  • Related