Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Invite): add deletable getter #3203

Merged
merged 7 commits into from Apr 22, 2019
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/structures/Invite.js
@@ -1,6 +1,7 @@
'use strict';

const { Endpoints } = require('../util/Constants');
const Permissions = require('../util/Permissions');
const Base = require('./Base');

/**
Expand Down Expand Up @@ -91,6 +92,17 @@ class Invite extends Base {
return this.createdTimestamp ? new Date(this.createdTimestamp) : null;
}

/**
* Whether the invite is deletable by the client user
* @type {boolean}
* @readonly
*/
get deletable() {
const guild = this.guild || this.channel.guild;
izexi marked this conversation as resolved.
Show resolved Hide resolved
return this.channel.permissionsFor(this.client.user).has(Permissions.FLAGS.MANAGE_CHANNELS, false) ||
izexi marked this conversation as resolved.
Show resolved Hide resolved
guild.me.permissions.has(Permissions.FLAGS.MANAGE_GUILD);
SpaceEEC marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* The timestamp the invite will expire at
* @type {?number}
Expand Down
3 changes: 2 additions & 1 deletion typings/index.d.ts
Expand Up @@ -614,7 +614,8 @@ declare module 'discord.js' {
constructor(client: Client, data: object);
public channel: GuildChannel;
public code: string;
public readonly createdAt: Date;
public readonly deletable: boolean;
public readonly createdAt: Date | null;
public createdTimestamp: number | null;
public readonly expiresAt: Date | null;
public readonly expiresTimestamp: number | null;
Expand Down