mirror of
https://github.com/discordeno/discordeno.git
synced 2026-09-17 16:57:22 +00:00
chore: WithReason type cleanup (#2449)
* type WithReason<T> = T & { reason?: string }
* deno fmt (1.25.2)
* WithReason: jsdoc comments for reason
Co-authored-by: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com>
* deno fmt
* types: WithReason type -> WithReason interface
* Fix: Some helpers missing support for reason
Co-authored-by: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com>
This commit is contained in:
co-authored by
Skillz4Killz
parent
b502c14ffb
commit
16f109ad43
@@ -1,8 +1,9 @@
|
||||
import type { Bot } from "../../bot.ts";
|
||||
import { WithReason } from "../../mod.ts";
|
||||
import { Channel } from "../../transformers/channel.ts";
|
||||
import { DiscordChannel } from "../../types/discord.ts";
|
||||
import { OverwriteReadable } from "../../types/discordeno.ts";
|
||||
import { ChannelTypes } from "../../types/shared.ts";
|
||||
import { OverwriteReadable } from "./editChannelPermissionOverrides.ts";
|
||||
|
||||
/**
|
||||
* Creates a channel within a guild.
|
||||
@@ -23,12 +24,7 @@ import { OverwriteReadable } from "./editChannelPermissionOverrides.ts";
|
||||
*
|
||||
* @see {@link https://discord.com/developers/docs/resources/guild#create-guild-channel}
|
||||
*/
|
||||
export async function createChannel(
|
||||
bot: Bot,
|
||||
guildId: bigint,
|
||||
options?: CreateGuildChannel,
|
||||
reason?: string,
|
||||
): Promise<Channel> {
|
||||
export async function createChannel(bot: Bot, guildId: bigint, options?: CreateGuildChannel): Promise<Channel> {
|
||||
// BITRATE IS IN THOUSANDS SO IF USER PROVIDES 32 WE CONVERT TO 32000
|
||||
if (options?.bitrate && options.bitrate < 1000) options.bitrate *= 1000;
|
||||
|
||||
@@ -53,7 +49,7 @@ export async function createChannel(
|
||||
deny: overwrite.deny ? bot.utils.calculateBits(overwrite.deny) : null,
|
||||
})),
|
||||
type: options?.type || ChannelTypes.GuildText,
|
||||
reason,
|
||||
reason: options.reason,
|
||||
default_auto_archive_duration: options?.defaultAutoArchiveDuration,
|
||||
}
|
||||
: {},
|
||||
@@ -62,7 +58,7 @@ export async function createChannel(
|
||||
return bot.transformers.channel(bot, { channel: result, guildId });
|
||||
}
|
||||
|
||||
export interface CreateGuildChannel {
|
||||
export interface CreateGuildChannel extends WithReason {
|
||||
/** Channel name (1-100 characters) */
|
||||
name: string;
|
||||
/** The type of channel */
|
||||
|
||||
@@ -14,10 +14,16 @@ import type { Bot } from "../../bot.ts";
|
||||
*
|
||||
* @see {@link https://discord.com/developers/docs/resources/channel#delete-channel-permission}
|
||||
*/
|
||||
export async function deleteChannelPermissionOverride(bot: Bot, channelId: bigint, overwriteId: bigint): Promise<void> {
|
||||
export async function deleteChannelPermissionOverride(
|
||||
bot: Bot,
|
||||
channelId: bigint,
|
||||
overwriteId: bigint,
|
||||
reason?: string,
|
||||
): Promise<void> {
|
||||
return await bot.rest.runMethod<void>(
|
||||
bot.rest,
|
||||
"DELETE",
|
||||
bot.constants.routes.CHANNEL_OVERWRITE(channelId, overwriteId),
|
||||
reason ? { reason } : undefined,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import type { Bot } from "../../bot.ts";
|
||||
import { WithReason } from "../../mod.ts";
|
||||
import { Channel } from "../../transformers/channel.ts";
|
||||
import { DiscordChannel } from "../../types/discord.ts";
|
||||
import { OverwriteReadable } from "../../types/discordeno.ts";
|
||||
import { ChannelTypes, VideoQualityModes } from "../../types/shared.ts";
|
||||
import { OverwriteReadable } from "./editChannelPermissionOverrides.ts";
|
||||
|
||||
/**
|
||||
* Edits a channel's settings.
|
||||
@@ -34,12 +35,7 @@ import { OverwriteReadable } from "./editChannelPermissionOverrides.ts";
|
||||
* - Otherwise:
|
||||
* - Fires a _Channel Update_ gateway event.
|
||||
*/
|
||||
export async function editChannel(
|
||||
bot: Bot,
|
||||
channelId: bigint,
|
||||
options: ModifyChannel,
|
||||
reason?: string,
|
||||
): Promise<Channel> {
|
||||
export async function editChannel(bot: Bot, channelId: bigint, options: ModifyChannel): Promise<Channel> {
|
||||
if (options.name || options.topic) {
|
||||
const request = editChannelNameTopicQueue.get(channelId);
|
||||
if (!request) {
|
||||
@@ -107,7 +103,7 @@ export async function editChannel(
|
||||
emoji_name: options.defaultReactionEmoji.emojiName,
|
||||
}
|
||||
: undefined,
|
||||
reason,
|
||||
reason: options.reason,
|
||||
},
|
||||
);
|
||||
|
||||
@@ -171,7 +167,7 @@ function processEditChannelQueue(bot: Bot): void {
|
||||
}
|
||||
}
|
||||
|
||||
export interface ModifyChannel {
|
||||
export interface ModifyChannel extends WithReason {
|
||||
/** 1-100 character channel name */
|
||||
name?: string;
|
||||
/** The type of channel; only conversion between text and news is supported and only in guilds with the "NEWS" feature */
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
import type { Bot } from "../../bot.ts";
|
||||
import { OverwriteTypes, PermissionStrings } from "../../types/shared.ts";
|
||||
import { WithReason } from "../../mod.ts";
|
||||
import { OverwriteReadable } from "../../types/discordeno.ts";
|
||||
|
||||
/**
|
||||
* Edits the permission overrides for a user or role in a channel.
|
||||
*
|
||||
* @param bot - The bot instance to use to make the request.
|
||||
* @param channelId - The ID of the channel to edit the permission overrides of.
|
||||
* @param overwrite - The permission override.
|
||||
* @param options - The permission override.
|
||||
*
|
||||
* @remarks
|
||||
* Requires the `MANAGE_ROLES` permission.
|
||||
@@ -20,38 +21,19 @@ import { OverwriteTypes, PermissionStrings } from "../../types/shared.ts";
|
||||
export async function editChannelPermissionOverrides(
|
||||
bot: Bot,
|
||||
channelId: bigint,
|
||||
overwrite: OverwriteReadable,
|
||||
options: EditChannelPermissionOverridesOptions,
|
||||
): Promise<void> {
|
||||
return await bot.rest.runMethod<void>(
|
||||
bot.rest,
|
||||
"PUT",
|
||||
bot.constants.routes.CHANNEL_OVERWRITE(channelId, overwrite.id),
|
||||
bot.constants.routes.CHANNEL_OVERWRITE(channelId, options.id),
|
||||
{
|
||||
allow: overwrite.allow ? bot.utils.calculateBits(overwrite.allow) : "0",
|
||||
deny: overwrite.deny ? bot.utils.calculateBits(overwrite.deny) : "0",
|
||||
type: overwrite.type,
|
||||
allow: options.allow ? bot.utils.calculateBits(options.allow) : "0",
|
||||
deny: options.deny ? bot.utils.calculateBits(options.deny) : "0",
|
||||
type: options.type,
|
||||
reason: options.reason,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
export interface OverwriteReadable {
|
||||
/** Role or user id */
|
||||
id: bigint;
|
||||
/** Either 0 (role) or 1 (member) */
|
||||
type: OverwriteTypes;
|
||||
/** Permission bit set */
|
||||
allow?: PermissionStrings[];
|
||||
/** Permission bit set */
|
||||
deny?: PermissionStrings[];
|
||||
}
|
||||
|
||||
export interface Overwrite {
|
||||
/** Role or user id */
|
||||
id: bigint;
|
||||
/** Either 0 (role) or 1 (member) */
|
||||
type: OverwriteTypes;
|
||||
/** Permission bit set */
|
||||
allow?: bigint;
|
||||
/** Permission bit set */
|
||||
deny?: bigint;
|
||||
}
|
||||
export interface EditChannelPermissionOverridesOptions extends OverwriteReadable, WithReason {}
|
||||
|
||||
@@ -2,7 +2,7 @@ import type { Bot } from "../../../bot.ts";
|
||||
import { Channel } from "../../../transformers/channel.ts";
|
||||
import { Embed } from "../../../transformers/embed.ts";
|
||||
import { DiscordChannel } from "../../../types/discord.ts";
|
||||
import { AllowedMentions, FileContent, MessageComponents } from "../../../types/mod.ts";
|
||||
import { AllowedMentions, FileContent, MessageComponents, WithReason } from "../../../types/mod.ts";
|
||||
|
||||
/**
|
||||
* Creates a new thread in a forum channel, and sends a message within the created thread.
|
||||
@@ -55,18 +55,13 @@ export async function createForumThread(
|
||||
return bot.transformers.channel(bot, { channel: result, guildId: bot.transformers.snowflake(result.guild_id!) });
|
||||
}
|
||||
|
||||
export interface CreateForumPostWithMessage extends CreateForumMessage {
|
||||
export interface CreateForumPostWithMessage extends WithReason {
|
||||
/** 1-100 character thread name */
|
||||
name: string;
|
||||
/** Duration in minutes to automatically archive the thread after recent activity */
|
||||
autoArchiveDuration: 60 | 1440 | 4320 | 10080;
|
||||
/** Amount of seconds a user has to wait before sending another message (0-21600) */
|
||||
rateLimitPerUser?: number | null;
|
||||
/** The reason you are creating the thread */
|
||||
reason?: string;
|
||||
}
|
||||
|
||||
export interface CreateForumMessage {
|
||||
/** The message contents (up to 2000 characters) */
|
||||
content?: string;
|
||||
/** Embedded `rich` content (up to 6000 characters) */
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { Bot } from "../../../bot.ts";
|
||||
import { WithReason } from "../../../mod.ts";
|
||||
import { StageInstance } from "../../../transformers/stageInstance.ts";
|
||||
import { DiscordStageInstance } from "../../../types/discord.ts";
|
||||
|
||||
@@ -25,13 +26,14 @@ export async function createStageInstance(bot: Bot, options: CreateStageInstance
|
||||
channel_id: options.channelId.toString(),
|
||||
topic: options.topic,
|
||||
send_start_notification: options.sendStartNotification,
|
||||
reason: options.reason,
|
||||
},
|
||||
);
|
||||
|
||||
return bot.transformers.stageInstance(bot, result);
|
||||
}
|
||||
|
||||
export interface CreateStageInstance {
|
||||
export interface CreateStageInstance extends WithReason {
|
||||
channelId: bigint;
|
||||
topic: string;
|
||||
/** Notify @everyone that the stage instance has started. Requires the MENTION_EVERYONE permission. */
|
||||
|
||||
@@ -13,6 +13,11 @@ import type { Bot } from "../../../bot.ts";
|
||||
*
|
||||
* @see {@link https://discord.com/developers/docs/resources/stage-instance#delete-stage-instance}
|
||||
*/
|
||||
export async function deleteStageInstance(bot: Bot, channelId: bigint): Promise<void> {
|
||||
return await bot.rest.runMethod<void>(bot.rest, "DELETE", bot.constants.routes.STAGE_INSTANCE(channelId));
|
||||
export async function deleteStageInstance(bot: Bot, channelId: bigint, reason?: string): Promise<void> {
|
||||
return await bot.rest.runMethod<void>(
|
||||
bot.rest,
|
||||
"DELETE",
|
||||
bot.constants.routes.STAGE_INSTANCE(channelId),
|
||||
reason ? { reason } : undefined,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { Bot } from "../../../bot.ts";
|
||||
import { WithReason } from "../../../mod.ts";
|
||||
import { StageInstance } from "../../../transformers/stageInstance.ts";
|
||||
import { DiscordStageInstance } from "../../../types/discord.ts";
|
||||
import { AtLeastOne } from "../../../types/shared.ts";
|
||||
|
||||
/**
|
||||
* Edits a stage instance.
|
||||
@@ -20,7 +20,7 @@ import { AtLeastOne } from "../../../types/shared.ts";
|
||||
export async function editStageInstance(
|
||||
bot: Bot,
|
||||
channelId: bigint,
|
||||
data: AtLeastOne<Pick<DiscordStageInstance, "topic">>,
|
||||
data: EditStageInstanceOptions,
|
||||
): Promise<StageInstance> {
|
||||
const result = await bot.rest.runMethod<DiscordStageInstance>(
|
||||
bot.rest,
|
||||
@@ -33,3 +33,8 @@ export async function editStageInstance(
|
||||
|
||||
return bot.transformers.stageInstance(bot, result);
|
||||
}
|
||||
|
||||
export interface EditStageInstanceOptions extends WithReason {
|
||||
/** The topic of the Stage instance (1-120 characters) */
|
||||
topic: string;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { Bot } from "../../../bot.ts";
|
||||
import { WithReason } from "../../../mod.ts";
|
||||
import { Channel } from "../../../transformers/channel.ts";
|
||||
import { DiscordChannel } from "../../../types/discord.ts";
|
||||
|
||||
@@ -35,19 +36,19 @@ export async function startThreadWithMessage(
|
||||
{
|
||||
name: options.name,
|
||||
auto_archive_duration: options.autoArchiveDuration,
|
||||
rate_limit_per_user: options.rateLimitPerUser,
|
||||
reason: options.reason,
|
||||
},
|
||||
);
|
||||
|
||||
return bot.transformers.channel(bot, { channel: result, guildId: bot.transformers.snowflake(result.guild_id!) });
|
||||
}
|
||||
|
||||
export interface StartThreadWithMessage {
|
||||
export interface StartThreadWithMessage extends WithReason {
|
||||
/** 1-100 character thread name */
|
||||
name: string;
|
||||
/** Duration in minutes to automatically archive the thread after recent activity */
|
||||
autoArchiveDuration: 60 | 1440 | 4320 | 10080;
|
||||
/** Amount of seconds a user has to wait before sending another message (0-21600) */
|
||||
rateLimitPerUser?: number | null;
|
||||
/** The reason you are creating the thread */
|
||||
reason?: string;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { Bot } from "../../../bot.ts";
|
||||
import { WithReason } from "../../../mod.ts";
|
||||
import { Channel } from "../../../transformers/channel.ts";
|
||||
import { DiscordChannel } from "../../../types/discord.ts";
|
||||
import { ChannelTypes } from "../../../types/shared.ts";
|
||||
@@ -30,6 +31,10 @@ export async function startThreadWithoutMessage(
|
||||
{
|
||||
name: options.name,
|
||||
auto_archive_duration: options.autoArchiveDuration,
|
||||
rate_limit_per_user: options.rateLimitPerUser,
|
||||
type: options.type,
|
||||
invitable: options.invitable,
|
||||
reason: options.reason,
|
||||
},
|
||||
);
|
||||
|
||||
@@ -39,15 +44,13 @@ export async function startThreadWithoutMessage(
|
||||
});
|
||||
}
|
||||
|
||||
export interface StartThreadWithoutMessage {
|
||||
export interface StartThreadWithoutMessage extends WithReason {
|
||||
/** 1-100 character thread name */
|
||||
name: string;
|
||||
/** Duration in minutes to automatically archive the thread after recent activity */
|
||||
autoArchiveDuration: 60 | 1440 | 4320 | 10080;
|
||||
/** Amount of seconds a user has to wait before sending another message (0-21600) */
|
||||
rateLimitPerUser?: number | null;
|
||||
/** The reason you are creating the thread */
|
||||
reason?: string;
|
||||
/** the type of thread to create */
|
||||
type: ChannelTypes.AnnouncementThread | ChannelTypes.PublicThread | ChannelTypes.PrivateThread;
|
||||
/** whether non-moderators can add other non-moderators to a thread; only available when creating a private thread */
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { Bot } from "../../bot.ts";
|
||||
import { WithReason } from "../../mod.ts";
|
||||
import { Emoji } from "../../transformers/emoji.ts";
|
||||
import { DiscordEmoji } from "../../types/discord.ts";
|
||||
|
||||
@@ -40,13 +41,11 @@ export async function createEmoji(bot: Bot, guildId: bigint, options: CreateGuil
|
||||
}
|
||||
|
||||
/** https://discord.com/developers/docs/resources/emoji#create-guild-emoji */
|
||||
export interface CreateGuildEmoji {
|
||||
export interface CreateGuildEmoji extends WithReason {
|
||||
/** Name of the emoji */
|
||||
name: string;
|
||||
/** The 128x128 emoji image. Emojis and animated emojis have a maximum file size of 256kb. Attempting to upload an emoji larger than this limit will fail and return 400 Bad Request and an error message, but not a JSON status code. If a URL is provided to the image parameter, Discordeno will automatically convert it to a base64 string internally. */
|
||||
image: string;
|
||||
/** Roles allowed to use this emoji */
|
||||
roles?: bigint[];
|
||||
/** The reason you are creating this emoji */
|
||||
reason?: string;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { Bot } from "../../bot.ts";
|
||||
import { WithReason } from "../../mod.ts";
|
||||
import { Emoji } from "../../transformers/emoji.ts";
|
||||
import { DiscordEmoji } from "../../types/discord.ts";
|
||||
|
||||
@@ -27,6 +28,7 @@ export async function editEmoji(bot: Bot, guildId: bigint, id: bigint, options:
|
||||
name: options.name,
|
||||
// NEED TERNARY TO SUPPORT NULL AS VALID
|
||||
roles: options.roles ? options.roles.map((role) => role.toString()) : options.roles,
|
||||
reason: options.reason,
|
||||
},
|
||||
);
|
||||
|
||||
@@ -34,7 +36,7 @@ export async function editEmoji(bot: Bot, guildId: bigint, id: bigint, options:
|
||||
}
|
||||
|
||||
/** https://discord.com/developers/docs/resources/emoji#modify-guild-emoji */
|
||||
export interface ModifyGuildEmoji {
|
||||
export interface ModifyGuildEmoji extends WithReason {
|
||||
/** Name of the emoji */
|
||||
name?: string;
|
||||
/** Roles allowed to use this emoji */
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Bot } from "../../../bot.ts";
|
||||
import { WithReason } from "../../../mod.ts";
|
||||
import { AutoModerationRule } from "../../../transformers/automodRule.ts";
|
||||
import {
|
||||
AutoModerationActionType,
|
||||
@@ -61,7 +62,7 @@ export async function createAutomodRule(
|
||||
return bot.transformers.automodRule(bot, result);
|
||||
}
|
||||
|
||||
export interface CreateAutoModerationRuleOptions {
|
||||
export interface CreateAutoModerationRuleOptions extends WithReason {
|
||||
/** The name of the rule. */
|
||||
name: string;
|
||||
/** The type of event to trigger the rule on. */
|
||||
@@ -97,6 +98,4 @@ export interface CreateAutoModerationRuleOptions {
|
||||
exemptRoles?: bigint[];
|
||||
/** The channel ids that should not be effected by the rule. */
|
||||
exemptChannels?: bigint[];
|
||||
/** The reason to add to the audit logs. */
|
||||
reason?: string;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Bot } from "../../../bot.ts";
|
||||
import { WithReason } from "../../../mod.ts";
|
||||
import { AutoModerationRule } from "../../../transformers/automodRule.ts";
|
||||
import {
|
||||
AutoModerationActionType,
|
||||
@@ -61,7 +62,7 @@ export async function editAutomodRule(
|
||||
return bot.transformers.automodRule(bot, result);
|
||||
}
|
||||
|
||||
export interface EditAutoModerationRuleOptions {
|
||||
export interface EditAutoModerationRuleOptions extends WithReason {
|
||||
/** The name of the rule. */
|
||||
name: string;
|
||||
/** The type of event to trigger the rule on. */
|
||||
@@ -96,6 +97,4 @@ export interface EditAutoModerationRuleOptions {
|
||||
exemptRoles?: bigint[];
|
||||
/** The channel ids that should not be effected by the rule. */
|
||||
exemptChannels?: bigint[];
|
||||
/** The reason to add to the audit logs. */
|
||||
reason?: string;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Bot } from "../../../bot.ts";
|
||||
import { WithReason } from "../../../mod.ts";
|
||||
import { ScheduledEvent } from "../../../transformers/scheduledEvent.ts";
|
||||
import { DiscordScheduledEvent } from "../../../types/discord.ts";
|
||||
import { ScheduledEventEntityType, ScheduledEventPrivacyLevel } from "../../../types/shared.ts";
|
||||
@@ -67,7 +68,7 @@ export async function createScheduledEvent(
|
||||
return bot.transformers.scheduledEvent(bot, result);
|
||||
}
|
||||
|
||||
export interface CreateScheduledEvent {
|
||||
export interface CreateScheduledEvent extends WithReason {
|
||||
/** the channel id of the scheduled event. */
|
||||
channelId?: bigint;
|
||||
/** location of the event. Required for events with `entityType: ScheduledEventEntityType.External` */
|
||||
@@ -84,5 +85,4 @@ export interface CreateScheduledEvent {
|
||||
privacyLevel?: ScheduledEventPrivacyLevel;
|
||||
/** the type of hosting entity associated with a scheduled event */
|
||||
entityType: ScheduledEventEntityType;
|
||||
reason?: string;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Bot } from "../../../bot.ts";
|
||||
import { WithReason } from "../../../mod.ts";
|
||||
import { ScheduledEvent } from "../../../transformers/scheduledEvent.ts";
|
||||
import { DiscordScheduledEvent } from "../../../types/discord.ts";
|
||||
import { ScheduledEventEntityType, ScheduledEventPrivacyLevel, ScheduledEventStatus } from "../../../types/shared.ts";
|
||||
@@ -62,7 +63,7 @@ export async function editScheduledEvent(
|
||||
return bot.transformers.scheduledEvent(bot, result);
|
||||
}
|
||||
|
||||
export interface EditScheduledEvent {
|
||||
export interface EditScheduledEvent extends WithReason {
|
||||
/** the channel id of the scheduled event. null if switching to external event. */
|
||||
channelId: bigint | null;
|
||||
/** location of the event */
|
||||
@@ -81,5 +82,4 @@ export interface EditScheduledEvent {
|
||||
entityType: ScheduledEventEntityType;
|
||||
/** the status of the scheduled event */
|
||||
status: ScheduledEventStatus;
|
||||
reason?: string;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { Bot } from "../../../bot.ts";
|
||||
import { WithReason } from "../../../mod.ts";
|
||||
import { DiscordInvite } from "../../../types/discord.ts";
|
||||
import { TargetTypes } from "../../../types/shared.ts";
|
||||
import { BaseInvite } from "./getInvite.ts";
|
||||
@@ -57,7 +58,7 @@ export async function createInvite(
|
||||
};
|
||||
}
|
||||
|
||||
export interface CreateChannelInvite {
|
||||
export interface CreateChannelInvite extends WithReason {
|
||||
/** 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 */
|
||||
|
||||
@@ -13,6 +13,11 @@ import type { Bot } from "../../../bot.ts";
|
||||
*
|
||||
* @see {@link https://discord.com/developers/docs/resources/channel#delete-channel-invite}
|
||||
*/
|
||||
export async function deleteInvite(bot: Bot, inviteCode: string): Promise<void> {
|
||||
return await bot.rest.runMethod<void>(bot.rest, "DELETE", bot.constants.routes.INVITE(inviteCode));
|
||||
export async function deleteInvite(bot: Bot, inviteCode: string, reason?: string): Promise<void> {
|
||||
return await bot.rest.runMethod<void>(
|
||||
bot.rest,
|
||||
"DELETE",
|
||||
bot.constants.routes.INVITE(inviteCode),
|
||||
reason ? { reason } : undefined,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { Bot } from "../../bot.ts";
|
||||
import { WithReason } from "../../mod.ts";
|
||||
|
||||
/**
|
||||
* Bans a user from a guild.
|
||||
@@ -15,7 +16,12 @@ import type { Bot } from "../../bot.ts";
|
||||
*
|
||||
* @see {@link https://discord.com/developers/docs/resources/guild#create-guild-ban}
|
||||
*/
|
||||
export async function banMember(bot: Bot, guildId: bigint, userId: bigint, options?: CreateGuildBan): Promise<void> {
|
||||
export async function banMember(
|
||||
bot: Bot,
|
||||
guildId: bigint,
|
||||
userId: bigint,
|
||||
options?: CreateGuildBan,
|
||||
): Promise<void> {
|
||||
return await bot.rest.runMethod<void>(
|
||||
bot.rest,
|
||||
"PUT",
|
||||
@@ -28,9 +34,7 @@ export async function banMember(bot: Bot, guildId: bigint, userId: bigint, optio
|
||||
}
|
||||
|
||||
/** https://discord.com/developers/docs/resources/guild#create-guild-ban */
|
||||
export interface CreateGuildBan {
|
||||
export interface CreateGuildBan extends WithReason {
|
||||
/** Number of seconds to delete messages for, between 0 and 604800 (7 days) */
|
||||
deleteMessageSeconds?: number;
|
||||
/** Reason for the ban */
|
||||
reason?: string;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { Bot } from "../../bot.ts";
|
||||
import { DiscordMember, Member } from "../../mod.ts";
|
||||
import { DiscordMember, Member, WithReason } from "../../mod.ts";
|
||||
|
||||
/**
|
||||
* Edits the nickname of the bot user.
|
||||
@@ -17,14 +17,21 @@ import { DiscordMember, Member } from "../../mod.ts";
|
||||
export async function editBotMember(
|
||||
bot: Bot,
|
||||
guildId: bigint,
|
||||
options: { nick: string | null; reason?: string },
|
||||
options: EditBotMemberOptions,
|
||||
): Promise<Member> {
|
||||
const result = await bot.rest.runMethod<DiscordMember>(
|
||||
bot.rest,
|
||||
"PATCH",
|
||||
bot.constants.routes.USER_NICK(guildId),
|
||||
options,
|
||||
{
|
||||
nick: options.nick,
|
||||
reason: options.reason,
|
||||
},
|
||||
);
|
||||
|
||||
return bot.transformers.member(bot, result, guildId, bot.id);
|
||||
}
|
||||
|
||||
export interface EditBotMemberOptions extends WithReason {
|
||||
nick?: string | null;
|
||||
}
|
||||
|
||||
@@ -18,6 +18,11 @@ import type { Bot } from "../../bot.ts";
|
||||
*
|
||||
* @see {@link https://discord.com/developers/docs/resources/channel#pin-message}
|
||||
*/
|
||||
export async function pinMessage(bot: Bot, channelId: bigint, messageId: bigint): Promise<void> {
|
||||
return await bot.rest.runMethod<void>(bot.rest, "PUT", bot.constants.routes.CHANNEL_PIN(channelId, messageId));
|
||||
export async function pinMessage(bot: Bot, channelId: bigint, messageId: bigint, reason?: string): Promise<void> {
|
||||
return await bot.rest.runMethod<void>(
|
||||
bot.rest,
|
||||
"PUT",
|
||||
bot.constants.routes.CHANNEL_PIN(channelId, messageId),
|
||||
reason ? { reason } : undefined,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -16,10 +16,11 @@ import type { Bot } from "../../bot.ts";
|
||||
*
|
||||
* @see {@link https://discord.com/developers/docs/resources/channel#unpin-message}
|
||||
*/
|
||||
export async function unpinMessage(bot: Bot, channelId: bigint, messageId: bigint): Promise<void> {
|
||||
export async function unpinMessage(bot: Bot, channelId: bigint, messageId: bigint, reason?: string): Promise<void> {
|
||||
return await bot.rest.runMethod<void>(
|
||||
bot.rest,
|
||||
"DELETE",
|
||||
bot.constants.routes.CHANNEL_PIN(channelId, messageId),
|
||||
reason ? { reason } : undefined,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { Bot } from "../../bot.ts";
|
||||
import { WithReason } from "../../mod.ts";
|
||||
import { Webhook } from "../../transformers/webhook.ts";
|
||||
import { DiscordWebhook } from "../../types/discord.ts";
|
||||
|
||||
@@ -34,11 +35,9 @@ export async function createWebhook(bot: Bot, channelId: bigint, options: Create
|
||||
return bot.transformers.webhook(bot, result);
|
||||
}
|
||||
|
||||
export interface CreateWebhook {
|
||||
export interface CreateWebhook extends WithReason {
|
||||
/** Name of the webhook (1-80 characters) */
|
||||
name: string;
|
||||
/** Image url for the default webhook avatar */
|
||||
avatar?: string | null;
|
||||
/** The reason you are creating this webhook */
|
||||
reason?: string;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { Bot } from "../../bot.ts";
|
||||
import { WithReason } from "../../mod.ts";
|
||||
import { Webhook } from "../../transformers/webhook.ts";
|
||||
import { DiscordWebhook } from "../../types/discord.ts";
|
||||
|
||||
@@ -32,13 +33,11 @@ export async function editWebhook(bot: Bot, webhookId: bigint, options: ModifyWe
|
||||
return bot.transformers.webhook(bot, result);
|
||||
}
|
||||
|
||||
export interface ModifyWebhook {
|
||||
export interface ModifyWebhook extends WithReason {
|
||||
/** The default name of the webhook */
|
||||
name?: string;
|
||||
/** Image for the default webhook avatar */
|
||||
avatar?: bigint | null;
|
||||
/** The new channel id this webhook should be moved to */
|
||||
channelId?: bigint;
|
||||
/** The reason you are modifying this webhook */
|
||||
reason?: string;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
InteractionResponseTypes,
|
||||
Localization,
|
||||
MessageComponentTypes,
|
||||
OverwriteTypes,
|
||||
PermissionStrings,
|
||||
TextStyles,
|
||||
} from "./shared.ts";
|
||||
@@ -212,3 +213,19 @@ export interface InteractionCallbackData {
|
||||
/** Autocomplete choices (max of 25 choices) */
|
||||
choices?: ApplicationCommandOptionChoice[];
|
||||
}
|
||||
|
||||
export interface WithReason {
|
||||
/** The reason which should be added in the audit logs for doing this action. */
|
||||
reason?: string;
|
||||
}
|
||||
|
||||
export interface OverwriteReadable {
|
||||
/** Role or user id */
|
||||
id: bigint;
|
||||
/** Either 0 (role) or 1 (member) */
|
||||
type: OverwriteTypes;
|
||||
/** Permission bit set */
|
||||
allow?: PermissionStrings[];
|
||||
/** Permission bit set */
|
||||
deny?: PermissionStrings[];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user