mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 11:28:15 +00:00
messages
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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)),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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]));
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user