mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-02 00:40:07 +00:00
Merge pull request #978 from discordeno/fix-get-invite-return-type
fix: invite helper types
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import type { CreateChannelInvite } from "../../types/invites/create_channel_invite.ts";
|
||||
import type { Invite } from "../../types/invites/invite.ts";
|
||||
import type { InviteMetadata } from "../../types/invites/invite_metadata.ts";
|
||||
import { Errors } from "../../types/discordeno/errors.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import { requireBotChannelPermissions } from "../../util/permissions.ts";
|
||||
|
||||
/** Creates a new invite for this channel. Requires CREATE_INSTANT_INVITE */
|
||||
export async function createInvite(channelId: bigint, options: CreateChannelInvite) {
|
||||
export async function createInvite(channelId: bigint, options: CreateChannelInvite = {}) {
|
||||
await requireBotChannelPermissions(channelId, ["CREATE_INSTANT_INVITE"]);
|
||||
|
||||
if (options.maxAge && (options.maxAge < 0 || options.maxAge > 604800)) {
|
||||
@@ -16,5 +16,5 @@ export async function createInvite(channelId: bigint, options: CreateChannelInvi
|
||||
throw new Error(Errors.INVITE_MAX_USES_INVALID);
|
||||
}
|
||||
|
||||
return await rest.runMethod<Invite>("post", endpoints.CHANNEL_INVITES(channelId), options);
|
||||
return await rest.runMethod<InviteMetadata>("post", endpoints.CHANNEL_INVITES(channelId), options);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import type { Invite } from "../../types/invites/invite.ts";
|
||||
import type { InviteMetadata } from "../../types/invites/invite_metadata.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import { botHasChannelPermissions, requireBotGuildPermissions } from "../../util/permissions.ts";
|
||||
|
||||
@@ -15,5 +15,5 @@ export async function deleteInvite(channelId: bigint, inviteCode: string) {
|
||||
}
|
||||
}
|
||||
|
||||
return await rest.runMethod<Invite>("delete", endpoints.INVITE(inviteCode));
|
||||
return await rest.runMethod<InviteMetadata>("delete", endpoints.INVITE(inviteCode));
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import type { Invite } from "../../types/invites/invite.ts";
|
||||
import type { InviteMetadata } from "../../types/invites/invite_metadata.ts";
|
||||
import { Collection } from "../../util/collection.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import { requireBotChannelPermissions } from "../../util/permissions.ts";
|
||||
@@ -8,7 +8,7 @@ import { requireBotChannelPermissions } from "../../util/permissions.ts";
|
||||
export async function getChannelInvites(channelId: bigint) {
|
||||
await requireBotChannelPermissions(channelId, ["MANAGE_CHANNELS"]);
|
||||
|
||||
const result = await rest.runMethod<Invite[]>("get", endpoints.CHANNEL_INVITES(channelId));
|
||||
const result = await rest.runMethod<InviteMetadata[]>("get", endpoints.CHANNEL_INVITES(channelId));
|
||||
|
||||
return new Collection(result.map((invite) => [invite.code, invite]));
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import { GetInvite } from "../../types/invites/get_invite.ts";
|
||||
import type { Invite } from "../../types/invites/invite.ts";
|
||||
import type { InviteMetadata } from "../../types/invites/invite_metadata.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import { snakelize } from "../../util/utils.ts";
|
||||
|
||||
/** Returns an invite for the given code or throws an error if the invite doesn't exists. */
|
||||
export async function getInvite(inviteCode: string, options?: GetInvite) {
|
||||
return await rest.runMethod<Invite>("get", endpoints.INVITE(inviteCode), snakelize(options ?? {}));
|
||||
return await rest.runMethod<InviteMetadata>("get", endpoints.INVITE(inviteCode), snakelize(options ?? {}));
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import type { Invite } from "../../types/invites/invite.ts";
|
||||
import type { InviteMetadata } from "../../types/invites/invite_metadata.ts";
|
||||
import { Collection } from "../../util/collection.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
||||
@@ -8,7 +8,7 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
||||
export async function getInvites(guildId: bigint) {
|
||||
await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]);
|
||||
|
||||
const result = await rest.runMethod<Invite[]>("get", endpoints.GUILD_INVITES(guildId));
|
||||
const result = await rest.runMethod<InviteMetadata[]>("get", endpoints.GUILD_INVITES(guildId));
|
||||
|
||||
return new Collection(result.map((invite) => [invite.code, invite]));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user