User Permissions

In the User Roles chapter we used the role for verifying if the user could use our KickCommand.

If you don't care the role of the user but you care if he have the permissions for kicking a user, then you can refactor the KickCommand for only requiring the user to have the permission for kicking members.

Refactoring KickCommand#

path/to/your/app/src/Commands/KickCommand.ts
import {
Command,
BaseCommand,
Argument,
Mention,
Author,
UserContract,
} from "discapp";
@Command({
permissions: ["KICK_MEMBERS"],
clientPermissions: ["KICK_MEMBERS"],
})
export class KickCommand extends BaseCommand {
@Argument()
public user: Mention;
@Author()
public author: UserContract;
public async execute() {
const userAsMember = await this.user.asMember();
if (userAsMember.kickable) {
await userAsMember.kick();
return `${this.author} kicked ${this.user}`;
}
return `Can't kick ${this.user}`;
}
}