Merge branch 'main' into application-command-permissions

This commit is contained in:
ITOH
2021-04-24 23:36:02 +02:00
154 changed files with 476 additions and 675 deletions
+3 -3
View File
@@ -2,7 +2,7 @@ import { eventHandlers } from "../../bot.ts";
import { cacheHandlers } from "../../cache.ts";
import { rest } from "../../rest/rest.ts";
import { structures } from "../../structures/mod.ts";
import { DiscordChannel } from "../../types/channels/channel.ts";
import { Channel } from "../../types/channels/channel.ts";
import { DiscordChannelTypes } from "../../types/channels/channel_types.ts";
import {
CreateGuildChannel,
@@ -38,7 +38,7 @@ export async function createChannel(
// BITRATES ARE IN THOUSANDS SO IF USER PROVIDES 32 WE CONVERT TO 32000
if (options?.bitrate && options.bitrate < 1000) options.bitrate *= 1000;
const result = (await rest.runMethod(
const result = await rest.runMethod<Channel>(
"post",
endpoints.GUILD_CHANNELS(guildId),
{
@@ -51,7 +51,7 @@ export async function createChannel(
type: options?.type || DiscordChannelTypes.GUILD_TEXT,
reason,
},
)) as DiscordChannel;
);
const discordenoChannel = await structures.createDiscordenoChannel(result);
await cacheHandlers.set("channels", discordenoChannel.id, discordenoChannel);
+1 -3
View File
@@ -23,11 +23,9 @@ export async function deleteChannel(
throw new Error(Errors.UPDATES_CHANNEL_CANNOT_BE_DELETED);
}
const result = await rest.runMethod(
return await rest.runMethod<undefined>(
"delete",
endpoints.CHANNEL_BASE(channelId),
{ reason },
);
return result;
}
@@ -10,10 +10,8 @@ export async function deleteChannelOverwrite(
): Promise<undefined> {
await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]);
const result = await rest.runMethod(
return await rest.runMethod<undefined>(
"delete",
endpoints.CHANNEL_OVERWRITE(channelId, overwriteId),
);
return result;
}
+2 -3
View File
@@ -1,6 +1,7 @@
import { eventHandlers } from "../../bot.ts";
import { rest } from "../../rest/rest.ts";
import { ModifyChannel } from "../../types/channels/modify_channel.ts";
import { Channel } from "../../types/mod.ts";
import { endpoints } from "../../util/constants.ts";
import {
calculateBits,
@@ -58,7 +59,7 @@ export async function editChannel(
}),
};
const result = await rest.runMethod(
return await rest.runMethod<Channel>(
"patch",
endpoints.CHANNEL_BASE(channelId),
{
@@ -66,8 +67,6 @@ export async function editChannel(
reason,
},
);
return result;
}
interface EditChannelRequest {
@@ -15,7 +15,7 @@ export async function editChannelOverwrite(
): Promise<undefined> {
await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]);
const result = await rest.runMethod(
return await rest.runMethod<undefined>(
"put",
endpoints.CHANNEL_OVERWRITE(channelId, overwriteId),
{
@@ -24,6 +24,4 @@ export async function editChannelOverwrite(
type: options.type,
},
);
return result;
}
+8 -5
View File
@@ -1,5 +1,5 @@
import { rest } from "../../rest/rest.ts";
import { DiscordFollowedChannel } from "../../types/channels/followed_channel.ts";
import { FollowedChannel } from "../../types/channels/followed_channel.ts";
import { endpoints } from "../../util/constants.ts";
import { requireBotChannelPermissions } from "../../util/permissions.ts";
@@ -10,10 +10,13 @@ export async function followChannel(
) {
await requireBotChannelPermissions(targetChannelId, ["MANAGE_WEBHOOKS"]);
const data =
(await rest.runMethod("post", endpoints.CHANNEL_FOLLOW(sourceChannelId), {
const data = await rest.runMethod<FollowedChannel>(
"post",
endpoints.CHANNEL_FOLLOW(sourceChannelId),
{
webhook_channel_id: targetChannelId,
})) as DiscordFollowedChannel;
},
);
return data.webhook_id;
return data.webhookId;
}
+4 -4
View File
@@ -1,7 +1,7 @@
import { cacheHandlers } from "../../cache.ts";
import { rest } from "../../rest/rest.ts";
import { structures } from "../../structures/mod.ts";
import { DiscordChannel } from "../../types/channels/channel.ts";
import { Channel } from "../../types/channels/channel.ts";
import { endpoints } from "../../util/constants.ts";
/** Fetches a single channel object from the api.
@@ -9,14 +9,14 @@ import { endpoints } from "../../util/constants.ts";
* ⚠️ **If you need this, you are probably doing something wrong. This is not intended for use. Your channels will be cached in your guild.**
*/
export async function getChannel(channelId: string, addToCache = true) {
const result = (await rest.runMethod(
const result = await rest.runMethod<Channel>(
"get",
endpoints.CHANNEL_BASE(channelId),
)) as DiscordChannel;
);
const discordenoChannel = await structures.createDiscordenoChannel(
result,
result.guild_id,
result.guildId,
);
if (addToCache) {
await cacheHandlers.set(
+4 -8
View File
@@ -1,23 +1,19 @@
import { rest } from "../../rest/rest.ts";
import { DiscordWebhook, Webhook } from "../../types/webhooks/webhook.ts";
import { Webhook } from "../../types/webhooks/webhook.ts";
import { Collection } from "../../util/collection.ts";
import { endpoints } from "../../util/constants.ts";
import { requireBotChannelPermissions } from "../../util/permissions.ts";
import { snakeKeysToCamelCase } from "../../util/utils.ts";
/** Gets the webhooks for this channel. Requires MANAGE_WEBHOOKS */
export async function getChannelWebhooks(channelId: string) {
await requireBotChannelPermissions(channelId, ["MANAGE_WEBHOOKS"]);
const result = (await rest.runMethod(
const result = await rest.runMethod<Webhook[]>(
"get",
endpoints.CHANNEL_WEBHOOKS(channelId),
)) as DiscordWebhook[];
);
return new Collection(
result.map((webhook) => [
webhook.id,
snakeKeysToCamelCase<Webhook>(webhook),
]),
result.map((webhook) => [webhook.id, webhook]),
);
}
+3 -3
View File
@@ -1,7 +1,7 @@
import { cacheHandlers } from "../../cache.ts";
import { rest } from "../../rest/rest.ts";
import { structures } from "../../structures/mod.ts";
import { DiscordChannel } from "../../types/channels/channel.ts";
import { Channel } from "../../types/channels/channel.ts";
import { Collection } from "../../util/collection.ts";
import { endpoints } from "../../util/constants.ts";
@@ -10,10 +10,10 @@ import { endpoints } from "../../util/constants.ts";
* ⚠️ **If you need this, you are probably doing something wrong. This is not intended for use. Your channels will be cached in your guild.**
*/
export async function getChannels(guildId: string, addToCache = true) {
const result = (await rest.runMethod(
const result = await rest.runMethod<Channel[]>(
"get",
endpoints.GUILD_CHANNELS(guildId),
)) as DiscordChannel[];
);
return new Collection(
(
+3 -3
View File
@@ -1,14 +1,14 @@
import { rest } from "../../rest/rest.ts";
import { structures } from "../../structures/mod.ts";
import { DiscordMessage } from "../../types/messages/message.ts";
import { Message } from "../../types/messages/message.ts";
import { endpoints } from "../../util/constants.ts";
/** Get pinned messages in this channel. */
export async function getPins(channelId: string) {
const result = (await rest.runMethod(
const result = await rest.runMethod<Message[]>(
"get",
endpoints.CHANNEL_PINS(channelId),
)) as DiscordMessage[];
);
return Promise.all(
result.map((res) => structures.createDiscordenoMessage(res)),
+2 -4
View File
@@ -10,7 +10,7 @@ import { botHasChannelPermissions } from "../../util/permissions.ts";
* However, if a bot is responding to a command and expects the computation to take a few seconds,
* this endpoint may be called to let the user know that the bot is processing their message.
*/
export async function startTyping(channelId: string): Promise<undefined> {
export async function startTyping(channelId: string) {
const channel = await cacheHandlers.get("channels", channelId);
// If the channel is cached, we can do extra checks/safety
if (channel) {
@@ -35,10 +35,8 @@ export async function startTyping(channelId: string): Promise<undefined> {
}
}
const result = await rest.runMethod(
return await rest.runMethod<undefined>(
"post",
endpoints.CHANNEL_TYPING(channelId),
);
return result;
}
+2 -4
View File
@@ -6,16 +6,14 @@ import { endpoints } from "../../util/constants.ts";
export async function swapChannels(
guildId: string,
channelPositions: ModifyGuildChannelPositions[],
): Promise<undefined> {
) {
if (channelPositions.length < 2) {
throw "You must provide at least two channels to be swapped.";
}
const result = await rest.runMethod(
return await rest.runMethod<undefined>(
"patch",
endpoints.GUILD_CHANNELS(guildId),
channelPositions,
);
return result;
}
+2 -3
View File
@@ -1,6 +1,7 @@
import { applicationId } from "../../bot.ts";
import { rest } from "../../rest/rest.ts";
import { CreateGlobalApplicationCommand } from "../../types/interactions/create_global_application_command.ts";
import { ApplicationCommand } from "../../types/mod.ts";
import { endpoints } from "../../util/constants.ts";
import {
camelKeysToSnakeCase,
@@ -24,13 +25,11 @@ export async function createSlashCommand(
) {
validateSlashCommands([options], true);
const result = await rest.runMethod(
return await rest.runMethod<ApplicationCommand>(
"post",
guildId
? endpoints.COMMANDS_GUILD(applicationId, guildId)
: endpoints.COMMANDS(applicationId),
camelKeysToSnakeCase(options),
);
return result;
}
+2 -4
View File
@@ -6,13 +6,11 @@ import { endpoints } from "../../util/constants.ts";
export async function deleteSlashCommand(
id: string,
guildId?: string,
): Promise<undefined> {
const result = await rest.runMethod(
) {
return await rest.runMethod<undefined>(
"delete",
guildId
? endpoints.COMMANDS_GUILD_ID(applicationId, guildId, id)
: endpoints.COMMANDS_ID(applicationId, id),
);
return result;
}
@@ -6,8 +6,8 @@ import { endpoints } from "../../util/constants.ts";
export async function deleteSlashResponse(
token: string,
messageId?: string,
): Promise<undefined> {
const result = await rest.runMethod(
) {
return await rest.runMethod<undefined>(
"delete",
messageId
? endpoints.INTERACTION_ID_TOKEN_MESSAGE_ID(
@@ -17,6 +17,4 @@ export async function deleteSlashResponse(
)
: endpoints.INTERACTION_ORIGINAL_ID_TOKEN(applicationId, token),
);
return result;
}
+2 -3
View File
@@ -3,7 +3,6 @@ import { rest } from "../../rest/rest.ts";
import { structures } from "../../structures/mod.ts";
import { DiscordenoEditWebhookMessage } from "../../types/discordeno/edit_webhook_message.ts";
import { DiscordAllowedMentionsTypes } from "../../types/messages/allowed_mentions_types.ts";
import { DiscordMessage } from "../../types/messages/message.ts";
import { Errors } from "../../types/misc/errors.ts";
import { endpoints } from "../../util/constants.ts";
@@ -69,10 +68,10 @@ export async function editSlashResponse(
);
// If the original message was edited, this will not return a message
if (!options.messageId) return result;
if (!options.messageId) return result as undefined;
const message = await structures.createDiscordenoMessage(
result as DiscordMessage,
result,
);
return message;
}
+1 -3
View File
@@ -5,12 +5,10 @@ import { endpoints } from "../../util/constants.ts";
/** Fetchs the global command for the given Id. If a guildId is provided, the guild command will be fetched. */
export async function getSlashCommand(commandId: string, guildId?: string) {
const result = await rest.runMethod(
return await rest.runMethod<ApplicationCommand>(
"get",
guildId
? endpoints.COMMANDS_GUILD_ID(applicationId, guildId, commandId)
: endpoints.COMMANDS_ID(applicationId, commandId),
);
return result as ApplicationCommand;
}
+2 -2
View File
@@ -6,12 +6,12 @@ import { endpoints } from "../../util/constants.ts";
/** Fetch all of the global commands for your application. */
export async function getSlashCommands(guildId?: string) {
const result = (await rest.runMethod(
const result = await rest.runMethod<ApplicationCommand[]>(
"get",
guildId
? endpoints.COMMANDS_GUILD(applicationId, guildId)
: endpoints.COMMANDS(applicationId),
)) as ApplicationCommand[];
);
return new Collection(result.map((command) => [command.name, command]));
}
@@ -17,9 +17,13 @@ export async function sendInteractionResponse(
) {
// If its already been executed, we need to send a followup response
if (cache.executedSlashCommands.has(token)) {
return rest.runMethod("post", endpoints.WEBHOOK(applicationId, token), {
...options,
});
return await rest.runMethod(
"post",
endpoints.WEBHOOK(applicationId, token),
{
...options,
},
);
}
// Expire in 15 minutes
@@ -45,11 +49,9 @@ export async function sendInteractionResponse(
options.data = { ...options.data, allowedMentions: { parse: [] } };
}
const result = await rest.runMethod(
return await rest.runMethod(
"post",
endpoints.INTERACTION_ID_TOKEN(id, token),
options,
);
return result;
}
+2 -3
View File
@@ -1,6 +1,7 @@
import { applicationId } from "../../bot.ts";
import { rest } from "../../rest/rest.ts";
import { EditGlobalApplicationCommand } from "../../types/interactions/edit_global_application_command.ts";
import { ApplicationCommand } from "../../types/mod.ts";
import { endpoints } from "../../util/constants.ts";
import { validateSlashCommands } from "../../util/utils.ts";
@@ -14,13 +15,11 @@ export async function upsertSlashCommand(
) {
validateSlashCommands([options]);
const result = await rest.runMethod(
return await rest.runMethod<ApplicationCommand>(
"patch",
guildId
? endpoints.COMMANDS_GUILD_ID(applicationId, guildId, commandId)
: endpoints.COMMANDS_ID(applicationId, commandId),
options,
);
return result;
}
@@ -1,6 +1,7 @@
import { applicationId } from "../../bot.ts";
import { rest } from "../../rest/rest.ts";
import { EditGlobalApplicationCommand } from "../../types/interactions/edit_global_application_command.ts";
import { ApplicationCommand } from "../../types/mod.ts";
import { endpoints } from "../../util/constants.ts";
import { validateSlashCommands } from "../../util/utils.ts";
@@ -15,13 +16,11 @@ export async function upsertSlashCommands(
) {
validateSlashCommands(options);
const result = await rest.runMethod(
return await rest.runMethod<ApplicationCommand[]>(
"put",
guildId
? endpoints.COMMANDS_GUILD(applicationId, guildId)
: endpoints.COMMANDS(applicationId),
options,
);
return result;
}
@@ -1,11 +1,9 @@
import { rest } from "../../rest/rest.ts";
import {
AddGuildDiscoverySubcategory,
DiscordAddGuildDiscoverySubcategory,
} from "../../types/discovery/add_guild_discovery_subcategory.ts";
import { endpoints } from "../../util/constants.ts";
import { requireBotGuildPermissions } from "../../util/permissions.ts";
import { snakeKeysToCamelCase } from "../../util/utils.ts";
/** Add a discovery subcategory to the guild. Requires the `MANAGE_GUILD` permission. */
export async function addDiscoverySubcategory(
@@ -14,10 +12,8 @@ export async function addDiscoverySubcategory(
) {
await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]);
const result = await rest.runMethod<DiscordAddGuildDiscoverySubcategory>(
return await rest.runMethod<AddGuildDiscoverySubcategory>(
"post",
endpoints.DISCOVERY_SUBCATEGORY(guildId, categoryId),
);
return snakeKeysToCamelCase<AddGuildDiscoverySubcategory>(result);
}
+3 -11
View File
@@ -1,15 +1,9 @@
import { rest } from "../../rest/rest.ts";
import {
DiscordDiscoveryMetadata,
DiscoveryMetadata,
} from "../../types/discovery/discovery_metadata.ts";
import { DiscoveryMetadata } from "../../types/discovery/discovery_metadata.ts";
import { ModifyGuildDiscoveryMetadata } from "../../types/discovery/modify_guild_discovery_metadata.ts";
import { endpoints } from "../../util/constants.ts";
import { requireBotGuildPermissions } from "../../util/permissions.ts";
import {
camelKeysToSnakeCase,
snakeKeysToCamelCase,
} from "../../util/utils.ts";
import { camelKeysToSnakeCase } from "../../util/utils.ts";
/** Modify the discovery metadata for the guild. Requires the MANAGE_GUILD permission. Returns the updated discovery metadata object on success. */
export async function editDiscovery(
@@ -18,11 +12,9 @@ export async function editDiscovery(
) {
await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]);
const result = await rest.runMethod<DiscordDiscoveryMetadata>(
return await rest.runMethod<DiscoveryMetadata>(
"patch",
endpoints.DISCOVERY_MODIFY(guildId),
camelKeysToSnakeCase(data),
);
return snakeKeysToCamelCase<DiscoveryMetadata>(result);
}
@@ -1,25 +1,18 @@
import { rest } from "../../rest/rest.ts";
import {
DiscordDiscoveryCategory,
DiscoveryCategory,
} from "../../types/discovery/discovery_category.ts";
import { DiscoveryCategory } from "../../types/discovery/discovery_category.ts";
import { Collection } from "../../util/collection.ts";
import { endpoints } from "../../util/constants.ts";
import { snakeKeysToCamelCase } from "../../util/utils.ts";
/** Returns an array of discovery category objects that can be used when editing guilds */
export async function getDiscoveryCategories() {
const result = await rest.runMethod<DiscordDiscoveryCategory[]>(
const result = await rest.runMethod<DiscoveryCategory[]>(
"get",
endpoints.DISCOVERY_CATEGORIES,
);
return new Collection<number, DiscoveryCategory>(
result.map(
(category) => [
category.id,
snakeKeysToCamelCase<DiscoveryCategory>(category),
],
(category) => [category.id, category],
),
);
}
+2 -4
View File
@@ -3,7 +3,7 @@ import { CreateGuildEmoji } from "../../types/emojis/create_guild_emoji.ts";
import { Emoji } from "../../types/emojis/emoji.ts";
import { endpoints } from "../../util/constants.ts";
import { requireBotGuildPermissions } from "../../util/permissions.ts";
import { snakeKeysToCamelCase, urlToBase64 } from "../../util/utils.ts";
import { urlToBase64 } from "../../util/utils.ts";
/** Create an emoji in the server. 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. */
export async function createEmoji(
@@ -18,11 +18,9 @@ export async function createEmoji(
image = await urlToBase64(image);
}
const result = await rest.runMethod("post", endpoints.GUILD_EMOJIS(guildId), {
return await rest.runMethod<Emoji>("post", endpoints.GUILD_EMOJIS(guildId), {
...options,
name,
image,
});
return snakeKeysToCamelCase<Emoji>(result);
}
+2 -4
View File
@@ -7,14 +7,12 @@ export async function deleteEmoji(
guildId: string,
id: string,
reason?: string,
): Promise<undefined> {
) {
await requireBotGuildPermissions(guildId, ["MANAGE_EMOJIS"]);
const result = await rest.runMethod(
return await rest.runMethod<undefined>(
"delete",
endpoints.GUILD_EMOJI(guildId, id),
{ reason },
);
return result;
}
+2 -3
View File
@@ -1,5 +1,6 @@
import { rest } from "../../rest/rest.ts";
import { ModifyGuildEmoji } from "../../types/emojis/modify_guild_emoji.ts";
import { Emoji } from "../../types/mod.ts";
import { endpoints } from "../../util/constants.ts";
import { requireBotGuildPermissions } from "../../util/permissions.ts";
@@ -11,7 +12,7 @@ export async function editEmoji(
) {
await requireBotGuildPermissions(guildId, ["MANAGE_EMOJIS"]);
const result = await rest.runMethod(
return await rest.runMethod<Emoji>(
"patch",
endpoints.GUILD_EMOJI(guildId, id),
{
@@ -19,6 +20,4 @@ export async function editEmoji(
roles: options.roles,
},
);
return result;
}
+3 -3
View File
@@ -14,16 +14,16 @@ export async function getEmoji(
emojiId: string,
addToCache = true,
) {
const result = (await rest.runMethod(
const result = await rest.runMethod<Emoji>(
"get",
endpoints.GUILD_EMOJI(guildId, emojiId),
)) as Emoji;
);
if (addToCache) {
const guild = await cacheHandlers.get("guilds", guildId);
if (!guild) throw new Error(Errors.GUILD_NOT_FOUND);
guild.emojis.set(emojiId, result);
cacheHandlers.set(
await cacheHandlers.set(
"guilds",
guildId,
guild,
+5 -3
View File
@@ -12,8 +12,10 @@ import { endpoints } from "../../util/constants.ts";
* ⚠️ **If you need this, you are probably doing something wrong. Always use cache.guilds.get()?.emojis
*/
export async function getEmojis(guildId: string, addToCache = true) {
const result =
(await rest.runMethod("get", endpoints.GUILD_EMOJIS(guildId))) as Emoji[];
const result = await rest.runMethod<Emoji[]>(
"get",
endpoints.GUILD_EMOJIS(guildId),
);
if (addToCache) {
const guild = await cacheHandlers.get("guilds", guildId);
@@ -27,7 +29,7 @@ export async function getEmojis(guildId: string, addToCache = true) {
guild.emojis.set(emoji.id!, emoji);
});
cacheHandlers.set("guilds", guildId, guild);
await cacheHandlers.set("guilds", guildId, guild);
}
return new Collection(result.map((e) => [e.id!, e]));
+3 -3
View File
@@ -3,17 +3,17 @@ import { cacheHandlers } from "../../cache.ts";
import { rest } from "../../rest/rest.ts";
import { structures } from "../../structures/mod.ts";
import { CreateGuild } from "../../types/guilds/create_guild.ts";
import { DiscordGuild } from "../../types/guilds/guild.ts";
import { Guild } from "../../types/guilds/guild.ts";
import { endpoints } from "../../util/constants.ts";
import { getMember } from "../members/get_member.ts";
/** Create a new guild. Returns a guild object on success. Fires a Guild Create Gateway event. This endpoint can be used only by bots in less than 10 guilds. */
export async function createGuild(options: CreateGuild) {
const result = (await rest.runMethod(
const result = await rest.runMethod<Guild>(
"post",
endpoints.GUILDS,
options,
)) as DiscordGuild;
);
const guild = await structures.createDiscordenoGuild(result, 0);
// MANUALLY CACHE THE GUILD
+5 -4
View File
@@ -3,8 +3,9 @@ import { endpoints } from "../../util/constants.ts";
/** Delete a guild permanently. User must be owner. Returns 204 No Content on success. Fires a Guild Delete Gateway event.
*/
export async function deleteServer(guildId: string): Promise<undefined> {
const result = await rest.runMethod("delete", endpoints.GUILDS_BASE(guildId));
return result;
export async function deleteServer(guildId: string) {
return await rest.runMethod<undefined>(
"delete",
endpoints.GUILDS_BASE(guildId),
);
}
+4 -3
View File
@@ -1,6 +1,6 @@
import { rest } from "../../rest/rest.ts";
import { structures } from "../../structures/mod.ts";
import { DiscordGuild } from "../../types/guilds/guild.ts";
import { Guild } from "../../types/guilds/guild.ts";
import { ModifyGuild } from "../../types/guilds/modify_guild.ts";
import { endpoints } from "../../util/constants.ts";
import { requireBotGuildPermissions } from "../../util/permissions.ts";
@@ -22,11 +22,12 @@ export async function editGuild(guildId: string, options: ModifyGuild) {
options.splash = await urlToBase64(options.splash);
}
const result = await rest.runMethod(
const result = await rest.runMethod<Guild>(
"patch",
endpoints.GUILDS_BASE(guildId),
options,
) as DiscordGuild;
);
// TODO: use ws.botGatewayData to calculate the shard ID
return structures.createDiscordenoGuild(result, -1);
}
+2 -7
View File
@@ -2,20 +2,15 @@ import { rest } from "../../rest/rest.ts";
import { ModifyGuildWelcomeScreen } from "../../types/guilds/modify_guild_welcome_screen.ts";
import { WelcomeScreen } from "../../types/mod.ts";
import { endpoints } from "../../util/constants.ts";
import {
camelKeysToSnakeCase,
snakeKeysToCamelCase,
} from "../../util/utils.ts";
import { camelKeysToSnakeCase } from "../../util/utils.ts";
export async function editWelcomeScreen(
guildId: string,
options: ModifyGuildWelcomeScreen,
) {
const result = await rest.runMethod(
return await rest.runMethod<WelcomeScreen>(
"patch",
endpoints.GUILD_WELCOME_SCREEN(guildId),
camelKeysToSnakeCase(options),
);
return snakeKeysToCamelCase<WelcomeScreen>(result);
}
+1 -4
View File
@@ -2,7 +2,6 @@ import { rest } from "../../rest/rest.ts";
import { GuildWidget } from "../../types/guilds/guild_widget.ts";
import { endpoints } from "../../util/constants.ts";
import { requireBotGuildPermissions } from "../../util/permissions.ts";
import { snakeKeysToCamelCase } from "../../util/utils.ts";
/** Modify a guild widget object for the guild. Requires the MANAGE_GUILD permission. */
export async function editWidget(
@@ -12,7 +11,7 @@ export async function editWidget(
) {
await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]);
const result = await rest.runMethod(
return await rest.runMethod<GuildWidget>(
"patch",
endpoints.GUILD_WIDGET(guildId),
{
@@ -20,6 +19,4 @@ export async function editWidget(
channel_id: channelId,
},
);
return snakeKeysToCamelCase<GuildWidget>(result);
}
+2 -7
View File
@@ -3,10 +3,7 @@ import { AuditLog } from "../../types/audit_log/audit_log.ts";
import { GetGuildAuditLog } from "../../types/audit_log/get_guild_audit_log.ts";
import { endpoints } from "../../util/constants.ts";
import { requireBotGuildPermissions } from "../../util/permissions.ts";
import {
camelKeysToSnakeCase,
snakeKeysToCamelCase,
} from "../../util/utils.ts";
import { camelKeysToSnakeCase } from "../../util/utils.ts";
/** Returns the audit logs for the guild. Requires VIEW AUDIT LOGS permission */
export async function getAuditLogs(
@@ -15,7 +12,7 @@ export async function getAuditLogs(
) {
await requireBotGuildPermissions(guildId, ["VIEW_AUDIT_LOG"]);
const result = await rest.runMethod(
return await rest.runMethod<AuditLog>(
"get",
endpoints.GUILD_AUDIT_LOGS(guildId),
camelKeysToSnakeCase({
@@ -25,6 +22,4 @@ export async function getAuditLogs(
: 50,
}),
);
return snakeKeysToCamelCase<AuditLog>(result);
}
@@ -4,7 +4,5 @@ import { endpoints } from "../../util/constants.ts";
/** Returns an array of voice regions that can be used when creating servers. */
export async function getAvailableVoiceRegions() {
const result = await rest.runMethod("get", endpoints.VOICE_REGIONS);
return result as VoiceRegion;
return await rest.runMethod<VoiceRegion>("get", endpoints.VOICE_REGIONS);
}
+1 -4
View File
@@ -2,16 +2,13 @@ import { rest } from "../../rest/rest.ts";
import { Ban } from "../../types/guilds/ban.ts";
import { endpoints } from "../../util/constants.ts";
import { requireBotGuildPermissions } from "../../util/permissions.ts";
import { snakeKeysToCamelCase } from "../../util/utils.ts";
/** Returns a ban object for the given user or a 404 not found if the ban cannot be found. Requires the BAN_MEMBERS permission. */
export async function getBan(guildId: string, memberId: string) {
await requireBotGuildPermissions(guildId, ["BAN_MEMBERS"]);
const result = await rest.runMethod(
return await rest.runMethod<Ban>(
"get",
endpoints.GUILD_BAN(guildId, memberId),
);
return snakeKeysToCamelCase<Ban>(result);
}
+4 -5
View File
@@ -1,20 +1,19 @@
import { rest } from "../../rest/rest.ts";
import { Ban, DiscordBan } from "../../types/guilds/ban.ts";
import { Ban } from "../../types/guilds/ban.ts";
import { Collection } from "../../util/collection.ts";
import { endpoints } from "../../util/constants.ts";
import { requireBotGuildPermissions } from "../../util/permissions.ts";
import { snakeKeysToCamelCase } from "../../util/utils.ts";
/** Returns a list of ban objects for the users banned from this guild. Requires the BAN_MEMBERS permission. */
export async function getBans(guildId: string) {
await requireBotGuildPermissions(guildId, ["BAN_MEMBERS"]);
const results = (await rest.runMethod(
const results = await rest.runMethod<Ban[]>(
"get",
endpoints.GUILD_BANS(guildId),
)) as DiscordBan[];
);
return new Collection<string, Ban>(
results.map((res) => [res.user.id, snakeKeysToCamelCase<Ban>(res)]),
results.map((res) => [res.user.id, res]),
);
}
+27 -6
View File
@@ -1,7 +1,9 @@
import { cacheHandlers } from "../../cache.ts";
import { rest } from "../../rest/rest.ts";
import { structures } from "../../structures/mod.ts";
import { Guild } from "../../types/guilds/guild.ts";
import { endpoints } from "../../util/constants.ts";
import { snakeKeysToCamelCase } from "../../util/utils.ts";
import { ws } from "../../ws/ws.ts";
/**
* ⚠️ **If you need this, you are probably doing something wrong. Always use cache.guilds.get()
@@ -10,10 +12,29 @@ import { snakeKeysToCamelCase } from "../../util/utils.ts";
* This function fetches a guild's data. This is not the same data as a GUILD_CREATE.
* So it does not cache the guild, you must do it manually.
* */
export async function getGuild(guildId: string, counts = true) {
const result = await rest.runMethod("get", endpoints.GUILDS_BASE(guildId), {
with_counts: counts,
});
export async function getGuild(
guildId: string,
options: { counts?: boolean; addToCache?: boolean } = {
counts: true,
addToCache: true,
},
) {
const result = await rest.runMethod<Guild>(
"get",
endpoints.GUILDS_BASE(guildId),
{
with_counts: options.counts,
},
);
return snakeKeysToCamelCase<Guild>(result);
const structure = await structures.createDiscordenoGuild(
result,
Number((BigInt(guildId) >> 22n) % BigInt(ws.botGatewayData.shards)),
);
if (options.addToCache) {
await cacheHandlers.set("guilds", guildId, structure);
}
return structure;
}
+4 -4
View File
@@ -1,11 +1,11 @@
import { rest } from "../../rest/rest.ts";
import { GuildPreview } from "../../types/guilds/guild_preview.ts";
import { endpoints } from "../../util/constants.ts";
import { snakeKeysToCamelCase } from "../../util/utils.ts";
/** Returns the guild preview object for the given id. If the bot is not in the guild, then the guild must be Discoverable. */
export async function getGuildPreview(guildId: string) {
const result = await rest.runMethod("get", endpoints.GUILD_PREVIEW(guildId));
return snakeKeysToCamelCase<GuildPreview>(result);
return await rest.runMethod<GuildPreview>(
"get",
endpoints.GUILD_PREVIEW(guildId),
);
}
+5 -8
View File
@@ -1,18 +1,15 @@
import { rest } from "../../rest/rest.ts";
import { InviteMetadata } from "../../types/invites/invite_metadata.ts";
import { endpoints } from "../../util/constants.ts";
import { snakeKeysToCamelCase } from "../../util/utils.ts";
/** Returns the code and uses of the vanity url for this server if it is enabled else `code` will be null. Requires the `MANAGE_GUILD` permission. */
export async function getVanityURL(guildId: string) {
const result = await rest.runMethod(
"get",
endpoints.GUILD_VANITY_URL(guildId),
);
return snakeKeysToCamelCase<
return await rest.runMethod<
(Partial<InviteMetadata> & Pick<InviteMetadata, "uses" | "code">) | {
code: null;
}
>(result);
>(
"get",
endpoints.GUILD_VANITY_URL(guildId),
);
}
+4 -10
View File
@@ -1,22 +1,16 @@
import { rest } from "../../rest/rest.ts";
import {
DiscordVoiceRegion,
VoiceRegion,
} from "../../types/voice/voice_region.ts";
import { VoiceRegion } from "../../types/voice/voice_region.ts";
import { Collection } from "../../util/collection.ts";
import { endpoints } from "../../util/constants.ts";
import { snakeKeysToCamelCase } from "../../util/utils.ts";
/** Returns a list of voice region objects for the guild. Unlike the similar /voice route, this returns VIP servers when the guild is VIP-enabled. */
export async function getVoiceRegions(guildId: string) {
const result = await rest.runMethod(
const result = await rest.runMethod<VoiceRegion[]>(
"get",
endpoints.GUILD_REGIONS(guildId),
) as DiscordVoiceRegion[];
const convertedRegions = snakeKeysToCamelCase<VoiceRegion[]>(result);
);
return new Collection<string, VoiceRegion>(
convertedRegions.map((region) => [region.id, region]),
result.map((region) => [region.id, region]),
);
}
+1 -4
View File
@@ -1,13 +1,10 @@
import { rest } from "../../rest/rest.ts";
import { WelcomeScreen } from "../../types/mod.ts";
import { endpoints } from "../../util/constants.ts";
import { snakeKeysToCamelCase } from "../../util/utils.ts";
export async function getWelcomeScreen(guildId: string) {
const result = await rest.runMethod(
return await rest.runMethod<WelcomeScreen>(
"get",
endpoints.GUILD_WELCOME_SCREEN(guildId),
);
return snakeKeysToCamelCase<WelcomeScreen>(result);
}
+2 -1
View File
@@ -11,5 +11,6 @@ export async function getWidget(guildId: string, options?: { force: boolean }) {
if (!guild?.widgetEnabled) throw new Error(Errors.GUILD_WIDGET_NOT_ENABLED);
}
return rest.runMethod("get", `${endpoints.GUILD_WIDGET(guildId)}.json`);
// TODO: add return type
return await rest.runMethod("get", `${endpoints.GUILD_WIDGET(guildId)}.json`);
}
+4 -3
View File
@@ -7,7 +7,8 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts";
export async function getWidgetSettings(guildId: string) {
await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]);
const result = await rest.runMethod("get", endpoints.GUILD_WIDGET(guildId));
return result as GuildWidget;
return await rest.runMethod<GuildWidget>(
"get",
endpoints.GUILD_WIDGET(guildId),
);
}
+5 -4
View File
@@ -2,8 +2,9 @@ import { rest } from "../../rest/rest.ts";
import { endpoints } from "../../util/constants.ts";
/** Leave a guild */
export async function leaveGuild(guildId: string): Promise<undefined> {
const result = await rest.runMethod("delete", endpoints.GUILD_LEAVE(guildId));
return result;
export async function leaveGuild(guildId: string) {
return await rest.runMethod<undefined>(
"delete",
endpoints.GUILD_LEAVE(guildId),
);
}
@@ -6,10 +6,8 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts";
export async function deleteIntegration(guildId: string, id: string) {
await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]);
const result = await rest.runMethod(
return await rest.runMethod<undefined>(
"delete",
endpoints.GUILD_INTEGRATION(guildId, id),
);
return result;
}
+2 -3
View File
@@ -1,4 +1,5 @@
import { rest } from "../../rest/rest.ts";
import { Integration } from "../../types/mod.ts";
import { endpoints } from "../../util/constants.ts";
import { requireBotGuildPermissions } from "../../util/permissions.ts";
@@ -6,10 +7,8 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts";
export async function getIntegrations(guildId: string) {
await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]);
const result = await rest.runMethod(
return await rest.runMethod<Integration>(
"get",
endpoints.GUILD_INTEGRATIONS(guildId),
);
return result;
}
+2 -3
View File
@@ -1,5 +1,6 @@
import { rest } from "../../rest/rest.ts";
import { CreateChannelInvite } from "../../types/invites/create_channel_invite.ts";
import { Invite } from "../../types/mod.ts";
import { endpoints } from "../../util/constants.ts";
import { requireBotChannelPermissions } from "../../util/permissions.ts";
@@ -12,11 +13,9 @@ export async function createInvite(
// TODO: add proper options validation
const result = await rest.runMethod(
return await rest.runMethod<Invite>(
"post",
endpoints.CHANNEL_INVITES(channelId),
options,
);
return result;
}
+2 -5
View File
@@ -1,13 +1,12 @@
import { cacheHandlers } from "../../cache.ts";
import { rest } from "../../rest/rest.ts";
import { DiscordInvite, Invite } from "../../types/invites/invite.ts";
import { Invite } from "../../types/invites/invite.ts";
import { Errors } from "../../types/misc/errors.ts";
import { endpoints } from "../../util/constants.ts";
import {
botHasChannelPermissions,
requireBotGuildPermissions,
} from "../../util/permissions.ts";
import { snakeKeysToCamelCase } from "../../util/utils.ts";
/** Deletes an invite for the given code. Requires `MANAGE_CHANNELS` or `MANAGE_GUILD` permission */
export async function deleteInvite(channelId: string, inviteCode: string) {
@@ -23,10 +22,8 @@ export async function deleteInvite(channelId: string, inviteCode: string) {
await requireBotGuildPermissions(channel!.guildId, ["MANAGE_GUILD"]);
}
const result: DiscordInvite = await rest.runMethod(
return await rest.runMethod<Invite>(
"delete",
endpoints.INVITE(inviteCode),
);
return snakeKeysToCamelCase<Invite>(result);
}
+4 -5
View File
@@ -1,20 +1,19 @@
import { rest } from "../../rest/rest.ts";
import { DiscordInvite, Invite } from "../../types/invites/invite.ts";
import { Invite } from "../../types/invites/invite.ts";
import { Collection } from "../../util/collection.ts";
import { endpoints } from "../../util/constants.ts";
import { requireBotChannelPermissions } from "../../util/permissions.ts";
import { snakeKeysToCamelCase } from "../../util/utils.ts";
/** Gets the invites for this channel. Requires MANAGE_CHANNEL */
export async function getChannelInvites(channelId: string) {
await requireBotChannelPermissions(channelId, ["MANAGE_CHANNELS"]);
const result = (await rest.runMethod(
const result = await rest.runMethod<Invite[]>(
"get",
endpoints.CHANNEL_INVITES(channelId),
)) as DiscordInvite[];
);
return new Collection(
result.map((invite) => [invite.code, snakeKeysToCamelCase<Invite>(invite)]),
result.map((invite) => [invite.code, invite]),
);
}
+2 -5
View File
@@ -1,14 +1,11 @@
import { rest } from "../../rest/rest.ts";
import { DiscordInvite, Invite } from "../../types/invites/invite.ts";
import { Invite } from "../../types/invites/invite.ts";
import { endpoints } from "../../util/constants.ts";
import { snakeKeysToCamelCase } 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) {
const result: DiscordInvite = await rest.runMethod(
return await rest.runMethod<Invite>(
"get",
endpoints.INVITE(inviteCode),
);
return snakeKeysToCamelCase<Invite>(result);
}
+4 -5
View File
@@ -1,20 +1,19 @@
import { rest } from "../../rest/rest.ts";
import { DiscordInvite, Invite } from "../../types/invites/invite.ts";
import { Invite } from "../../types/invites/invite.ts";
import { Collection } from "../../util/collection.ts";
import { endpoints } from "../../util/constants.ts";
import { requireBotGuildPermissions } from "../../util/permissions.ts";
import { snakeKeysToCamelCase } from "../../util/utils.ts";
/** Get all the invites for this guild. Requires MANAGE_GUILD permission */
export async function getInvites(guildId: string) {
await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]);
const result = (await rest.runMethod(
const result = await rest.runMethod<Invite[]>(
"get",
endpoints.GUILD_INVITES(guildId),
)) as DiscordInvite[];
);
return new Collection(
result.map((invite) => [invite.code, snakeKeysToCamelCase<Invite>(invite)]),
result.map((invite) => [invite.code, invite]),
);
}
+2 -4
View File
@@ -1,5 +1,5 @@
import { CreateGuildBan } from "../../types/guilds/create_guild_ban.ts";
import { rest } from "../../rest/rest.ts";
import { CreateGuildBan } from "../../types/guilds/create_guild_ban.ts";
import { endpoints } from "../../util/constants.ts";
import { requireBotGuildPermissions } from "../../util/permissions.ts";
import { camelKeysToSnakeCase } from "../../util/utils.ts";
@@ -12,13 +12,11 @@ export async function ban(
) {
await requireBotGuildPermissions(guildId, ["BAN_MEMBERS"]);
const result = await rest.runMethod(
return await rest.runMethod<undefined>(
"put",
endpoints.GUILD_BAN(guildId, id),
camelKeysToSnakeCase(options),
);
return result;
}
// aliases
+7 -3
View File
@@ -9,9 +9,13 @@ export async function editBotNickname(
) {
await requireBotGuildPermissions(guildId, ["CHANGE_NICKNAME"]);
const response = await rest.runMethod("patch", endpoints.USER_NICK(guildId), {
nick: nickname,
}) as { nick: string };
const response = await rest.runMethod<{ nick: string }>(
"patch",
endpoints.USER_NICK(guildId),
{
nick: nickname,
},
);
return response.nick;
}
+3 -3
View File
@@ -1,5 +1,6 @@
import { rest } from "../../rest/rest.ts";
import { Errors } from "../../types/misc/errors.ts";
import { User } from "../../types/mod.ts";
import { endpoints } from "../../util/constants.ts";
import { urlToBase64 } from "../../util/utils.ts";
@@ -26,10 +27,9 @@ export async function editBotProfile(username?: string, botAvatarURL?: string) {
}
const avatar = botAvatarURL ? await urlToBase64(botAvatarURL) : undefined;
const result = await rest.runMethod("patch", endpoints.USER_BOT, {
return await rest.runMethod<User>("patch", endpoints.USER_BOT, {
username: username?.trim(),
avatar,
});
return result;
}
+6 -8
View File
@@ -1,7 +1,7 @@
import { cacheHandlers } from "../../cache.ts";
import { rest } from "../../rest/rest.ts";
import { structures } from "../../structures/mod.ts";
import { DiscordGuildMember } from "../../types/guilds/guild_member.ts";
import { GuildMemberWithUser } from "../../types/guilds/guild_member.ts";
import { Errors } from "../../types/misc/errors.ts";
import { ModifyGuildMember } from "../../types/mod.ts";
import { PermissionStrings } from "../../types/permissions/permission_strings.ts";
@@ -10,10 +10,7 @@ import {
requireBotChannelPermissions,
requireBotGuildPermissions,
} from "../../util/permissions.ts";
import {
camelKeysToSnakeCase,
snakeKeysToCamelCase,
} from "../../util/utils.ts";
import { camelKeysToSnakeCase } from "../../util/utils.ts";
/** Edit the member */
export async function editMember(
@@ -72,13 +69,14 @@ export async function editMember(
await requireBotGuildPermissions(guildId, [...requiredPerms]);
const result = await rest.runMethod(
const result = await rest.runMethod<GuildMemberWithUser>(
"patch",
endpoints.GUILD_MEMBER(guildId, memberId),
camelKeysToSnakeCase(options),
) as DiscordGuildMember;
);
const member = await structures.createDiscordenoMember(
snakeKeysToCamelCase(result),
result,
guildId,
);
+2 -2
View File
@@ -1,7 +1,7 @@
import { cacheHandlers } from "../../cache.ts";
import { rest } from "../../rest/rest.ts";
import { structures } from "../../structures/mod.ts";
import { DiscordGuildMemberWithUser } from "../../types/guilds/guild_member.ts";
import { GuildMemberWithUser } from "../../types/guilds/guild_member.ts";
import { endpoints } from "../../util/constants.ts";
/** Returns a guild member object for the specified user.
@@ -16,7 +16,7 @@ export async function getMember(
const guild = await cacheHandlers.get("guilds", guildId);
if (!guild && !options?.force) return;
const data: DiscordGuildMemberWithUser = (await rest.runMethod(
const data = (await rest.runMethod<GuildMemberWithUser>(
"get",
endpoints.GUILD_MEMBER(guildId, id),
));
+4 -7
View File
@@ -4,10 +4,7 @@ import { rest } from "../../rest/rest.ts";
import { DiscordenoMember } from "../../structures/member.ts";
import { structures } from "../../structures/mod.ts";
import { DiscordGatewayIntents } from "../../types/gateway/gateway_intents.ts";
import {
DiscordGuildMember,
DiscordGuildMemberWithUser,
} from "../../types/guilds/guild_member.ts";
import { GuildMemberWithUser } from "../../types/guilds/guild_member.ts";
import { ListGuildMembers } from "../../types/guilds/list_guild_members.ts";
import { Errors } from "../../types/misc/errors.ts";
import { Collection } from "../../util/collection.ts";
@@ -49,7 +46,7 @@ export async function getMembers(guildId: string, options?: ListGuildMembers) {
);
}
const result: DiscordGuildMember[] = (await rest.runMethod(
const result = (await rest.runMethod<GuildMemberWithUser[]>(
"get",
`${endpoints.GUILD_MEMBERS(guildId)}?limit=${
membersLeft > 1000 ? 1000 : membersLeft
@@ -59,7 +56,7 @@ export async function getMembers(guildId: string, options?: ListGuildMembers) {
const discordenoMembers = await Promise.all(
result.map(async (member) => {
const discordenoMember = await structures.createDiscordenoMember(
member as DiscordGuildMemberWithUser,
member,
guildId,
);
@@ -71,7 +68,7 @@ export async function getMembers(guildId: string, options?: ListGuildMembers) {
return discordenoMember;
}),
) as DiscordenoMember[];
);
if (!discordenoMembers.length) break;
+1 -3
View File
@@ -20,13 +20,11 @@ export async function kick(guildId: string, memberId: string, reason?: string) {
await requireBotGuildPermissions(guildId, ["KICK_MEMBERS"]);
const result = await rest.runMethod(
return await rest.runMethod<undefined>(
"delete",
endpoints.GUILD_MEMBER(guildId, memberId),
{ reason },
);
return result;
}
// aliases
+2 -2
View File
@@ -19,11 +19,11 @@ export async function pruneMembers(
await requireBotGuildPermissions(guildId, ["KICK_MEMBERS"]);
const result = await rest.runMethod(
const result = await rest.runMethod<{ pruned: number }>(
"post",
endpoints.GUILD_PRUNE(guildId),
camelKeysToSnakeCase(options),
);
return result;
return result.pruned;
}
+2 -2
View File
@@ -2,7 +2,7 @@ import { cacheHandlers } from "../../cache.ts";
import { rest } from "../../rest/rest.ts";
import { DiscordenoMember } from "../../structures/member.ts";
import { structures } from "../../structures/mod.ts";
import { DiscordGuildMemberWithUser } from "../../types/guilds/guild_member.ts";
import { GuildMemberWithUser } from "../../types/guilds/guild_member.ts";
import { SearchGuildMembers } from "../../types/members/search_guild_members.ts";
import { Errors } from "../../types/misc/errors.ts";
import { Collection } from "../../util/collection.ts";
@@ -24,7 +24,7 @@ export async function searchMembers(
}
}
const result = await rest.runMethod<DiscordGuildMemberWithUser[]>(
const result = await rest.runMethod<GuildMemberWithUser[]>(
"get",
endpoints.GUILD_MEMBERS_SEARCH(guildId),
{
+10 -6
View File
@@ -1,7 +1,7 @@
import { cacheHandlers } from "../../cache.ts";
import { rest } from "../../rest/rest.ts";
import { structures } from "../../structures/mod.ts";
import { DiscordChannel } from "../../types/channels/channel.ts";
import { Channel } from "../../types/channels/channel.ts";
import { CreateMessage } from "../../types/messages/create_message.ts";
import { endpoints } from "../../util/constants.ts";
import { sendMessage } from "../messages/send_message.ts";
@@ -14,11 +14,15 @@ export async function sendDirectMessage(
let dmChannel = await cacheHandlers.get("channels", memberId);
if (!dmChannel) {
// If not available in cache create a new one.
const dmChannelData = await rest.runMethod("post", endpoints.USER_DM, {
recipient_id: memberId,
});
const dmChannelData = await rest.runMethod<Channel>(
"post",
endpoints.USER_DM,
{
recipient_id: memberId,
},
);
const discordenoChannel = await structures.createDiscordenoChannel(
dmChannelData as DiscordChannel,
dmChannelData,
);
// Recreate the channel and add it undert he users id
await cacheHandlers.set("channels", memberId, discordenoChannel);
@@ -26,5 +30,5 @@ export async function sendDirectMessage(
}
// If it does exist try sending a message to this user
return sendMessage(dmChannel.id, content);
return await sendMessage(dmChannel.id, content);
}
+1 -3
View File
@@ -6,12 +6,10 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts";
export async function unban(guildId: string, id: string) {
await requireBotGuildPermissions(guildId, ["BAN_MEMBERS"]);
const result = await rest.runMethod(
return await rest.runMethod<undefined>(
"delete",
endpoints.GUILD_BAN(guildId, id),
);
return result;
}
// aliases
+1 -3
View File
@@ -19,10 +19,8 @@ export async function addReaction(
reaction = reaction.substring(3, reaction.length - 1);
}
const result = await rest.runMethod(
return await rest.runMethod<undefined>(
"put",
endpoints.CHANNEL_MESSAGE_REACTION_ME(channelId, messageId, reaction),
);
return result;
}
+1 -3
View File
@@ -20,11 +20,9 @@ export async function deleteMessage(
if (delayMilliseconds) await delay(delayMilliseconds);
const result = await rest.runMethod(
return await rest.runMethod<undefined>(
"delete",
endpoints.CHANNEL_MESSAGE(channelId, messageId),
{ reason },
);
return result;
}
+1 -3
View File
@@ -21,7 +21,7 @@ export async function deleteMessages(
);
}
const result = await rest.runMethod(
return await rest.runMethod<undefined>(
"post",
endpoints.CHANNEL_BULK_DELETE(channelId),
{
@@ -29,6 +29,4 @@ export async function deleteMessages(
reason,
},
);
return result;
}
+3 -3
View File
@@ -3,7 +3,7 @@ import { rest } from "../../rest/rest.ts";
import { DiscordenoMessage } from "../../structures/message.ts";
import { structures } from "../../structures/mod.ts";
import { EditMessage } from "../../types/messages/edit_message.ts";
import { DiscordMessage } from "../../types/messages/message.ts";
import { Message } from "../../types/messages/message.ts";
import { Errors } from "../../types/misc/errors.ts";
import { PermissionStrings } from "../../types/permissions/permission_strings.ts";
import { endpoints } from "../../util/constants.ts";
@@ -28,11 +28,11 @@ export async function editMessage(
throw new Error(Errors.MESSAGE_MAX_LENGTH);
}
const result: DiscordMessage = await rest.runMethod(
const result = await rest.runMethod<Message>(
"patch",
endpoints.CHANNEL_MESSAGE(message.channelId, message.id),
content,
);
return structures.createDiscordenoMessage(result);
return await structures.createDiscordenoMessage(result);
}
+4 -4
View File
@@ -1,7 +1,7 @@
import { cacheHandlers } from "../../cache.ts";
import { rest } from "../../rest/rest.ts";
import { structures } from "../../structures/mod.ts";
import { DiscordMessage } from "../../types/messages/message.ts";
import { Message } from "../../types/messages/message.ts";
import { endpoints } from "../../util/constants.ts";
import { requireBotChannelPermissions } from "../../util/permissions.ts";
@@ -14,10 +14,10 @@ export async function getMessage(channelId: string, id: string) {
]);
}
const result = (await rest.runMethod(
const result = await rest.runMethod<Message>(
"get",
endpoints.CHANNEL_MESSAGE(channelId, id),
)) as DiscordMessage;
);
return structures.createDiscordenoMessage(result);
return await structures.createDiscordenoMessage(result);
}
+4 -4
View File
@@ -6,7 +6,7 @@ import {
GetMessagesBefore,
GetMessagesLimit,
} from "../../types/messages/get_messages.ts";
import { DiscordMessage } from "../../types/messages/message.ts";
import { Message } from "../../types/messages/message.ts";
import { endpoints } from "../../util/constants.ts";
import { requireBotChannelPermissions } from "../../util/permissions.ts";
@@ -26,13 +26,13 @@ export async function getMessages(
if (options?.limit && options.limit > 100) return;
const result = (await rest.runMethod(
const result = await rest.runMethod<Message[]>(
"get",
endpoints.CHANNEL_MESSAGES(channelId),
options,
)) as DiscordMessage[];
);
return Promise.all(
return await Promise.all(
result.map((res) => structures.createDiscordenoMessage(res)),
);
}
+4 -4
View File
@@ -1,8 +1,8 @@
import { rest } from "../../rest/rest.ts";
import { DiscordUser } from "../../types/users/user.ts";
import { GetReactions } from "../../types/messages/message_get_reactions.ts";
import { User } from "../../types/users/user.ts";
import { Collection } from "../../util/collection.ts";
import { endpoints } from "../../util/constants.ts";
import { GetReactions } from "../../types/messages/message_get_reactions.ts";
/** Get a list of users that reacted with this emoji. */
export async function getReactions(
@@ -11,11 +11,11 @@ export async function getReactions(
reaction: string,
options?: GetReactions,
) {
const users = (await rest.runMethod(
const users = await rest.runMethod<User[]>(
"get",
endpoints.CHANNEL_MESSAGE_REACTION(channelId, messageId, reaction),
options,
)) as DiscordUser[];
);
return new Collection(users.map((user) => [user.id, user]));
}
+1 -3
View File
@@ -6,12 +6,10 @@ import { requireBotChannelPermissions } from "../../util/permissions.ts";
export async function pin(channelId: string, messageId: string) {
await requireBotChannelPermissions(channelId, ["MANAGE_MESSAGES"]);
const result = await rest.runMethod(
return await rest.runMethod<undefined>(
"put",
endpoints.CHANNEL_PIN(channelId, messageId),
);
return result;
}
// aliases
+4 -4
View File
@@ -1,14 +1,14 @@
import { rest } from "../../rest/rest.ts";
import { structures } from "../../structures/mod.ts";
import { DiscordMessage } from "../../types/messages/message.ts";
import { Message } from "../../types/messages/message.ts";
import { endpoints } from "../../util/constants.ts";
/** Crosspost a message in a News Channel to following channels. */
export async function publishMessage(channelId: string, messageId: string) {
const data = (await rest.runMethod(
const data = await rest.runMethod<Message>(
"post",
endpoints.CHANNEL_MESSAGE_CROSSPOST(channelId, messageId),
)) as DiscordMessage;
);
return structures.createDiscordenoMessage(data);
return await structures.createDiscordenoMessage(data);
}
+1 -3
View File
@@ -6,10 +6,8 @@ import { requireBotChannelPermissions } from "../../util/permissions.ts";
export async function removeAllReactions(channelId: string, messageId: string) {
await requireBotChannelPermissions(channelId, ["MANAGE_MESSAGES"]);
const result = await rest.runMethod(
return await rest.runMethod<undefined>(
"delete",
endpoints.CHANNEL_MESSAGE_REACTIONS(channelId, messageId),
);
return result;
}
+1 -3
View File
@@ -13,10 +13,8 @@ export async function removeReaction(
reaction = reaction.substring(3, reaction.length - 1);
}
const result = await rest.runMethod(
return await rest.runMethod<undefined>(
"delete",
endpoints.CHANNEL_MESSAGE_REACTION_ME(channelId, messageId, reaction),
);
return result;
}
@@ -16,10 +16,8 @@ export async function removeReactionEmoji(
reaction = reaction.substring(3, reaction.length - 1);
}
const result = await rest.runMethod(
return await rest.runMethod<undefined>(
"delete",
endpoints.CHANNEL_MESSAGE_REACTION(channelId, messageId, reaction),
);
return result;
}
+1 -3
View File
@@ -17,7 +17,7 @@ export async function removeUserReaction(
reaction = reaction.substring(3, reaction.length - 1);
}
const result = await rest.runMethod(
return await rest.runMethod<undefined>(
"delete",
endpoints.CHANNEL_MESSAGE_REACTION_USER(
channelId,
@@ -26,6 +26,4 @@ export async function removeUserReaction(
userId,
),
);
return result;
}
+3 -3
View File
@@ -4,7 +4,7 @@ import { structures } from "../../structures/mod.ts";
import { DiscordChannelTypes } from "../../types/channels/channel_types.ts";
import { DiscordAllowedMentionsTypes } from "../../types/messages/allowed_mentions_types.ts";
import { CreateMessage } from "../../types/messages/create_message.ts";
import { DiscordMessage } from "../../types/messages/message.ts";
import { DiscordMessage, Message } from "../../types/messages/message.ts";
import { Errors } from "../../types/misc/errors.ts";
import { PermissionStrings } from "../../types/permissions/permission_strings.ts";
import { endpoints } from "../../util/constants.ts";
@@ -93,7 +93,7 @@ export async function sendMessage(
}
}
const result = (await rest.runMethod(
const result = await rest.runMethod<Message>(
"post",
endpoints.CHANNEL_MESSAGES(channelId),
camelKeysToSnakeCase<DiscordMessage>({
@@ -107,7 +107,7 @@ export async function sendMessage(
}
: {}),
}),
)) as DiscordMessage;
);
return structures.createDiscordenoMessage(result);
}
+1 -3
View File
@@ -9,12 +9,10 @@ export async function unpin(
): Promise<undefined> {
await requireBotChannelPermissions(channelId, ["MANAGE_MESSAGES"]);
const result = await rest.runMethod(
return await rest.runMethod<undefined>(
"delete",
endpoints.CHANNEL_PIN(channelId, messageId),
);
return result;
}
// aliases
+2 -8
View File
@@ -1,14 +1,8 @@
import { rest } from "../../rest/rest.ts";
import {
DiscordGetGatewayBot,
GetGatewayBot,
} from "../../types/gateway/get_gateway_bot.ts";
import { GetGatewayBot } from "../../types/gateway/get_gateway_bot.ts";
import { endpoints } from "../../util/constants.ts";
import { snakeKeysToCamelCase } from "../../util/utils.ts";
/** Get the bots Gateway metadata that can help during the operation of large or sharded bots. */
export async function getGatewayBot() {
const result = await rest.runMethod("get", endpoints.GATEWAY_BOT);
return snakeKeysToCamelCase(result as DiscordGetGatewayBot) as GetGatewayBot;
return await rest.runMethod<GetGatewayBot>("get", endpoints.GATEWAY_BOT);
}
+1 -5
View File
@@ -1,12 +1,8 @@
import { rest } from "../../rest/rest.ts";
import { DiscordUser } from "../../types/users/user.ts";
import { User } from "../../types/users/user.ts";
import { endpoints } from "../../util/constants.ts";
import { snakeKeysToCamelCase } from "../../util/utils.ts";
/** This function will return the raw user payload in the rare cases you need to fetch a user directly from the API. */
export async function getUser(userId: string) {
const result: User = await rest.runMethod("get", endpoints.USER(userId));
return snakeKeysToCamelCase<DiscordUser>(result);
return await rest.runMethod<User>("get", endpoints.USER(userId));
}
+1 -3
View File
@@ -25,11 +25,9 @@ export async function addRole(
await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]);
const result = await rest.runMethod(
return await rest.runMethod<undefined>(
"put",
endpoints.GUILD_MEMBER_ROLE(guildId, memberId, roleId),
{ reason },
);
return result;
}
+4 -3
View File
@@ -2,7 +2,7 @@ import { cacheHandlers } from "../../cache.ts";
import { rest } from "../../rest/rest.ts";
import { structures } from "../../structures/mod.ts";
import { CreateGuildRole } from "../../types/guilds/create_guild_role.ts";
import { DiscordRole } from "../../types/permissions/role.ts";
import { Role } from "../../types/permissions/role.ts";
import { endpoints } from "../../util/constants.ts";
import {
calculateBits,
@@ -17,7 +17,7 @@ export async function createRole(
) {
await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]);
const result: DiscordRole = await rest.runMethod(
const result = await rest.runMethod<Role>(
"post",
endpoints.GUILD_ROLES(guildId),
{
@@ -29,10 +29,11 @@ export async function createRole(
const role = await structures.createDiscordenoRole({
role: result,
guild_id: guildId,
guildId,
});
const guild = await cacheHandlers.get("guilds", guildId);
guild?.roles.set(role.id, role);
// TODO: ADD TO CACHE?
return role;
}
+1 -3
View File
@@ -6,10 +6,8 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts";
export async function deleteRole(guildId: string, id: string) {
await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]);
const result = await rest.runMethod(
return await rest.runMethod<undefined>(
"delete",
endpoints.GUILD_ROLE(guildId, id),
);
return result;
}
+4 -3
View File
@@ -1,5 +1,6 @@
import { rest } from "../../rest/rest.ts";
import { CreateGuildRole } from "../../types/mod.ts";
import { structures } from "../../structures/mod.ts";
import { CreateGuildRole, Role } from "../../types/mod.ts";
import { endpoints } from "../../util/constants.ts";
import {
calculateBits,
@@ -14,7 +15,7 @@ export async function editRole(
) {
await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]);
const result = await rest.runMethod(
const result = await rest.runMethod<Role>(
"patch",
endpoints.GUILD_ROLE(guildId, id),
{
@@ -25,5 +26,5 @@ export async function editRole(
},
);
return result;
return await structures.createDiscordenoRole({ role: result, guildId });
}
+6 -5
View File
@@ -1,9 +1,8 @@
import { rest } from "../../rest/rest.ts";
import { DiscordRole, Role } from "../../types/permissions/role.ts";
import { Role } from "../../types/permissions/role.ts";
import { Collection } from "../../util/collection.ts";
import { endpoints } from "../../util/constants.ts";
import { requireBotGuildPermissions } from "../../util/permissions.ts";
import { snakeKeysToCamelCase } from "../../util/utils.ts";
/** Returns a list of role objects for the guild.
*
@@ -12,12 +11,14 @@ import { snakeKeysToCamelCase } from "../../util/utils.ts";
export async function getRoles(guildId: string) {
await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]);
const result = (await rest.runMethod(
const result = await rest.runMethod<Role[]>(
"get",
endpoints.GUILD_ROLES(guildId),
)) as DiscordRole[];
);
// TODO: addToCache
return new Collection(
result.map((role) => [role.id, snakeKeysToCamelCase<Role>(role)]),
result.map((role) => [role.id, role]),
);
}
+1 -3
View File
@@ -27,11 +27,9 @@ export async function removeRole(
await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]);
const result = await rest.runMethod(
return await rest.runMethod<undefined>(
"delete",
endpoints.GUILD_MEMBER_ROLE(guildId, memberId, roleId),
{ reason },
);
return result;
}
@@ -3,7 +3,7 @@ import { rest } from "../../rest/rest.ts";
import { Guild } from "../../types/guilds/guild.ts";
import { CreateGuildFromTemplate } from "../../types/templates/create_guild_from_template.ts";
import { endpoints } from "../../util/constants.ts";
import { snakeKeysToCamelCase, urlToBase64 } from "../../util/utils.ts";
import { urlToBase64 } from "../../util/utils.ts";
/**
* Create a new guild based on a template
@@ -23,11 +23,11 @@ export async function createGuildFromTemplate(
data.icon = await urlToBase64(data.icon);
}
const result = await rest.runMethod(
// TODO: discordeno guild?
return await rest.runMethod<Guild>(
"post",
endpoints.GUILD_TEMPLATE(templateCode),
data,
);
return snakeKeysToCamelCase<Guild>(result);
}
@@ -1,8 +1,7 @@
import { rest } from "../../rest/rest.ts";
import { DiscordTemplate, Template } from "../../types/templates/template.ts";
import { Template } from "../../types/templates/template.ts";
import { endpoints } from "../../util/constants.ts";
import { requireBotGuildPermissions } from "../../util/permissions.ts";
import { snakeKeysToCamelCase } from "../../util/utils.ts";
/**
* Creates a template for the guild.
@@ -24,11 +23,9 @@ export async function createGuildTemplate(
throw new Error("The description can only be in between 0-120 characters.");
}
const template = await rest.runMethod<DiscordTemplate>(
return await rest.runMethod<Template>(
"post",
endpoints.GUILD_TEMPLATES(guildId),
data,
);
return snakeKeysToCamelCase<Template>(template);
}
@@ -1,8 +1,7 @@
import { rest } from "../../rest/rest.ts";
import { DiscordTemplate, Template } from "../../types/templates/template.ts";
import { Template } from "../../types/templates/template.ts";
import { endpoints } from "../../util/constants.ts";
import { requireBotGuildPermissions } from "../../util/permissions.ts";
import { snakeKeysToCamelCase } from "../../util/utils.ts";
/**
* Deletes a template from a guild.
@@ -14,10 +13,8 @@ export async function deleteGuildTemplate(
) {
await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]);
const deletedTemplate = await rest.runMethod<DiscordTemplate>(
return await rest.runMethod<Template>(
"delete",
`${endpoints.GUILD_TEMPLATES(guildId)}/${templateCode}`,
);
return snakeKeysToCamelCase<Template>(deletedTemplate);
}
+2 -5
View File
@@ -1,9 +1,8 @@
import { rest } from "../../rest/rest.ts";
import { ModifyGuildTemplate } from "../../types/templates/modify_guild_template.ts";
import { DiscordTemplate, Template } from "../../types/templates/template.ts";
import { Template } from "../../types/templates/template.ts";
import { endpoints } from "../../util/constants.ts";
import { requireBotGuildPermissions } from "../../util/permissions.ts";
import { snakeKeysToCamelCase } from "../../util/utils.ts";
/**
* Edit a template's metadata.
@@ -24,11 +23,9 @@ export async function editGuildTemplate(
throw new Error("The description can only be in between 0-120 characters.");
}
const template = await rest.runMethod<DiscordTemplate>(
return await rest.runMethod<Template>(
"patch",
`${endpoints.GUILD_TEMPLATES(guildId)}/${templateCode}`,
data,
);
return snakeKeysToCamelCase<Template>(template);
}
+4 -5
View File
@@ -1,9 +1,8 @@
import { rest } from "../../rest/rest.ts";
import { DiscordTemplate, Template } from "../../types/templates/template.ts";
import { Template } from "../../types/templates/template.ts";
import { Collection } from "../../util/collection.ts";
import { endpoints } from "../../util/constants.ts";
import { requireBotGuildPermissions } from "../../util/permissions.ts";
import { snakeKeysToCamelCase } from "../../util/utils.ts";
/**
* Returns an array of templates.
@@ -12,15 +11,15 @@ import { snakeKeysToCamelCase } from "../../util/utils.ts";
export async function getGuildTemplates(guildId: string) {
await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]);
const templates = (await rest.runMethod(
const templates = await rest.runMethod<Template[]>(
"get",
endpoints.GUILD_TEMPLATES(guildId),
)) as DiscordTemplate[];
);
return new Collection(
templates.map((template) => [
template.code,
snakeKeysToCamelCase<Template>(template),
template,
]),
);
}
+2 -5
View File
@@ -1,14 +1,11 @@
import { rest } from "../../rest/rest.ts";
import { DiscordTemplate, Template } from "../../types/templates/template.ts";
import { Template } from "../../types/templates/template.ts";
import { endpoints } from "../../util/constants.ts";
import { snakeKeysToCamelCase } from "../../util/utils.ts";
/** Returns the guild template if it exists */
export async function getTemplate(templateCode: string) {
const template = await rest.runMethod<DiscordTemplate>(
return await rest.runMethod<Template>(
"get",
endpoints.GUILD_TEMPLATE(templateCode),
);
return snakeKeysToCamelCase<Template>(template);
}
+2 -5
View File
@@ -1,8 +1,7 @@
import { rest } from "../../rest/rest.ts";
import { DiscordTemplate, Template } from "../../types/templates/template.ts";
import { Template } from "../../types/templates/template.ts";
import { endpoints } from "../../util/constants.ts";
import { requireBotGuildPermissions } from "../../util/permissions.ts";
import { snakeKeysToCamelCase } from "../../util/utils.ts";
/**
* Syncs the template to the guild's current state.
@@ -11,10 +10,8 @@ import { snakeKeysToCamelCase } from "../../util/utils.ts";
export async function syncGuildTemplate(guildId: string, templateCode: string) {
await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]);
const template = await rest.runMethod<DiscordTemplate>(
return await rest.runMethod<Template>(
"put",
`${endpoints.GUILD_TEMPLATES(guildId)}/${templateCode}`,
);
return snakeKeysToCamelCase<Template>(template);
}
+2 -5
View File
@@ -2,10 +2,9 @@ import { rest } from "../../rest/rest.ts";
import { Errors } from "../../types/misc/errors.ts";
import { CreateWebhook } from "../../types/webhooks/create_webhook.ts";
import { Webhook } from "../../types/webhooks/webhook.ts";
import { DiscordWebhook } from "../../types/webhooks/webhook.ts";
import { endpoints } from "../../util/constants.ts";
import { requireBotChannelPermissions } from "../../util/permissions.ts";
import { snakeKeysToCamelCase, urlToBase64 } from "../../util/utils.ts";
import { urlToBase64 } from "../../util/utils.ts";
import { validateLength } from "../../util/validate_length.ts";
/**
@@ -27,7 +26,7 @@ export async function createWebhook(
throw new Error(Errors.INVALID_WEBHOOK_NAME);
}
const result: DiscordWebhook = await rest.runMethod(
return await rest.runMethod<Webhook>(
"post",
endpoints.CHANNEL_WEBHOOKS(channelId),
{
@@ -35,6 +34,4 @@ export async function createWebhook(
avatar: options.avatar ? await urlToBase64(options.avatar) : undefined,
},
);
return snakeKeysToCamelCase<Webhook>(result);
}
+1 -3
View File
@@ -6,10 +6,8 @@ import { requireBotChannelPermissions } from "../../util/permissions.ts";
export async function deleteWebhook(channelId: string, webhookId: string) {
await requireBotChannelPermissions(channelId, ["MANAGE_WEBHOOKS"]);
const result = await rest.runMethod(
return await rest.runMethod<undefined>(
"delete",
endpoints.WEBHOOK_ID(webhookId),
);
return result;
}
@@ -6,10 +6,8 @@ export async function deleteWebhookMessage(
webhookToken: string,
messageId: string,
) {
const result = await rest.runMethod(
return await rest.runMethod<undefined>(
"delete",
endpoints.WEBHOOK_MESSAGE(webhookId, webhookToken, messageId),
);
return result;
}
@@ -6,10 +6,8 @@ export async function deleteWebhookWithToken(
webhookId: string,
webhookToken: string,
) {
const result = await rest.runMethod(
return await rest.runMethod<undefined>(
"delete",
endpoints.WEBHOOK(webhookId, webhookToken),
);
return result;
}
+2 -5
View File
@@ -1,9 +1,8 @@
import { rest } from "../../rest/rest.ts";
import { ModifyWebhook } from "../../types/webhooks/modify_webhook.ts";
import { DiscordWebhook, Webhook } from "../../types/webhooks/webhook.ts";
import { Webhook } from "../../types/webhooks/webhook.ts";
import { endpoints } from "../../util/constants.ts";
import { requireBotChannelPermissions } from "../../util/permissions.ts";
import { snakeKeysToCamelCase } from "../../util/utils.ts";
/** Edit a webhook. Requires the `MANAGE_WEBHOOKS` permission. Returns the updated webhook object on success. */
export async function editWebhook(
@@ -13,7 +12,7 @@ export async function editWebhook(
) {
await requireBotChannelPermissions(channelId, ["MANAGE_WEBHOOKS"]);
const result: DiscordWebhook = await rest.runMethod(
return await rest.runMethod<Webhook>(
"patch",
endpoints.WEBHOOK_ID(webhookId),
{
@@ -21,6 +20,4 @@ export async function editWebhook(
channel_id: options.channelId,
},
);
return snakeKeysToCamelCase<Webhook>(result);
}
+4 -5
View File
@@ -1,7 +1,7 @@
import { rest } from "../../rest/rest.ts";
import { structures } from "../../structures/mod.ts";
import { DiscordAllowedMentionsTypes } from "../../types/messages/allowed_mentions_types.ts";
import { DiscordMessage } from "../../types/messages/message.ts";
import { Message } from "../../types/messages/message.ts";
import { Errors } from "../../types/misc/errors.ts";
import { EditWebhookMessage } from "../../types/webhooks/edit_webhook_message.ts";
import { endpoints } from "../../util/constants.ts";
@@ -60,12 +60,11 @@ export async function editWebhookMessage(
}
}
const result = (await rest.runMethod(
const result = await rest.runMethod<Message>(
"patch",
endpoints.WEBHOOK_MESSAGE(webhookId, webhookToken, messageId),
{ ...options, allowedMentions: options.allowedMentions },
)) as DiscordMessage;
);
const message = await structures.createDiscordenoMessage(result);
return message;
return await structures.createDiscordenoMessage(result);
}

Some files were not shown because too many files have changed in this diff Show More