mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-19 21:13:30 +01:00
feat(GuildChannel): createInvite target options (#5514)
Co-authored-by: Antonio Román <kyradiscord@gmail.com> Co-authored-by: Advaith <advaithj1@gmail.com>
This commit is contained in:
@@ -30,7 +30,7 @@ class ClientApplication extends Application {
|
|||||||
this.flags = 'flags' in data ? new ApplicationFlags(data.flags) : this.flags;
|
this.flags = 'flags' in data ? new ApplicationFlags(data.flags) : this.flags;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The app's cover image
|
* The hash of the application's cover image
|
||||||
* @type {?string}
|
* @type {?string}
|
||||||
*/
|
*/
|
||||||
this.cover = data.cover_image ?? this.cover ?? null;
|
this.cover = data.cover_image ?? this.cover ?? null;
|
||||||
|
|||||||
@@ -483,6 +483,14 @@ class GuildChannel extends Channel {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Data that can be resolved to an Application. This can be:
|
||||||
|
* * An Application
|
||||||
|
* * An Activity with associated Application
|
||||||
|
* * A Snowflake
|
||||||
|
* @typedef {Application|Snowflake} ApplicationResolvable
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an invite to this guild channel.
|
* Creates an invite to this guild channel.
|
||||||
* @param {Object} [options={}] Options for the invite
|
* @param {Object} [options={}] Options for the invite
|
||||||
@@ -491,6 +499,11 @@ class GuildChannel extends Channel {
|
|||||||
* @param {number} [options.maxAge=86400] How long the invite should last (in seconds, 0 for forever)
|
* @param {number} [options.maxAge=86400] How long the invite should last (in seconds, 0 for forever)
|
||||||
* @param {number} [options.maxUses=0] Maximum number of uses
|
* @param {number} [options.maxUses=0] Maximum number of uses
|
||||||
* @param {boolean} [options.unique=false] Create a unique invite, or use an existing one with similar settings
|
* @param {boolean} [options.unique=false] Create a unique invite, or use an existing one with similar settings
|
||||||
|
* @param {UserResolvable} [options.targetUser] The user whose stream to display for this invite,
|
||||||
|
* required if `targetType` is 1, the user must be streaming in the channel
|
||||||
|
* @param {ApplicationResolvable} [options.targetApplication] The embedded application to open for this invite,
|
||||||
|
* required if `targetType` is 2, the application must have the `EMBEDDED` flag
|
||||||
|
* @param {InviteTargetType} [options.targetType] The type of the target for this voice channel invite
|
||||||
* @param {string} [options.reason] Reason for creating this
|
* @param {string} [options.reason] Reason for creating this
|
||||||
* @returns {Promise<Invite>}
|
* @returns {Promise<Invite>}
|
||||||
* @example
|
* @example
|
||||||
@@ -499,7 +512,16 @@ class GuildChannel extends Channel {
|
|||||||
* .then(invite => console.log(`Created an invite with a code of ${invite.code}`))
|
* .then(invite => console.log(`Created an invite with a code of ${invite.code}`))
|
||||||
* .catch(console.error);
|
* .catch(console.error);
|
||||||
*/
|
*/
|
||||||
createInvite({ temporary = false, maxAge = 86400, maxUses = 0, unique, reason } = {}) {
|
createInvite({
|
||||||
|
temporary = false,
|
||||||
|
maxAge = 86400,
|
||||||
|
maxUses = 0,
|
||||||
|
unique,
|
||||||
|
targetUser,
|
||||||
|
targetApplication,
|
||||||
|
targetType,
|
||||||
|
reason,
|
||||||
|
} = {}) {
|
||||||
return this.client.api
|
return this.client.api
|
||||||
.channels(this.id)
|
.channels(this.id)
|
||||||
.invites.post({
|
.invites.post({
|
||||||
@@ -508,6 +530,9 @@ class GuildChannel extends Channel {
|
|||||||
max_age: maxAge,
|
max_age: maxAge,
|
||||||
max_uses: maxUses,
|
max_uses: maxUses,
|
||||||
unique,
|
unique,
|
||||||
|
target_user_id: this.client.users.resolveID(targetUser),
|
||||||
|
target_application_id: targetApplication?.id ?? targetApplication?.applicationID ?? targetApplication,
|
||||||
|
target_type: targetType,
|
||||||
},
|
},
|
||||||
reason,
|
reason,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -15,6 +15,48 @@ class IntegrationApplication extends Application {
|
|||||||
* @type {?User}
|
* @type {?User}
|
||||||
*/
|
*/
|
||||||
this.bot = data.bot ? this.client.users.add(data.bot) : this.bot ?? null;
|
this.bot = data.bot ? this.client.users.add(data.bot) : this.bot ?? null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The url of the app's terms of service
|
||||||
|
* @type {?string}
|
||||||
|
*/
|
||||||
|
this.termsOfServiceURL = data.terms_of_service_url ?? this.termsOfServiceURL ?? null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The url of the app's privacy policy
|
||||||
|
* @type {?string}
|
||||||
|
*/
|
||||||
|
this.privacyPolicyURL = data.privacy_policy_url ?? this.privacyPolicyURL ?? null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Array of RPC origin urls
|
||||||
|
* @type {string[]}
|
||||||
|
*/
|
||||||
|
this.rpcOrigins = data.rpc_origins ?? this.rpcOrigins ?? [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The application summary
|
||||||
|
* @type {?string}
|
||||||
|
*/
|
||||||
|
this.summary = data.summary ?? this.summary ?? null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the application can be default hooked by the client
|
||||||
|
* @type {?boolean}
|
||||||
|
*/
|
||||||
|
this.hook = data.hook ?? this.hook ?? null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The hash of the application's cover image
|
||||||
|
* @type {?string}
|
||||||
|
*/
|
||||||
|
this.cover = data.cover_image ?? this.cover ?? null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The hex-encoded key for verification in interactions and the GameSDK's GetTicket
|
||||||
|
* @type {?string}
|
||||||
|
*/
|
||||||
|
this.verifyKey = data.verify_key ?? this.verifyKey ?? null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const Base = require('./Base');
|
const Base = require('./Base');
|
||||||
|
const IntegrationApplication = require('./IntegrationApplication');
|
||||||
const { Endpoints } = require('../util/Constants');
|
const { Endpoints } = require('../util/Constants');
|
||||||
const Permissions = require('../util/Permissions');
|
const Permissions = require('../util/Permissions');
|
||||||
|
|
||||||
@@ -71,22 +72,31 @@ class Invite extends Base {
|
|||||||
this.inviter = data.inviter ? this.client.users.add(data.inviter) : null;
|
this.inviter = data.inviter ? this.client.users.add(data.inviter) : null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The target user for this invite
|
* The user whose stream to display for this voice channel stream invite
|
||||||
* @type {?User}
|
* @type {?User}
|
||||||
*/
|
*/
|
||||||
this.targetUser = data.target_user ? this.client.users.add(data.target_user) : null;
|
this.targetUser = data.target_user ? this.client.users.add(data.target_user) : null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The type of the target user:
|
* The embedded application to open for this voice channel embedded application invite
|
||||||
|
* @type {?IntegrationApplication}
|
||||||
|
*/
|
||||||
|
this.targetApplication = data.target_application
|
||||||
|
? new IntegrationApplication(this.client, data.target_application)
|
||||||
|
: null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type of the invite target:
|
||||||
* * 1: STREAM
|
* * 1: STREAM
|
||||||
* @typedef {number} TargetUser
|
* * 2: EMBEDDED_APPLICATION
|
||||||
|
* @typedef {number} TargetType
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The target user type
|
* The target type
|
||||||
* @type {?TargetUser}
|
* @type {?TargetType}
|
||||||
*/
|
*/
|
||||||
this.targetUserType = typeof data.target_user_type === 'number' ? data.target_user_type : null;
|
this.targetType = typeof data.target_type === 'number' ? data.target_type : null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The channel the invite is for
|
* The channel the invite is for
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ class Application extends Base {
|
|||||||
* @param {ImageURLOptions} [options={}] Options for the Image URL
|
* @param {ImageURLOptions} [options={}] Options for the Image URL
|
||||||
* @returns {?string} URL to the cover image
|
* @returns {?string} URL to the cover image
|
||||||
*/
|
*/
|
||||||
coverImage({ format, size } = {}) {
|
coverURL({ format, size } = {}) {
|
||||||
if (!this.cover) return null;
|
if (!this.cover) return null;
|
||||||
return Endpoints.CDN(this.client.options.http.cdn).AppIcon(this.id, this.cover, { format, size });
|
return Endpoints.CDN(this.client.options.http.cdn).AppIcon(this.id, this.cover, { format, size });
|
||||||
}
|
}
|
||||||
|
|||||||
24
typings/index.d.ts
vendored
24
typings/index.d.ts
vendored
@@ -32,6 +32,11 @@ declare enum InteractionTypes {
|
|||||||
APPLICATION_COMMAND = 2,
|
APPLICATION_COMMAND = 2,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
declare enum InviteTargetType {
|
||||||
|
STREAM = 1,
|
||||||
|
EMBEDDED_APPLICATION = 2,
|
||||||
|
}
|
||||||
|
|
||||||
declare enum OverwriteTypes {
|
declare enum OverwriteTypes {
|
||||||
role = 0,
|
role = 0,
|
||||||
member = 1,
|
member = 1,
|
||||||
@@ -153,7 +158,7 @@ declare module 'discord.js' {
|
|||||||
public icon: string | null;
|
public icon: string | null;
|
||||||
public id: Snowflake;
|
public id: Snowflake;
|
||||||
public name: string | null;
|
public name: string | null;
|
||||||
public coverImage(options?: ImageURLOptions): string | null;
|
public coverURL(options?: ImageURLOptions): string | null;
|
||||||
public fetchAssets(): Promise<ApplicationAsset[]>;
|
public fetchAssets(): Promise<ApplicationAsset[]>;
|
||||||
public iconURL(options?: ImageURLOptions): string | null;
|
public iconURL(options?: ImageURLOptions): string | null;
|
||||||
public toJSON(): object;
|
public toJSON(): object;
|
||||||
@@ -178,6 +183,8 @@ declare module 'discord.js' {
|
|||||||
private static transformOption(option: ApplicationCommandOptionData, received?: boolean): object;
|
private static transformOption(option: ApplicationCommandOptionData, received?: boolean): object;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ApplicationResolvable = Application | Activity | Snowflake;
|
||||||
|
|
||||||
export class ApplicationFlags extends BitField<ApplicationFlagsString> {
|
export class ApplicationFlags extends BitField<ApplicationFlagsString> {
|
||||||
public static FLAGS: Record<ApplicationFlagsString, number>;
|
public static FLAGS: Record<ApplicationFlagsString, number>;
|
||||||
public static resolve(bit?: BitFieldResolvable<ApplicationFlagsString, number>): number;
|
public static resolve(bit?: BitFieldResolvable<ApplicationFlagsString, number>): number;
|
||||||
@@ -1034,6 +1041,13 @@ declare module 'discord.js' {
|
|||||||
|
|
||||||
export class IntegrationApplication extends Application {
|
export class IntegrationApplication extends Application {
|
||||||
public bot: User | null;
|
public bot: User | null;
|
||||||
|
public termsOfServiceURL: string | null;
|
||||||
|
public privacyPolicyURL: string | null;
|
||||||
|
public rpcOrigins: string[];
|
||||||
|
public summary: string | null;
|
||||||
|
public hook: boolean | null;
|
||||||
|
public cover: string | null;
|
||||||
|
public verifyKey: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Intents extends BitField<IntentsString> {
|
export class Intents extends BitField<IntentsString> {
|
||||||
@@ -1077,8 +1091,9 @@ declare module 'discord.js' {
|
|||||||
public maxUses: number | null;
|
public maxUses: number | null;
|
||||||
public memberCount: number;
|
public memberCount: number;
|
||||||
public presenceCount: number;
|
public presenceCount: number;
|
||||||
|
public targetApplication: IntegrationApplication | null;
|
||||||
public targetUser: User | null;
|
public targetUser: User | null;
|
||||||
public targetUserType: TargetUser | null;
|
public targetType: InviteTargetType | null;
|
||||||
public temporary: boolean | null;
|
public temporary: boolean | null;
|
||||||
public readonly url: string;
|
public readonly url: string;
|
||||||
public uses: number | null;
|
public uses: number | null;
|
||||||
@@ -3093,6 +3108,9 @@ declare module 'discord.js' {
|
|||||||
maxUses?: number;
|
maxUses?: number;
|
||||||
unique?: boolean;
|
unique?: boolean;
|
||||||
reason?: string;
|
reason?: string;
|
||||||
|
targetApplication?: ApplicationResolvable;
|
||||||
|
targetUser?: UserResolvable;
|
||||||
|
targetType?: InviteTargetType;
|
||||||
}
|
}
|
||||||
|
|
||||||
type InviteResolvable = string;
|
type InviteResolvable = string;
|
||||||
@@ -3576,8 +3594,6 @@ declare module 'discord.js' {
|
|||||||
|
|
||||||
type SystemMessageType = Exclude<MessageType, 'DEFAULT' | 'REPLY' | 'APPLICATION_COMMAND'>;
|
type SystemMessageType = Exclude<MessageType, 'DEFAULT' | 'REPLY' | 'APPLICATION_COMMAND'>;
|
||||||
|
|
||||||
type TargetUser = number;
|
|
||||||
|
|
||||||
interface TypingData {
|
interface TypingData {
|
||||||
user: User | PartialUser;
|
user: User | PartialUser;
|
||||||
since: Date;
|
since: Date;
|
||||||
|
|||||||
Reference in New Issue
Block a user