mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-04 18:00:08 +00:00
fix: more return await fixes
This commit is contained in:
@@ -3,5 +3,16 @@ import type { Bot } from "../../bot.ts";
|
||||
|
||||
/** Gets the stage instance associated with the Stage channel, if it exists. */
|
||||
export async function getStageInstance(bot: Bot, channelId: bigint) {
|
||||
return await bot.rest.runMethod<StageInstance>(bot.rest, "get", bot.constants.endpoints.STAGE_INSTANCE(channelId));
|
||||
const result = await bot.rest.runMethod<StageInstance>(
|
||||
bot.rest,
|
||||
"get",
|
||||
bot.constants.endpoints.STAGE_INSTANCE(channelId)
|
||||
);
|
||||
|
||||
return {
|
||||
id: bot.transformers.snowflake(result.id),
|
||||
guildId: bot.transformers.snowflake(result.guild_id),
|
||||
channelId: bot.transformers.snowflake(result.channel_id),
|
||||
topic: result.topic,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -4,8 +4,18 @@ import type { Bot } from "../../../bot.ts";
|
||||
|
||||
/** Creates a new private thread. Returns a thread channel. */
|
||||
export async function startThreadWithoutMessage(bot: Bot, channelId: bigint, options: StartThreadWithoutMessage) {
|
||||
return await bot.rest.runMethod<Channel>(bot.rest, "post", bot.constants.endpoints.THREAD_START_PRIVATE(channelId), {
|
||||
name: options.name,
|
||||
auto_archive_duration: options.autoArchiveDuration,
|
||||
const result = await bot.rest.runMethod<Channel>(
|
||||
bot.rest,
|
||||
"post",
|
||||
bot.constants.endpoints.THREAD_START_PRIVATE(channelId),
|
||||
{
|
||||
name: options.name,
|
||||
auto_archive_duration: options.autoArchiveDuration,
|
||||
}
|
||||
);
|
||||
|
||||
return bot.transformers.channel(bot, {
|
||||
channel: result,
|
||||
guildId: result.guild_id ? bot.transformers.snowflake(result.guild_id) : undefined,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ import type { Bot } from "../../bot.ts";
|
||||
* - When suppressed, the user will have their `request_to_speak_timestamp` removed.
|
||||
*/
|
||||
export async function updateBotVoiceState(bot: Bot, guildId: bigint, options: UpdateSelfVoiceState) {
|
||||
return await bot.rest.runMethod(bot.rest, "patch", bot.constants.endpoints.UPDATE_VOICE_STATE(guildId), {
|
||||
await bot.rest.runMethod(bot.rest, "patch", bot.constants.endpoints.UPDATE_VOICE_STATE(guildId), {
|
||||
channel_id: options.channelId,
|
||||
suppress: options.suppress,
|
||||
request_to_speak_timestamp: options.requestToSpeakTimestamp
|
||||
@@ -34,7 +34,7 @@ export async function updateBotVoiceState(bot: Bot, guildId: bigint, options: Up
|
||||
* - When suppressed, the user will have their `request_to_speak_timestamp` removed.
|
||||
*/
|
||||
export async function updateUserVoiceState(bot: Bot, guildId: bigint, options: UpdateOthersVoiceState) {
|
||||
return await bot.rest.runMethod(
|
||||
await bot.rest.runMethod(
|
||||
bot.rest,
|
||||
"patch",
|
||||
bot.constants.endpoints.UPDATE_VOICE_STATE(guildId, options.userId),
|
||||
|
||||
@@ -3,7 +3,7 @@ import type { Bot } from "../../bot.ts";
|
||||
|
||||
/** Add a discovery subcategory to the guild. Requires the `MANAGE_GUILD` permission. */
|
||||
export async function addDiscoverySubcategory(bot: Bot, guildId: bigint, categoryId: number) {
|
||||
return await bot.rest.runMethod<AddGuildDiscoverySubcategory>(
|
||||
await bot.rest.runMethod<AddGuildDiscoverySubcategory>(
|
||||
bot.rest,
|
||||
"post",
|
||||
bot.constants.endpoints.DISCOVERY_SUBCATEGORY(guildId, categoryId)
|
||||
|
||||
@@ -4,7 +4,7 @@ import type { Bot } from "../../bot.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(bot: Bot, guildId: bigint, data: ModifyGuildDiscoveryMetadata) {
|
||||
return await bot.rest.runMethod<DiscoveryMetadata>(
|
||||
const result = await bot.rest.runMethod<DiscoveryMetadata>(
|
||||
bot.rest,
|
||||
"patch",
|
||||
bot.constants.endpoints.DISCOVERY_METADATA(guildId),
|
||||
@@ -14,4 +14,18 @@ export async function editDiscovery(bot: Bot, guildId: bigint, data: ModifyGuild
|
||||
emoji_discoverability_enabled: data.emojiDiscoverabilityEnabled,
|
||||
}
|
||||
);
|
||||
|
||||
return {
|
||||
guildId,
|
||||
primaryCategoryId: result.primary_category_id,
|
||||
keywords: result.keywords ?? undefined,
|
||||
emojiDiscoverabilityEnabled: result.emoji_discoverability_enabled,
|
||||
partnerActionedTimestamp: result.partner_actioned_timestamp
|
||||
? Date.parse(result.partner_actioned_timestamp)
|
||||
: undefined,
|
||||
partnerApplicationTimestamp: result.partner_application_timestamp
|
||||
? Date.parse(result.partner_application_timestamp)
|
||||
: undefined,
|
||||
categoryIds: result.category_ids,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -3,9 +3,23 @@ import type { Bot } from "../../bot.ts";
|
||||
|
||||
/** Returns the discovery metadata object for the guild. Requires the `MANAGE_GUILD` permission. */
|
||||
export async function getDiscovery(bot: Bot, guildId: bigint) {
|
||||
return await bot.rest.runMethod<DiscoveryMetadata>(
|
||||
const result = await bot.rest.runMethod<DiscoveryMetadata>(
|
||||
bot.rest,
|
||||
"get",
|
||||
bot.constants.endpoints.DISCOVERY_METADATA(guildId)
|
||||
);
|
||||
|
||||
return {
|
||||
guildId,
|
||||
primaryCategoryId: result.primary_category_id,
|
||||
keywords: result.keywords ?? undefined,
|
||||
emojiDiscoverabilityEnabled: result.emoji_discoverability_enabled,
|
||||
partnerActionedTimestamp: result.partner_actioned_timestamp
|
||||
? Date.parse(result.partner_actioned_timestamp)
|
||||
: undefined,
|
||||
partnerApplicationTimestamp: result.partner_application_timestamp
|
||||
? Date.parse(result.partner_application_timestamp)
|
||||
: undefined,
|
||||
categoryIds: result.category_ids,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -4,5 +4,12 @@ import type { Bot } from "../../bot.ts";
|
||||
|
||||
/** Modify the given emoji. Requires the MANAGE_EMOJIS permission. */
|
||||
export async function editEmoji(bot: Bot, guildId: bigint, id: bigint, options: ModifyGuildEmoji) {
|
||||
return await bot.rest.runMethod<Emoji>(bot.rest, "patch", bot.constants.endpoints.GUILD_EMOJI(guildId, id), options);
|
||||
const result = await bot.rest.runMethod<Emoji>(
|
||||
bot.rest,
|
||||
"patch",
|
||||
bot.constants.endpoints.GUILD_EMOJI(guildId, id),
|
||||
options
|
||||
);
|
||||
|
||||
return bot.transformers.emoji(bot, result);
|
||||
}
|
||||
|
||||
@@ -6,5 +6,11 @@ import type { Bot } from "../../bot.ts";
|
||||
* Returns an emoji for the given guild and emoji Id.
|
||||
*/
|
||||
export async function getEmoji(bot: Bot, guildId: bigint, emojiId: bigint) {
|
||||
return await bot.rest.runMethod<Emoji>(bot.rest, "get", bot.constants.endpoints.GUILD_EMOJI(guildId, emojiId));
|
||||
const result = await bot.rest.runMethod<Emoji>(
|
||||
bot.rest,
|
||||
"get",
|
||||
bot.constants.endpoints.GUILD_EMOJI(guildId, emojiId)
|
||||
);
|
||||
|
||||
return bot.transformers.emoji(bot, result);
|
||||
}
|
||||
|
||||
@@ -3,10 +3,14 @@ import type { Bot } from "../../bot.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(bot: Bot, guildId: bigint) {
|
||||
return await bot.rest.runMethod<
|
||||
| (Partial<InviteMetadata> & Pick<InviteMetadata, "uses" | "code">)
|
||||
| {
|
||||
code: null;
|
||||
}
|
||||
>(bot.rest, "get", bot.constants.endpoints.GUILD_VANITY_URL(guildId));
|
||||
const result = await bot.rest.runMethod<Partial<InviteMetadata>>(
|
||||
bot.rest,
|
||||
"get",
|
||||
bot.constants.endpoints.GUILD_VANITY_URL(guildId)
|
||||
);
|
||||
|
||||
return {
|
||||
uses: result.uses,
|
||||
code: result.code,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -10,5 +10,10 @@ export async function getVoiceRegions(bot: Bot, guildId: bigint) {
|
||||
bot.constants.endpoints.GUILD_REGIONS(guildId)
|
||||
);
|
||||
|
||||
return new Collection<string, VoiceRegion>(result.map((region) => [region.id, region]));
|
||||
return new Collection(
|
||||
result.map((reg) => {
|
||||
const region = bot.transformers.voiceRegion(bot, reg);
|
||||
return [region.id, region];
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
@@ -26,8 +26,10 @@ export async function editBotProfile(bot: Bot, options: { username?: string; bot
|
||||
|
||||
const avatar = options?.botAvatarURL ? await bot.utils.urlToBase64(options?.botAvatarURL) : options?.botAvatarURL;
|
||||
|
||||
return await bot.rest.runMethod<User>(bot.rest, "patch", bot.constants.endpoints.USER_BOT, {
|
||||
const result = await bot.rest.runMethod<User>(bot.rest, "patch", bot.constants.endpoints.USER_BOT, {
|
||||
username: options.username?.trim(),
|
||||
avatar,
|
||||
});
|
||||
|
||||
return bot.transformers.user(bot, result);
|
||||
}
|
||||
|
||||
@@ -4,5 +4,7 @@ import { SnakeCasedPropertiesDeep } from "../../types/util.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(bot: Bot, userId: bigint) {
|
||||
return await bot.rest.runMethod<User>(bot.rest, "get", bot.constants.endpoints.USER(userId));
|
||||
const result = await bot.rest.runMethod<User>(bot.rest, "get", bot.constants.endpoints.USER(userId));
|
||||
|
||||
return bot.transformers.user(bot, result);
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import type { Bot } from "../../bot.ts";
|
||||
* Requires the `MANAGE_GUILD` permission.
|
||||
*/
|
||||
export async function deleteGuildTemplate(bot: Bot, guildId: bigint, templateCode: string) {
|
||||
return await bot.rest.runMethod<Template>(
|
||||
await bot.rest.runMethod<Template>(
|
||||
bot.rest,
|
||||
"delete",
|
||||
`${bot.constants.endpoints.GUILD_TEMPLATES(guildId)}/${templateCode}`
|
||||
|
||||
Reference in New Issue
Block a user