mirror of
https://github.com/discordeno/discordeno.git
synced 2026-05-30 15:30:07 +00:00
* fix: check new types idea * fix: type errors * fix: new style * fix: more cleanup * fix: more cleanup * fix: cleanup audit logs * fix: cleanup stickers * fix: cleanup integrations * fix: more cleanup * fix: organize into 1 place * fix: few errors * fix: some broken import fixes * fix: quite a lot of fixes across the board * fix: more fixes for broken imports * fix: more fixes for broken imports * fix: handler imports * fix: all remaining import errors * fix: more errors needing fixes * fix: clearing up transformers * fix: few moer types * fix: more cleanup of extra types * fix: fmt * fix: cleanup discordeno file * Nuke Base Types (#2102) * fix: cleanup snake stuff * convert camelCase to snake_case (#2103) * fix: add camelize * fix: finalize remaining errors * fix: imports in test Co-authored-by: LTS20050703 <87189679+lts20050703@users.noreply.github.com>
54 lines
2.5 KiB
TypeScript
54 lines
2.5 KiB
TypeScript
import type { Bot } from "../../bot.ts";
|
|
import { DiscordInvite } from "../../types/discord.ts";
|
|
import { InviteTargetTypes } from "../../types/shared.ts";
|
|
|
|
/** Creates a new invite for this channel. Requires CREATE_INSTANT_INVITE */
|
|
export async function createInvite(bot: Bot, channelId: bigint, options: CreateChannelInvite = {}) {
|
|
const result = await bot.rest.runMethod<DiscordInvite>(
|
|
bot.rest,
|
|
"post",
|
|
bot.constants.endpoints.CHANNEL_INVITES(channelId),
|
|
{
|
|
max_age: options.maxAge,
|
|
max_uses: options.maxUses,
|
|
temporary: options.temporary,
|
|
unique: options.unique,
|
|
target_type: options.targetType,
|
|
target_user_id: options.targetUserId,
|
|
target_application_id: options.targetUserId,
|
|
},
|
|
);
|
|
|
|
return {
|
|
code: result.code,
|
|
guildId: result.guild?.id ? bot.transformers.snowflake(result.guild.id) : undefined,
|
|
channelId: result.channel?.id ? bot.transformers.snowflake(result.channel.id) : undefined,
|
|
inviter: result.inviter ? bot.transformers.user(bot, result.inviter) : undefined,
|
|
targetType: result.target_type,
|
|
targetUser: result.target_user ? bot.transformers.user(bot, result.target_user) : undefined,
|
|
targetApplicationId: result.target_application?.id
|
|
? bot.transformers.snowflake(result.target_application.id)
|
|
: undefined,
|
|
approximatePresenceCount: result.approximate_presence_count,
|
|
approximateMemberCount: result.approximate_member_count,
|
|
expiresAt: result.expires_at ? Date.parse(result.expires_at) : undefined,
|
|
};
|
|
}
|
|
|
|
export interface CreateChannelInvite {
|
|
/** Duration of invite in seconds before expiry, or 0 for never. Between 0 and 604800 (7 days). Default: 86400 (24 hours) */
|
|
maxAge?: number;
|
|
/** Max number of users or 0 for unlimited. Between 0 and 100. Default: 0 */
|
|
maxUses?: number;
|
|
/** Whether this invite only grants temporary membership. Default: false */
|
|
temporary?: boolean;
|
|
/** If true, don't try to reuse simmilar invite (useful for creating many unique one time use invites). Default: false */
|
|
unique?: boolean;
|
|
/** The type of target for this voice channel invite */
|
|
targetType?: InviteTargetTypes;
|
|
/** The id of the user whose stream to display for this invite, required if `target_type` is 1, the user must be streaming in the channel */
|
|
targetUserId?: string;
|
|
/** The id of the embedded application to open for this invite, required if `target_type` is 2, the application must have the `EMBEDDED` flag */
|
|
targetApplicationId?: string;
|
|
}
|