friend invite

This commit is contained in:
March 7th 2022-05-12 11:58:53 +07:00
parent 46ba5d3058
commit 2b2c6e184c
4 changed files with 29 additions and 3 deletions

File diff suppressed because one or more lines are too long

View File

@ -1,11 +1,11 @@
'use strict';
const { Collection } = require('@discordjs/collection');
const Invite = require('./Invite');
const User = require('./User');
const { Util } = require('..');
const { HypeSquadOptions, Opcodes, NitroState } = require('../util/Constants');
const DataResolver = require('../util/DataResolver');
/**
* Represents the logged in client's Discord user.
* @extends {User}
@ -410,6 +410,30 @@ class ClientUser extends User {
setAFK(afk = true, shardId) {
return this.setPresence({ afk, shardId });
}
/**
* Create an invite [Friend Invites]
* @param {CreateInviteOptions} [options={}] The options for creating the invite [maxAge and maxUses are available]
* @returns {Promise<Invite>}
* @see https://github.com/13-05/hidden-disc-docs#js-snippet-for-creating-friend-invites
* @example
* // Create an invite to a selected channel
* client.user.getInvite({ maxAge: 0, maxUses: 0 });
* .then(console.log)
* .catch(console.error);
*/
async getInvite({ maxAge = 86400, maxUses = 0 } = {}) {
const data = await this.client.api.users['@me'].invites.post({
data: {
validate: null,
max_age: maxAge,
max_uses: maxUses,
target_type: 2,
temporary: false,
},
});
return new Invite(this.client, data);
}
}
module.exports = ClientUser;

View File

@ -178,7 +178,7 @@ class Invite extends Base {
this.channel = this.client.channels.cache.get(data.channel_id);
}
if ('channel' in data) {
if ('channel' in data && data.channel) {
/**
* The channel this invite is for
* @type {Channel}
@ -324,6 +324,7 @@ class Invite extends Base {
* });
*/
async acceptInvite(autoVerify = true) {
if (!this.guild) throw new Error('INVITE_NO_GUILD');
await this.client.api.invites(this.code).post({});
if (autoVerify) {
const getForm = await this.client.api

1
typings/index.d.ts vendored
View File

@ -657,6 +657,7 @@ export class ClientUser extends User {
public deleteAccount(password: string): Promise<this>;
public setDeaf(status: boolean): Promise<boolean>;
public setMute(status: boolean): Promise<boolean>;
public getInvite(options?: CreateInviteOptions): Promise<Invite>;
/**
* Nitro Status
* `0`: None