diff --git a/src/api/handlers/channel.ts b/src/api/handlers/channel.ts index e22b410ca..5e1b772d1 100644 --- a/src/api/handlers/channel.ts +++ b/src/api/handlers/channel.ts @@ -321,6 +321,20 @@ export async function createInvite( throw new Error(Errors.MISSING_CREATE_INSTANT_INVITE); } + if (options.max_age && (options.max_age > 604800 || options.max_age < 0)) { + console.log( + `The max age for invite created in ${channelID} was not between 0-604800. Using default values instead.`, + ); + options.max_age = undefined; + } + + if (options.max_uses && (options.max_uses > 100 || options.max_uses < 0)) { + console.log( + `The max uses for invite created in ${channelID} was not between 0-100. Using default values instead.`, + ); + options.max_uses = undefined; + } + const result = await RequestManager.post( endpoints.CHANNEL_INVITES(channelID), options, diff --git a/src/types/channel.ts b/src/types/channel.ts index ad3202a95..3743c2ebc 100644 --- a/src/types/channel.ts +++ b/src/types/channel.ts @@ -154,11 +154,12 @@ export interface GetMessagesAround extends GetMessages { around: string; } +// TODO: v11 change to camelcase export interface CreateInviteOptions { - /** Duration of invite in seconds before expiry, or 0 for never. Defaults to 86400 (24 hours) */ - "max_age": number; - /** Max number of uses or 0 for unlimited. Default 0 */ - "max_uses": number; + /** Duration of invite in seconds before expiry, or 0 for never. Between 0-604800 (7 days). Defaults to 86400 (24 hours). */ + "max_age"?: number; + /** Max number of uses or 0 for unlimited. Between 0-100. Default 0 */ + "max_uses"?: number; /** Whether this invite only grants temporary membership. */ temporary: boolean; /** If true, don't try to reuse a similar invite (useful for creating many unique one time use invites.) */