mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 19:28:17 +00:00
change: ids to use bigint instead of string (#892)
* p1 of bigints change * shtuff fixes and bits * Commit from GitHub Actions (Lint) * finish bigint structs * typings fixes * Commit from GitHub Actions (Lint) * more fixes * Commit from GitHub Actions (Lint) * more fixes * Commit from GitHub Actions (Lint) * blame wolf * Commit from GitHub Actions (Lint) * foxed * Commit from GitHub Actions (Lint) * fix unit tests * Commit from GitHub Actions (Lint) * change: guildUpdate guild ID can't change * delete server has been renamed to delete guild * fixes Co-authored-by: Skillz4Killz <Skillz4Killz@users.noreply.github.com> Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
|
||||
/** Gets an array of all the channels ids that are the children of this category. */
|
||||
export function categoryChildren(id: string) {
|
||||
export function categoryChildren(id: bigint) {
|
||||
return cacheHandlers.filter(
|
||||
"channels",
|
||||
(channel) => channel.parentId === id,
|
||||
|
||||
@@ -4,9 +4,13 @@ import { PermissionStrings } from "../../types/permissions/permission_strings.ts
|
||||
|
||||
/** Checks if a channel overwrite for a user id or a role id has permission in this channel */
|
||||
export function channelOverwriteHasPermission(
|
||||
guildId: string,
|
||||
id: string,
|
||||
overwrites: DiscordOverwrite[],
|
||||
guildId: bigint,
|
||||
id: bigint,
|
||||
overwrites: (Omit<DiscordOverwrite, "id" | "allow" | "deny"> & {
|
||||
id: bigint;
|
||||
allow: bigint;
|
||||
deny: bigint;
|
||||
})[],
|
||||
permissions: PermissionStrings[],
|
||||
) {
|
||||
const overwrite = overwrites.find((perm) => perm.id === id) ||
|
||||
|
||||
@@ -2,11 +2,12 @@ import { cacheHandlers } from "../../cache.ts";
|
||||
import { DiscordChannelTypes } from "../../types/channels/channel_types.ts";
|
||||
import { CreateGuildChannel } from "../../types/guilds/create_guild_channel.ts";
|
||||
import { Errors } from "../../types/misc/errors.ts";
|
||||
import { bigintToSnowflake } from "../../util/bigint.ts";
|
||||
import { calculatePermissions } from "../../util/permissions.ts";
|
||||
import { createChannel } from "./create_channel.ts";
|
||||
|
||||
/** Create a copy of a channel */
|
||||
export async function cloneChannel(channelId: string, reason?: string) {
|
||||
export async function cloneChannel(channelId: bigint, reason?: string) {
|
||||
const channelToClone = await cacheHandlers.get("channels", channelId);
|
||||
//Return undefined if channel is not cached
|
||||
if (!channelToClone) throw new Error(Errors.CHANNEL_NOT_FOUND);
|
||||
@@ -23,14 +24,16 @@ export async function cloneChannel(channelId: string, reason?: string) {
|
||||
...channelToClone,
|
||||
name: channelToClone.name!,
|
||||
topic: channelToClone.topic || undefined,
|
||||
parentId: channelToClone.parentId || undefined,
|
||||
parentId: channelToClone.parentId
|
||||
? bigintToSnowflake(channelToClone.parentId)
|
||||
: undefined,
|
||||
permissionOverwrites: channelToClone.permissionOverwrites.map((
|
||||
overwrite,
|
||||
) => ({
|
||||
id: overwrite.id,
|
||||
id: overwrite.id.toString(),
|
||||
type: overwrite.type,
|
||||
allow: calculatePermissions(overwrite.allow),
|
||||
deny: calculatePermissions(overwrite.deny),
|
||||
allow: calculatePermissions(overwrite.allow.toString()),
|
||||
deny: calculatePermissions(overwrite.deny.toString()),
|
||||
})),
|
||||
};
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ import { camelKeysToSnakeCase } from "../../util/utils.ts";
|
||||
|
||||
/** Create a channel in your server. Bot needs MANAGE_CHANNEL permissions in the server. */
|
||||
export async function createChannel(
|
||||
guildId: string,
|
||||
guildId: bigint,
|
||||
options?: CreateGuildChannel,
|
||||
reason?: string,
|
||||
) {
|
||||
|
||||
@@ -6,8 +6,8 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
||||
|
||||
/** Delete a channel in your server. Bot needs MANAGE_CHANNEL permissions in the server. */
|
||||
export async function deleteChannel(
|
||||
guildId: string,
|
||||
channelId: string,
|
||||
guildId: bigint,
|
||||
channelId: bigint,
|
||||
reason?: string,
|
||||
): Promise<undefined> {
|
||||
await requireBotGuildPermissions(guildId, ["MANAGE_CHANNELS"]);
|
||||
|
||||
@@ -4,9 +4,9 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
||||
|
||||
/** Delete the channel permission overwrites for a user or role in this channel. Requires `MANAGE_ROLES` permission. */
|
||||
export async function deleteChannelOverwrite(
|
||||
guildId: string,
|
||||
channelId: string,
|
||||
overwriteId: string,
|
||||
guildId: bigint,
|
||||
channelId: bigint,
|
||||
overwriteId: bigint,
|
||||
): Promise<undefined> {
|
||||
await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]);
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
|
||||
/** Update a channel's settings. Requires the `MANAGE_CHANNELS` permission for the guild. */
|
||||
export async function editChannel(
|
||||
channelId: string,
|
||||
channelId: bigint,
|
||||
options: ModifyChannel,
|
||||
reason?: string,
|
||||
) {
|
||||
@@ -72,14 +72,14 @@ export async function editChannel(
|
||||
interface EditChannelRequest {
|
||||
amount: number;
|
||||
timestamp: number;
|
||||
channelId: string;
|
||||
channelId: bigint;
|
||||
items: {
|
||||
channelId: string;
|
||||
channelId: bigint;
|
||||
options: ModifyChannel;
|
||||
}[];
|
||||
}
|
||||
|
||||
const editChannelNameTopicQueue = new Map<string, EditChannelRequest>();
|
||||
const editChannelNameTopicQueue = new Map<bigint, EditChannelRequest>();
|
||||
let editChannelProcessing = false;
|
||||
|
||||
function processEditChannelQueue() {
|
||||
|
||||
@@ -8,9 +8,9 @@ import {
|
||||
|
||||
/** Edit the channel permission overwrites for a user or role in this channel. Requires `MANAGE_ROLES` permission. */
|
||||
export async function editChannelOverwrite(
|
||||
guildId: string,
|
||||
channelId: string,
|
||||
overwriteId: string,
|
||||
guildId: bigint,
|
||||
channelId: bigint,
|
||||
overwriteId: bigint,
|
||||
options: Omit<Overwrite, "id">,
|
||||
): Promise<undefined> {
|
||||
await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]);
|
||||
|
||||
@@ -5,8 +5,8 @@ import { requireBotChannelPermissions } from "../../util/permissions.ts";
|
||||
|
||||
/** Follow a News Channel to send messages to a target channel. Requires the `MANAGE_WEBHOOKS` permission in the target channel. Returns the webhook id. */
|
||||
export async function followChannel(
|
||||
sourceChannelId: string,
|
||||
targetChannelId: string,
|
||||
sourceChannelId: bigint,
|
||||
targetChannelId: bigint,
|
||||
) {
|
||||
await requireBotChannelPermissions(targetChannelId, ["MANAGE_WEBHOOKS"]);
|
||||
|
||||
|
||||
@@ -2,13 +2,14 @@ import { cacheHandlers } from "../../cache.ts";
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import { structures } from "../../structures/mod.ts";
|
||||
import { Channel } from "../../types/channels/channel.ts";
|
||||
import { snowflakeToBigint } from "../../util/bigint.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
|
||||
/** Fetches a single channel object from the api.
|
||||
*
|
||||
* ⚠️ **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) {
|
||||
export async function getChannel(channelId: bigint, addToCache = true) {
|
||||
const result = await rest.runMethod<Channel>(
|
||||
"get",
|
||||
endpoints.CHANNEL_BASE(channelId),
|
||||
@@ -16,7 +17,7 @@ export async function getChannel(channelId: string, addToCache = true) {
|
||||
|
||||
const discordenoChannel = await structures.createDiscordenoChannel(
|
||||
result,
|
||||
result.guildId,
|
||||
result.guildId ? snowflakeToBigint(result.guildId) : undefined,
|
||||
);
|
||||
if (addToCache) {
|
||||
await cacheHandlers.set(
|
||||
|
||||
@@ -5,7 +5,7 @@ import { endpoints } from "../../util/constants.ts";
|
||||
import { requireBotChannelPermissions } from "../../util/permissions.ts";
|
||||
|
||||
/** Gets the webhooks for this channel. Requires MANAGE_WEBHOOKS */
|
||||
export async function getChannelWebhooks(channelId: string) {
|
||||
export async function getChannelWebhooks(channelId: bigint) {
|
||||
await requireBotChannelPermissions(channelId, ["MANAGE_WEBHOOKS"]);
|
||||
|
||||
const result = await rest.runMethod<Webhook[]>(
|
||||
|
||||
@@ -9,7 +9,7 @@ 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) {
|
||||
export async function getChannels(guildId: bigint, addToCache = true) {
|
||||
const result = await rest.runMethod<Channel[]>(
|
||||
"get",
|
||||
endpoints.GUILD_CHANNELS(guildId),
|
||||
|
||||
@@ -4,7 +4,7 @@ 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) {
|
||||
export async function getPins(channelId: bigint) {
|
||||
const result = await rest.runMethod<Message[]>(
|
||||
"get",
|
||||
endpoints.CHANNEL_PINS(channelId),
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
|
||||
/** Checks whether a channel is synchronized with its parent/category channel or not. */
|
||||
export async function isChannelSynced(channelId: string) {
|
||||
export async function isChannelSynced(channelId: bigint) {
|
||||
const channel = await cacheHandlers.get("channels", channelId);
|
||||
if (!channel?.parentId) return false;
|
||||
|
||||
|
||||
@@ -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) {
|
||||
export async function startTyping(channelId: bigint) {
|
||||
const channel = await cacheHandlers.get("channels", channelId);
|
||||
// If the channel is cached, we can do extra checks/safety
|
||||
if (channel) {
|
||||
|
||||
@@ -4,7 +4,7 @@ import { endpoints } from "../../util/constants.ts";
|
||||
|
||||
/** Modify the positions of channels on the guild. Requires MANAGE_CHANNELS permisison. */
|
||||
export async function swapChannels(
|
||||
guildId: string,
|
||||
guildId: bigint,
|
||||
channelPositions: ModifyGuildChannelPositions[],
|
||||
) {
|
||||
if (channelPositions.length < 2) {
|
||||
|
||||
@@ -6,7 +6,7 @@ import { camelKeysToSnakeCase } from "../../util/utils.ts";
|
||||
|
||||
/** Batch edits permissions for all commands in a guild. Takes an array of partial GuildApplicationCommandPermissions objects including `id` and `permissions`. */
|
||||
export async function batchEditSlashCommandPermissions(
|
||||
guildId: string,
|
||||
guildId: bigint,
|
||||
options: { id: string; permissions: ApplicationCommandPermissions[] }[],
|
||||
) {
|
||||
return await rest.runMethod(
|
||||
|
||||
@@ -21,7 +21,7 @@ import {
|
||||
*/
|
||||
export async function createSlashCommand(
|
||||
options: CreateGlobalApplicationCommand,
|
||||
guildId?: string,
|
||||
guildId?: bigint,
|
||||
) {
|
||||
validateSlashCommands([options], true);
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@ import { endpoints } from "../../util/constants.ts";
|
||||
|
||||
/** Deletes a slash command. */
|
||||
export async function deleteSlashCommand(
|
||||
id: string,
|
||||
guildId?: string,
|
||||
id: bigint,
|
||||
guildId?: bigint,
|
||||
) {
|
||||
return await rest.runMethod<undefined>(
|
||||
"delete",
|
||||
|
||||
@@ -5,7 +5,7 @@ import { endpoints } from "../../util/constants.ts";
|
||||
/** To delete your response to a slash command. If a message id is not provided, it will default to deleting the original response. */
|
||||
export async function deleteSlashResponse(
|
||||
token: string,
|
||||
messageId?: string,
|
||||
messageId?: bigint,
|
||||
) {
|
||||
return await rest.runMethod<undefined>(
|
||||
"delete",
|
||||
|
||||
@@ -6,8 +6,8 @@ import { camelKeysToSnakeCase } from "../../util/utils.ts";
|
||||
|
||||
/** Edits command permissions for a specific command for your application in a guild. */
|
||||
export async function editSlashCommandPermissions(
|
||||
guildId: string,
|
||||
commandId: string,
|
||||
guildId: bigint,
|
||||
commandId: bigint,
|
||||
options: ApplicationCommandPermissions[],
|
||||
) {
|
||||
return await rest.runMethod(
|
||||
|
||||
@@ -4,7 +4,7 @@ import { ApplicationCommand } from "../../types/interactions/application_command
|
||||
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) {
|
||||
export async function getSlashCommand(commandId: bigint, guildId?: bigint) {
|
||||
return await rest.runMethod<ApplicationCommand>(
|
||||
"get",
|
||||
guildId
|
||||
|
||||
@@ -5,8 +5,8 @@ import { endpoints } from "../../util/constants.ts";
|
||||
|
||||
/** Fetches command permissions for a specific command for your application in a guild. Returns a GuildApplicationCommandPermissions object. */
|
||||
export async function getSlashCommandPermission(
|
||||
guildId: string,
|
||||
commandId: string,
|
||||
guildId: bigint,
|
||||
commandId: bigint,
|
||||
) {
|
||||
return await rest.runMethod<GuildApplicationCommandPermissions>(
|
||||
"get",
|
||||
|
||||
@@ -4,7 +4,7 @@ import { GuildApplicationCommandPermissions } from "../../types/interactions/gui
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
|
||||
/** Fetches command permissions for all commands for your application in a guild. Returns an array of GuildApplicationCommandPermissions objects. */
|
||||
export async function getSlashCommandPermissions(guildId: string) {
|
||||
export async function getSlashCommandPermissions(guildId: bigint) {
|
||||
return await rest.runMethod<GuildApplicationCommandPermissions[]>(
|
||||
"get",
|
||||
endpoints.COMMANDS_PERMISSIONS(applicationId, guildId),
|
||||
|
||||
@@ -5,7 +5,7 @@ import { Collection } from "../../util/collection.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
|
||||
/** Fetch all of the global commands for your application. */
|
||||
export async function getSlashCommands(guildId?: string) {
|
||||
export async function getSlashCommands(guildId?: bigint) {
|
||||
const result = await rest.runMethod<ApplicationCommand[]>(
|
||||
"get",
|
||||
guildId
|
||||
|
||||
@@ -11,7 +11,7 @@ import { endpoints } from "../../util/constants.ts";
|
||||
* NOTE: By default we will suppress mentions. To enable mentions, just pass any mentions object.
|
||||
*/
|
||||
export async function sendInteractionResponse(
|
||||
id: string,
|
||||
id: bigint,
|
||||
token: string,
|
||||
options: DiscordenoInteractionResponse,
|
||||
) {
|
||||
@@ -27,7 +27,7 @@ export async function sendInteractionResponse(
|
||||
}
|
||||
|
||||
// Expire in 15 minutes
|
||||
cache.executedSlashCommands.set(token, id);
|
||||
cache.executedSlashCommands.add(token);
|
||||
setTimeout(
|
||||
() => {
|
||||
eventHandlers.debug?.(
|
||||
|
||||
@@ -9,9 +9,9 @@ import { validateSlashCommands } from "../../util/utils.ts";
|
||||
* Edit an existing slash command. If this command did not exist, it will create it.
|
||||
*/
|
||||
export async function upsertSlashCommand(
|
||||
commandId: string,
|
||||
commandId: bigint,
|
||||
options: EditGlobalApplicationCommand,
|
||||
guildId?: string,
|
||||
guildId?: bigint,
|
||||
) {
|
||||
validateSlashCommands([options]);
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ import { validateSlashCommands } from "../../util/utils.ts";
|
||||
*/
|
||||
export async function upsertSlashCommands(
|
||||
options: EditGlobalApplicationCommand[],
|
||||
guildId?: string,
|
||||
guildId?: bigint,
|
||||
) {
|
||||
validateSlashCommands(options);
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
||||
|
||||
/** Add a discovery subcategory to the guild. Requires the `MANAGE_GUILD` permission. */
|
||||
export async function addDiscoverySubcategory(
|
||||
guildId: string,
|
||||
guildId: bigint,
|
||||
categoryId: number,
|
||||
) {
|
||||
await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]);
|
||||
|
||||
@@ -7,7 +7,7 @@ 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(
|
||||
guildId: string,
|
||||
guildId: bigint,
|
||||
data: ModifyGuildDiscoveryMetadata,
|
||||
) {
|
||||
await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]);
|
||||
|
||||
@@ -4,7 +4,7 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
||||
|
||||
/** Removes a discovery subcategory from the guild. Requires the MANAGE_GUILD permission. Returns a 204 No Content on success. */
|
||||
export async function removeDiscoverySubcategory(
|
||||
guildId: string,
|
||||
guildId: bigint,
|
||||
categoryId: number,
|
||||
) {
|
||||
await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]);
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import { CreateGuildEmoji } from "../../types/emojis/create_guild_emoji.ts";
|
||||
import { Emoji } from "../../types/emojis/emoji.ts";
|
||||
import { snowflakeToBigint } from "../../util/bigint.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import { requireBotGuildPermissions } from "../../util/permissions.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(
|
||||
guildId: string,
|
||||
guildId: bigint,
|
||||
name: string,
|
||||
image: string,
|
||||
options: CreateGuildEmoji,
|
||||
@@ -18,9 +19,18 @@ export async function createEmoji(
|
||||
image = await urlToBase64(image);
|
||||
}
|
||||
|
||||
return await rest.runMethod<Emoji>("post", endpoints.GUILD_EMOJIS(guildId), {
|
||||
...options,
|
||||
name,
|
||||
image,
|
||||
});
|
||||
const emoji = await rest.runMethod<Emoji>(
|
||||
"post",
|
||||
endpoints.GUILD_EMOJIS(guildId),
|
||||
{
|
||||
...options,
|
||||
name,
|
||||
image,
|
||||
},
|
||||
);
|
||||
|
||||
return {
|
||||
...emoji,
|
||||
id: snowflakeToBigint(emoji.id!),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -4,8 +4,8 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
||||
|
||||
/** Delete the given emoji. Requires the MANAGE_EMOJIS permission. Returns 204 No Content on success. */
|
||||
export async function deleteEmoji(
|
||||
guildId: string,
|
||||
id: string,
|
||||
guildId: bigint,
|
||||
id: bigint,
|
||||
reason?: string,
|
||||
) {
|
||||
await requireBotGuildPermissions(guildId, ["MANAGE_EMOJIS"]);
|
||||
|
||||
@@ -6,8 +6,8 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
||||
|
||||
/** Modify the given emoji. Requires the MANAGE_EMOJIS permission. */
|
||||
export async function editEmoji(
|
||||
guildId: string,
|
||||
id: string,
|
||||
guildId: bigint,
|
||||
id: bigint,
|
||||
options: ModifyGuildEmoji,
|
||||
) {
|
||||
await requireBotGuildPermissions(guildId, ["MANAGE_EMOJIS"]);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/** Creates a url to the emoji from the Discord CDN. */
|
||||
export function emojiURL(id: string, animated = false) {
|
||||
export function emojiURL(id: bigint, animated = false) {
|
||||
return `https://cdn.discordapp.com/emojis/${id}.${animated ? "gif" : "png"}`;
|
||||
}
|
||||
|
||||
@@ -10,8 +10,8 @@ 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 getEmoji(
|
||||
guildId: string,
|
||||
emojiId: string,
|
||||
guildId: bigint,
|
||||
emojiId: bigint,
|
||||
addToCache = true,
|
||||
) {
|
||||
const result = await rest.runMethod<Emoji>(
|
||||
|
||||
@@ -3,6 +3,7 @@ import { cacheHandlers } from "../../cache.ts";
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import { Emoji } from "../../types/emojis/emoji.ts";
|
||||
import { Errors } from "../../types/misc/errors.ts";
|
||||
import { snowflakeToBigint } from "../../util/bigint.ts";
|
||||
import { Collection } from "../../util/collection.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
|
||||
@@ -11,7 +12,7 @@ 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) {
|
||||
export async function getEmojis(guildId: bigint, addToCache = true) {
|
||||
const result = await rest.runMethod<Emoji[]>(
|
||||
"get",
|
||||
endpoints.GUILD_EMOJIS(guildId),
|
||||
@@ -26,7 +27,7 @@ export async function getEmojis(guildId: string, addToCache = true) {
|
||||
"loop",
|
||||
`Running forEach loop in get_emojis file.`,
|
||||
);
|
||||
guild.emojis.set(emoji.id!, emoji);
|
||||
guild.emojis.set(snowflakeToBigint(emoji.id!), emoji);
|
||||
});
|
||||
|
||||
await cacheHandlers.set("guilds", guildId, guild);
|
||||
|
||||
@@ -2,7 +2,7 @@ import { rest } from "../../rest/rest.ts";
|
||||
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 deleteGuild(guildId: string) {
|
||||
export async function deleteGuild(guildId: bigint) {
|
||||
return await rest.runMethod<undefined>(
|
||||
"delete",
|
||||
endpoints.GUILDS_BASE(guildId),
|
||||
|
||||
@@ -9,7 +9,7 @@ import { urlToBase64 } from "../../util/utils.ts";
|
||||
import { ws } from "../../ws/ws.ts";
|
||||
|
||||
/** Modify a guilds settings. Requires the MANAGE_GUILD permission. */
|
||||
export async function editGuild(guildId: string, options: ModifyGuild) {
|
||||
export async function editGuild(guildId: bigint, options: ModifyGuild) {
|
||||
await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]);
|
||||
|
||||
if (options.icon && !options.icon.startsWith("data:image/")) {
|
||||
|
||||
@@ -5,7 +5,7 @@ import { endpoints } from "../../util/constants.ts";
|
||||
import { camelKeysToSnakeCase } from "../../util/utils.ts";
|
||||
|
||||
export async function editWelcomeScreen(
|
||||
guildId: string,
|
||||
guildId: bigint,
|
||||
options: ModifyGuildWelcomeScreen,
|
||||
) {
|
||||
return await rest.runMethod<WelcomeScreen>(
|
||||
|
||||
@@ -5,7 +5,7 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
||||
|
||||
/** Modify a guild widget object for the guild. Requires the MANAGE_GUILD permission. */
|
||||
export async function editWidget(
|
||||
guildId: string,
|
||||
guildId: bigint,
|
||||
enabled: boolean,
|
||||
channelId?: string | null,
|
||||
) {
|
||||
|
||||
@@ -7,7 +7,7 @@ import { camelKeysToSnakeCase } from "../../util/utils.ts";
|
||||
|
||||
/** Returns the audit logs for the guild. Requires VIEW AUDIT LOGS permission */
|
||||
export async function getAuditLogs(
|
||||
guildId: string,
|
||||
guildId: bigint,
|
||||
options: GetGuildAuditLog,
|
||||
) {
|
||||
await requireBotGuildPermissions(guildId, ["VIEW_AUDIT_LOG"]);
|
||||
|
||||
@@ -4,7 +4,7 @@ import { endpoints } from "../../util/constants.ts";
|
||||
import { requireBotGuildPermissions } from "../../util/permissions.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) {
|
||||
export async function getBan(guildId: bigint, memberId: bigint) {
|
||||
await requireBotGuildPermissions(guildId, ["BAN_MEMBERS"]);
|
||||
|
||||
return await rest.runMethod<Ban>(
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import { Ban } from "../../types/guilds/ban.ts";
|
||||
import { snowflakeToBigint } from "../../util/bigint.ts";
|
||||
import { Collection } from "../../util/collection.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import { requireBotGuildPermissions } from "../../util/permissions.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) {
|
||||
export async function getBans(guildId: bigint) {
|
||||
await requireBotGuildPermissions(guildId, ["BAN_MEMBERS"]);
|
||||
|
||||
const results = await rest.runMethod<Ban[]>(
|
||||
@@ -13,7 +14,7 @@ export async function getBans(guildId: string) {
|
||||
endpoints.GUILD_BANS(guildId),
|
||||
);
|
||||
|
||||
return new Collection<string, Ban>(
|
||||
results.map((res) => [res.user.id, res]),
|
||||
return new Collection<bigint, Ban>(
|
||||
results.map((res) => [snowflakeToBigint(res.user.id), res]),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ import { ws } from "../../ws/ws.ts";
|
||||
* So it does not cache the guild, you must do it manually.
|
||||
* */
|
||||
export async function getGuild(
|
||||
guildId: string,
|
||||
guildId: bigint,
|
||||
options: { counts?: boolean; addToCache?: boolean } = {
|
||||
counts: true,
|
||||
addToCache: true,
|
||||
@@ -27,14 +27,14 @@ export async function getGuild(
|
||||
},
|
||||
);
|
||||
|
||||
const structure = await structures.createDiscordenoGuild(
|
||||
const guild = await structures.createDiscordenoGuild(
|
||||
result,
|
||||
Number((BigInt(guildId) >> 22n) % BigInt(ws.botGatewayData.shards)),
|
||||
);
|
||||
|
||||
if (options.addToCache) {
|
||||
await cacheHandlers.set("guilds", guildId, structure);
|
||||
await cacheHandlers.set("guilds", guild.id, guild);
|
||||
}
|
||||
|
||||
return structure;
|
||||
return guild;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ import { GuildPreview } from "../../types/guilds/guild_preview.ts";
|
||||
import { endpoints } from "../../util/constants.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) {
|
||||
export async function getGuildPreview(guildId: bigint) {
|
||||
return await rest.runMethod<GuildPreview>(
|
||||
"get",
|
||||
endpoints.GUILD_PREVIEW(guildId),
|
||||
|
||||
@@ -7,7 +7,7 @@ import { camelKeysToSnakeCase } from "../../util/utils.ts";
|
||||
|
||||
/** Check how many members would be removed from the server in a prune operation. Requires the KICK_MEMBERS permission */
|
||||
export async function getPruneCount(
|
||||
guildId: string,
|
||||
guildId: bigint,
|
||||
options?: GetGuildPruneCountQuery,
|
||||
) {
|
||||
if (options?.days && options.days < 1) throw new Error(Errors.PRUNE_MIN_DAYS);
|
||||
|
||||
@@ -3,7 +3,7 @@ import { InviteMetadata } from "../../types/invites/invite_metadata.ts";
|
||||
import { endpoints } from "../../util/constants.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) {
|
||||
export async function getVanityURL(guildId: bigint) {
|
||||
return await rest.runMethod<
|
||||
(Partial<InviteMetadata> & Pick<InviteMetadata, "uses" | "code">) | {
|
||||
code: null;
|
||||
|
||||
@@ -4,7 +4,7 @@ import { Collection } from "../../util/collection.ts";
|
||||
import { endpoints } from "../../util/constants.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) {
|
||||
export async function getVoiceRegions(guildId: bigint) {
|
||||
const result = await rest.runMethod<VoiceRegion[]>(
|
||||
"get",
|
||||
endpoints.GUILD_REGIONS(guildId),
|
||||
|
||||
@@ -2,7 +2,7 @@ import { rest } from "../../rest/rest.ts";
|
||||
import { WelcomeScreen } from "../../types/mod.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
|
||||
export async function getWelcomeScreen(guildId: string) {
|
||||
export async function getWelcomeScreen(guildId: bigint) {
|
||||
return await rest.runMethod<WelcomeScreen>(
|
||||
"get",
|
||||
endpoints.GUILD_WELCOME_SCREEN(guildId),
|
||||
|
||||
@@ -5,7 +5,7 @@ import { Errors } from "../../types/misc/errors.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
|
||||
/** Returns the widget for the guild. */
|
||||
export async function getWidget(guildId: string, options?: { force: boolean }) {
|
||||
export async function getWidget(guildId: bigint, options?: { force: boolean }) {
|
||||
if (!options?.force) {
|
||||
const guild = await cacheHandlers.get("guilds", guildId);
|
||||
if (!guild) throw new Error(Errors.GUILD_NOT_FOUND);
|
||||
|
||||
@@ -5,7 +5,7 @@ import { endpoints } from "../../util/constants.ts";
|
||||
|
||||
/** Returns the widget image URL for the guild. */
|
||||
export async function getWidgetImageURL(
|
||||
guildId: string,
|
||||
guildId: bigint,
|
||||
options?: GetGuildWidgetImageQuery & { force?: boolean },
|
||||
) {
|
||||
if (!options?.force) {
|
||||
|
||||
@@ -4,7 +4,7 @@ import { endpoints } from "../../util/constants.ts";
|
||||
import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
||||
|
||||
/** Returns the guild widget object. Requires the MANAGE_GUILD permission. */
|
||||
export async function getWidgetSettings(guildId: string) {
|
||||
export async function getWidgetSettings(guildId: bigint) {
|
||||
await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]);
|
||||
|
||||
return await rest.runMethod<GuildWidget>(
|
||||
|
||||
@@ -5,7 +5,7 @@ import { formatImageURL } from "../../util/utils.ts";
|
||||
|
||||
/** The full URL of the banner from Discords CDN. Undefined if no banner is set. */
|
||||
export function guildBannerURL(
|
||||
id: string,
|
||||
id: bigint,
|
||||
banner?: string,
|
||||
size: DiscordImageSize = 128,
|
||||
format?: DiscordImageFormat,
|
||||
|
||||
@@ -5,7 +5,7 @@ import { formatImageURL } from "../../util/utils.ts";
|
||||
|
||||
/** The full URL of the icon from Discords CDN. Undefined when no icon is set. */
|
||||
export function guildIconURL(
|
||||
id: string,
|
||||
id: bigint,
|
||||
icon?: string,
|
||||
size: DiscordImageSize = 128,
|
||||
format?: DiscordImageFormat,
|
||||
|
||||
@@ -5,7 +5,7 @@ import { formatImageURL } from "../../util/utils.ts";
|
||||
|
||||
/** The full URL of the splash from Discords CDN. Undefined if no splash is set. */
|
||||
export function guildSplashURL(
|
||||
id: string,
|
||||
id: bigint,
|
||||
splash?: string,
|
||||
size: DiscordImageSize = 128,
|
||||
format?: DiscordImageFormat,
|
||||
|
||||
@@ -2,7 +2,7 @@ import { rest } from "../../rest/rest.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
|
||||
/** Leave a guild */
|
||||
export async function leaveGuild(guildId: string) {
|
||||
export async function leaveGuild(guildId: bigint) {
|
||||
return await rest.runMethod<undefined>(
|
||||
"delete",
|
||||
endpoints.GUILD_LEAVE(guildId),
|
||||
|
||||
@@ -16,7 +16,7 @@ import { camelKeysToSnakeCase } from "../../util/utils.ts";
|
||||
* - You are able to set `request_to_speak_timestamp` to any present or future time.
|
||||
*/
|
||||
export function updateBotVoiceState(
|
||||
guildId: string,
|
||||
guildId: bigint,
|
||||
data: UpdateSelfVoiceState,
|
||||
) {
|
||||
const payload = camelKeysToSnakeCase<DiscordUpdateSelfVoiceState>(data);
|
||||
|
||||
@@ -16,8 +16,8 @@ import { camelKeysToSnakeCase } from "../../util/utils.ts";
|
||||
* - When suppressed, the user will have their `request_to_speak_timestamp` removed.
|
||||
*/
|
||||
export function updateVoiceState(
|
||||
guildId: string,
|
||||
userId: string,
|
||||
guildId: bigint,
|
||||
userId: bigint,
|
||||
data: UpdateOthersVoiceState,
|
||||
) {
|
||||
const payload = camelKeysToSnakeCase<DiscordUpdateOthersVoiceState>(data);
|
||||
|
||||
@@ -3,7 +3,7 @@ import { endpoints } from "../../util/constants.ts";
|
||||
import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
||||
|
||||
/** Delete the attached integration object for the guild with this id. Requires MANAGE_GUILD permission. */
|
||||
export async function deleteIntegration(guildId: string, id: string) {
|
||||
export async function deleteIntegration(guildId: bigint, id: bigint) {
|
||||
await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]);
|
||||
|
||||
return await rest.runMethod<undefined>(
|
||||
|
||||
@@ -4,7 +4,7 @@ import { endpoints } from "../../util/constants.ts";
|
||||
import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
||||
|
||||
/** Returns a list of integrations for the guild. Requires the MANAGE_GUILD permission. */
|
||||
export async function getIntegrations(guildId: string) {
|
||||
export async function getIntegrations(guildId: bigint) {
|
||||
await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]);
|
||||
|
||||
return await rest.runMethod<Integration>(
|
||||
|
||||
@@ -7,7 +7,7 @@ import { requireBotChannelPermissions } from "../../util/permissions.ts";
|
||||
|
||||
/** Creates a new invite for this channel. Requires CREATE_INSTANT_INVITE */
|
||||
export async function createInvite(
|
||||
channelId: string,
|
||||
channelId: bigint,
|
||||
options: CreateChannelInvite,
|
||||
) {
|
||||
await requireBotChannelPermissions(channelId, ["CREATE_INSTANT_INVITE"]);
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
} from "../../util/permissions.ts";
|
||||
|
||||
/** Deletes an invite for the given code. Requires `MANAGE_CHANNELS` or `MANAGE_GUILD` permission */
|
||||
export async function deleteInvite(channelId: string, inviteCode: string) {
|
||||
export async function deleteInvite(channelId: bigint, inviteCode: string) {
|
||||
const channel = await cacheHandlers.get("channels", channelId);
|
||||
|
||||
if (!channel) throw new Error(Errors.CHANNEL_NOT_FOUND);
|
||||
|
||||
@@ -5,7 +5,7 @@ import { endpoints } from "../../util/constants.ts";
|
||||
import { requireBotChannelPermissions } from "../../util/permissions.ts";
|
||||
|
||||
/** Gets the invites for this channel. Requires MANAGE_CHANNEL */
|
||||
export async function getChannelInvites(channelId: string) {
|
||||
export async function getChannelInvites(channelId: bigint) {
|
||||
await requireBotChannelPermissions(channelId, ["MANAGE_CHANNELS"]);
|
||||
|
||||
const result = await rest.runMethod<Invite[]>(
|
||||
|
||||
@@ -5,7 +5,7 @@ import { endpoints } from "../../util/constants.ts";
|
||||
import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
||||
|
||||
/** Get all the invites for this guild. Requires MANAGE_GUILD permission */
|
||||
export async function getInvites(guildId: string) {
|
||||
export async function getInvites(guildId: bigint) {
|
||||
await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]);
|
||||
|
||||
const result = await rest.runMethod<Invite[]>(
|
||||
|
||||
@@ -5,8 +5,8 @@ import { formatImageURL } from "../../util/utils.ts";
|
||||
|
||||
/** The users custom avatar or the default avatar if you don't have a member object. */
|
||||
export function avatarURL(
|
||||
userId: string,
|
||||
discriminator: string,
|
||||
userId: bigint,
|
||||
discriminator: bigint,
|
||||
avatar?: string | null,
|
||||
size: DiscordImageSize = 128,
|
||||
format?: DiscordImageFormat,
|
||||
|
||||
@@ -6,8 +6,8 @@ import { camelKeysToSnakeCase } from "../../util/utils.ts";
|
||||
|
||||
/** Ban a user from the guild and optionally delete previous messages sent by the user. Requires the BAN_MEMBERS permission. */
|
||||
export async function ban(
|
||||
guildId: string,
|
||||
id: string,
|
||||
guildId: bigint,
|
||||
id: bigint,
|
||||
options: CreateGuildBan,
|
||||
) {
|
||||
await requireBotGuildPermissions(guildId, ["BAN_MEMBERS"]);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { editMember } from "./edit_member.ts";
|
||||
|
||||
/** Kicks a member from a voice channel */
|
||||
export function disconnectMember(guildId: string, memberId: string) {
|
||||
export function disconnectMember(guildId: bigint, memberId: bigint) {
|
||||
return editMember(guildId, memberId, { channelId: null });
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
||||
|
||||
/** Edit the nickname of the bot in this guild */
|
||||
export async function editBotNickname(
|
||||
guildId: string,
|
||||
guildId: bigint,
|
||||
nickname: string | null,
|
||||
) {
|
||||
await requireBotGuildPermissions(guildId, ["CHANGE_NICKNAME"]);
|
||||
|
||||
@@ -5,6 +5,7 @@ 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";
|
||||
import { bigintToSnowflake } from "../../util/bigint.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import {
|
||||
requireBotChannelPermissions,
|
||||
@@ -14,9 +15,9 @@ import { camelKeysToSnakeCase } from "../../util/utils.ts";
|
||||
|
||||
/** Edit the member */
|
||||
export async function editMember(
|
||||
guildId: string,
|
||||
memberId: string,
|
||||
options: ModifyGuildMember,
|
||||
guildId: bigint,
|
||||
memberId: bigint,
|
||||
options: Omit<ModifyGuildMember, "channelId"> & { channelId?: bigint | null },
|
||||
) {
|
||||
const requiredPerms: Set<PermissionStrings> = new Set();
|
||||
|
||||
@@ -72,7 +73,12 @@ export async function editMember(
|
||||
const result = await rest.runMethod<GuildMemberWithUser>(
|
||||
"patch",
|
||||
endpoints.GUILD_MEMBER(guildId, memberId),
|
||||
camelKeysToSnakeCase(options),
|
||||
camelKeysToSnakeCase({
|
||||
...options,
|
||||
channelId: options.channelId
|
||||
? bigintToSnowflake(options.channelId)
|
||||
: undefined,
|
||||
}) as ModifyGuildMember,
|
||||
);
|
||||
|
||||
const member = await structures.createDiscordenoMember(
|
||||
|
||||
@@ -17,7 +17,7 @@ import { ws } from "../../ws/ws.ts";
|
||||
* GW(this function): 120/m(PER shard) rate limit. Meaning if you have 8 shards your limit is now 960/m.
|
||||
*/
|
||||
export function fetchMembers(
|
||||
guildId: string,
|
||||
guildId: bigint,
|
||||
shardId: number,
|
||||
options?: Omit<RequestGuildMembers, "guildId">,
|
||||
) {
|
||||
@@ -49,5 +49,5 @@ export function fetchMembers(
|
||||
nonce,
|
||||
},
|
||||
});
|
||||
}) as Promise<Collection<string, DiscordenoMember>>;
|
||||
}) as Promise<Collection<bigint, DiscordenoMember>>;
|
||||
}
|
||||
|
||||
@@ -9,8 +9,8 @@ import { endpoints } from "../../util/constants.ts";
|
||||
* ⚠️ **ADVANCED USE ONLY: Your members will be cached in your guild most likely. Only use this when you are absolutely sure the member is not cached.**
|
||||
*/
|
||||
export async function getMember(
|
||||
guildId: string,
|
||||
id: string,
|
||||
guildId: bigint,
|
||||
id: bigint,
|
||||
options?: { force?: boolean },
|
||||
) {
|
||||
const guild = await cacheHandlers.get("guilds", guildId);
|
||||
|
||||
@@ -7,6 +7,7 @@ import { DiscordGatewayIntents } from "../../types/gateway/gateway_intents.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 { bigintToSnowflake } from "../../util/bigint.ts";
|
||||
import { Collection } from "../../util/collection.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import { ws } from "../../ws/ws.ts";
|
||||
@@ -20,7 +21,7 @@ import { ws } from "../../ws/ws.ts";
|
||||
* GW(fetchMembers): 120/m(PER shard) rate limit. Meaning if you have 8 shards your limit is 960/m.
|
||||
*/
|
||||
export async function getMembers(
|
||||
guildId: string,
|
||||
guildId: bigint,
|
||||
options?: ListGuildMembers & { addToCache?: boolean },
|
||||
) {
|
||||
if (!(ws.identifyPayload.intents && DiscordGatewayIntents.GUILD_MEMBERS)) {
|
||||
@@ -30,7 +31,7 @@ export async function getMembers(
|
||||
const guild = await cacheHandlers.get("guilds", guildId);
|
||||
if (!guild) throw new Error(Errors.GUILD_NOT_FOUND);
|
||||
|
||||
const members = new Collection<string, DiscordenoMember>();
|
||||
const members = new Collection<bigint, DiscordenoMember>();
|
||||
|
||||
let membersLeft = options?.limit ?? guild.memberCount;
|
||||
let loops = 1;
|
||||
@@ -88,7 +89,9 @@ export async function getMembers(
|
||||
|
||||
options = {
|
||||
limit: options?.limit,
|
||||
after: discordenoMembers[discordenoMembers.length - 1].id,
|
||||
after: bigintToSnowflake(
|
||||
discordenoMembers[discordenoMembers.length - 1].id,
|
||||
),
|
||||
};
|
||||
|
||||
membersLeft -= 1000;
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
} from "../../util/permissions.ts";
|
||||
|
||||
/** Kick a member from the server */
|
||||
export async function kick(guildId: string, memberId: string, reason?: string) {
|
||||
export async function kick(guildId: bigint, memberId: bigint, reason?: string) {
|
||||
const botsHighestRole = await highestRole(guildId, botId);
|
||||
const membersHighestRole = await highestRole(guildId, memberId);
|
||||
if (
|
||||
|
||||
@@ -7,9 +7,9 @@ import { editMember } from "./edit_member.ts";
|
||||
* @param channelId id of channel to move user to (if they are connected to voice)
|
||||
*/
|
||||
export function moveMember(
|
||||
guildId: string,
|
||||
memberId: string,
|
||||
channelId: string,
|
||||
guildId: bigint,
|
||||
memberId: bigint,
|
||||
channelId: bigint,
|
||||
) {
|
||||
return editMember(guildId, memberId, { channelId });
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import { camelKeysToSnakeCase } from "../../util/utils.ts";
|
||||
* By default, prune will not remove users with roles. You can optionally include specific roles in your prune by providing the roles (resolved to include_roles internally) parameter. Any inactive user that has a subset of the provided role(s) will be included in the prune and users with additional roles will not.
|
||||
*/
|
||||
export async function pruneMembers(
|
||||
guildId: string,
|
||||
guildId: bigint,
|
||||
options: BeginGuildPrune,
|
||||
) {
|
||||
if (options.days && options.days < 1) throw new Error(Errors.PRUNE_MIN_DAYS);
|
||||
|
||||
@@ -13,7 +13,7 @@ import { endpoints } from "../../util/constants.ts";
|
||||
* @param query Query string to match username(s) and nickname(s) against
|
||||
*/
|
||||
export async function searchMembers(
|
||||
guildId: string,
|
||||
guildId: bigint,
|
||||
query: string,
|
||||
options?: Omit<SearchGuildMembers, "query"> & { cache?: boolean },
|
||||
) {
|
||||
@@ -45,7 +45,7 @@ export async function searchMembers(
|
||||
return discordenoMember;
|
||||
}));
|
||||
|
||||
return new Collection<string, DiscordenoMember>(
|
||||
return new Collection<bigint, DiscordenoMember>(
|
||||
members.map((member) => [member.id, member]),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import { sendMessage } from "../messages/send_message.ts";
|
||||
|
||||
/** Send a message to a users DM. Note: this takes 2 API calls. 1 is to fetch the users dm channel. 2 is to send a message to that channel. */
|
||||
export async function sendDirectMessage(
|
||||
memberId: string,
|
||||
memberId: bigint,
|
||||
content: string | CreateMessage,
|
||||
) {
|
||||
let dmChannel = await cacheHandlers.get("channels", memberId);
|
||||
|
||||
@@ -3,7 +3,7 @@ import { endpoints } from "../../util/constants.ts";
|
||||
import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
||||
|
||||
/** Remove the ban for a user. Requires BAN_MEMBERS permission */
|
||||
export async function unban(guildId: string, id: string) {
|
||||
export async function unban(guildId: bigint, id: bigint) {
|
||||
await requireBotGuildPermissions(guildId, ["BAN_MEMBERS"]);
|
||||
|
||||
return await rest.runMethod<undefined>(
|
||||
|
||||
@@ -4,8 +4,8 @@ import { requireBotChannelPermissions } from "../../util/permissions.ts";
|
||||
|
||||
/** Create a reaction for the message. Reaction takes the form of **name:id** for custom guild emoji, or Unicode characters. Requires READ_MESSAGE_HISTORY and ADD_REACTIONS */
|
||||
export async function addReaction(
|
||||
channelId: string,
|
||||
messageId: string,
|
||||
channelId: bigint,
|
||||
messageId: bigint,
|
||||
reaction: string,
|
||||
) {
|
||||
await requireBotChannelPermissions(channelId, [
|
||||
|
||||
@@ -3,8 +3,8 @@ import { addReaction } from "./add_reaction.ts";
|
||||
|
||||
/** Adds multiple reactions to a message. If `ordered` is true(default is false), it will add the reactions one at a time in the order provided. Note: Reaction takes the form of **name:id** for custom guild emoji, or Unicode characters. Requires READ_MESSAGE_HISTORY and ADD_REACTIONS */
|
||||
export async function addReactions(
|
||||
channelId: string,
|
||||
messageId: string,
|
||||
channelId: bigint,
|
||||
messageId: bigint,
|
||||
reactions: string[],
|
||||
ordered = false,
|
||||
) {
|
||||
|
||||
@@ -7,14 +7,14 @@ import { delay } from "../../util/utils.ts";
|
||||
|
||||
/** Delete a message with the channel id and message id only. */
|
||||
export async function deleteMessage(
|
||||
channelId: string,
|
||||
messageId: string,
|
||||
channelId: bigint,
|
||||
messageId: bigint,
|
||||
reason?: string,
|
||||
delayMilliseconds = 0,
|
||||
) {
|
||||
const message = await cacheHandlers.get("messages", messageId);
|
||||
|
||||
if (message && message.author.id !== botId) {
|
||||
if (message && message.authorId !== botId) {
|
||||
await requireBotChannelPermissions(message.channelId, ["MANAGE_MESSAGES"]);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import { requireBotChannelPermissions } from "../../util/permissions.ts";
|
||||
|
||||
/** Delete messages from the channel. 2-100. Requires the MANAGE_MESSAGES permission */
|
||||
export async function deleteMessages(
|
||||
channelId: string,
|
||||
channelId: bigint,
|
||||
ids: string[],
|
||||
reason?: string,
|
||||
) {
|
||||
|
||||
@@ -14,7 +14,7 @@ export async function editMessage(
|
||||
message: DiscordenoMessage,
|
||||
content: string | EditMessage,
|
||||
) {
|
||||
if (message.author.id !== botId) {
|
||||
if (message.authorId !== botId) {
|
||||
throw "You can only edit a message that was sent by the bot.";
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import { endpoints } from "../../util/constants.ts";
|
||||
import { requireBotChannelPermissions } from "../../util/permissions.ts";
|
||||
|
||||
/** Fetch a single message from the server. Requires VIEW_CHANNEL and READ_MESSAGE_HISTORY */
|
||||
export async function getMessage(channelId: string, id: string) {
|
||||
export async function getMessage(channelId: bigint, id: bigint) {
|
||||
if (await cacheHandlers.has("channels", channelId)) {
|
||||
await requireBotChannelPermissions(channelId, [
|
||||
"VIEW_CHANNEL",
|
||||
|
||||
@@ -12,7 +12,7 @@ import { requireBotChannelPermissions } from "../../util/permissions.ts";
|
||||
|
||||
/** Fetches between 2-100 messages. Requires VIEW_CHANNEL and READ_MESSAGE_HISTORY */
|
||||
export async function getMessages(
|
||||
channelId: string,
|
||||
channelId: bigint,
|
||||
options?:
|
||||
| GetMessagesAfter
|
||||
| GetMessagesBefore
|
||||
|
||||
@@ -6,8 +6,8 @@ import { endpoints } from "../../util/constants.ts";
|
||||
|
||||
/** Get a list of users that reacted with this emoji. */
|
||||
export async function getReactions(
|
||||
channelId: string,
|
||||
messageId: string,
|
||||
channelId: bigint,
|
||||
messageId: bigint,
|
||||
reaction: string,
|
||||
options?: GetReactions,
|
||||
) {
|
||||
|
||||
@@ -3,7 +3,7 @@ import { endpoints } from "../../util/constants.ts";
|
||||
import { requireBotChannelPermissions } from "../../util/permissions.ts";
|
||||
|
||||
/** Pin a message in a channel. Requires MANAGE_MESSAGES. Max pins allowed in a channel = 50. */
|
||||
export async function pin(channelId: string, messageId: string) {
|
||||
export async function pin(channelId: bigint, messageId: bigint) {
|
||||
await requireBotChannelPermissions(channelId, ["MANAGE_MESSAGES"]);
|
||||
|
||||
return await rest.runMethod<undefined>(
|
||||
|
||||
@@ -4,7 +4,7 @@ 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) {
|
||||
export async function publishMessage(channelId: bigint, messageId: bigint) {
|
||||
const data = await rest.runMethod<Message>(
|
||||
"post",
|
||||
endpoints.CHANNEL_MESSAGE_CROSSPOST(channelId, messageId),
|
||||
|
||||
@@ -3,7 +3,7 @@ import { endpoints } from "../../util/constants.ts";
|
||||
import { requireBotChannelPermissions } from "../../util/permissions.ts";
|
||||
|
||||
/** Removes all reactions for all emojis on this message. */
|
||||
export async function removeAllReactions(channelId: string, messageId: string) {
|
||||
export async function removeAllReactions(channelId: bigint, messageId: bigint) {
|
||||
await requireBotChannelPermissions(channelId, ["MANAGE_MESSAGES"]);
|
||||
|
||||
return await rest.runMethod<undefined>(
|
||||
|
||||
@@ -4,10 +4,10 @@ import { requireBotChannelPermissions } from "../../util/permissions.ts";
|
||||
|
||||
/** Removes a reaction from the given user on this message, defaults to bot. Reaction takes the form of **name:id** for custom guild emoji, or Unicode characters. */
|
||||
export async function removeReaction(
|
||||
channelId: string,
|
||||
messageId: string,
|
||||
channelId: bigint,
|
||||
messageId: bigint,
|
||||
reaction: string,
|
||||
options?: { userId?: string },
|
||||
options?: { userId?: bigint },
|
||||
) {
|
||||
if (options?.userId) {
|
||||
await requireBotChannelPermissions(channelId, ["MANAGE_MESSAGES"]);
|
||||
|
||||
@@ -4,8 +4,8 @@ import { requireBotChannelPermissions } from "../../util/permissions.ts";
|
||||
|
||||
/** Removes all reactions for a single emoji on this message. Reaction takes the form of **name:id** for custom guild emoji, or Unicode characters. */
|
||||
export async function removeReactionEmoji(
|
||||
channelId: string,
|
||||
messageId: string,
|
||||
channelId: bigint,
|
||||
messageId: bigint,
|
||||
reaction: string,
|
||||
) {
|
||||
await requireBotChannelPermissions(channelId, ["MANAGE_MESSAGES"]);
|
||||
|
||||
@@ -17,7 +17,7 @@ import { isButton } from "../type_guards/is_button.ts";
|
||||
|
||||
/** Send a message to the channel. Requires SEND_MESSAGES permission. */
|
||||
export async function sendMessage(
|
||||
channelId: string,
|
||||
channelId: bigint,
|
||||
content: string | CreateMessage,
|
||||
) {
|
||||
if (typeof content === "string") content = { content };
|
||||
|
||||
@@ -4,8 +4,8 @@ import { requireBotChannelPermissions } from "../../util/permissions.ts";
|
||||
|
||||
/** Unpin a message in a channel. Requires MANAGE_MESSAGES. */
|
||||
export async function unpin(
|
||||
channelId: string,
|
||||
messageId: string,
|
||||
channelId: bigint,
|
||||
messageId: bigint,
|
||||
): Promise<undefined> {
|
||||
await requireBotChannelPermissions(channelId, ["MANAGE_MESSAGES"]);
|
||||
|
||||
|
||||
@@ -3,6 +3,6 @@ import { User } from "../../types/users/user.ts";
|
||||
import { endpoints } from "../../util/constants.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) {
|
||||
export async function getUser(userId: bigint) {
|
||||
return await rest.runMethod<User>("get", endpoints.USER(userId));
|
||||
}
|
||||
|
||||
@@ -9,9 +9,9 @@ import {
|
||||
|
||||
/** Add a role to the member */
|
||||
export async function addRole(
|
||||
guildId: string,
|
||||
memberId: string,
|
||||
roleId: string,
|
||||
guildId: bigint,
|
||||
memberId: bigint,
|
||||
roleId: bigint,
|
||||
reason?: string,
|
||||
) {
|
||||
const isHigherRolePosition = await isHigherPosition(
|
||||
|
||||
@@ -11,7 +11,7 @@ import {
|
||||
|
||||
/** Create a new role for the guild. Requires the MANAGE_ROLES permission. */
|
||||
export async function createRole(
|
||||
guildId: string,
|
||||
guildId: bigint,
|
||||
options: CreateGuildRole,
|
||||
reason?: string,
|
||||
) {
|
||||
|
||||
@@ -3,7 +3,7 @@ import { endpoints } from "../../util/constants.ts";
|
||||
import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
||||
|
||||
/** Delete a guild role. Requires the MANAGE_ROLES permission. */
|
||||
export async function deleteRole(guildId: string, id: string) {
|
||||
export async function deleteRole(guildId: bigint, id: bigint) {
|
||||
await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]);
|
||||
|
||||
return await rest.runMethod<undefined>(
|
||||
|
||||
@@ -9,8 +9,8 @@ import {
|
||||
|
||||
/** Edit a guild role. Requires the MANAGE_ROLES permission. */
|
||||
export async function editRole(
|
||||
guildId: string,
|
||||
id: string,
|
||||
guildId: bigint,
|
||||
id: bigint,
|
||||
options: CreateGuildRole,
|
||||
) {
|
||||
await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]);
|
||||
|
||||
@@ -8,7 +8,7 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
||||
*
|
||||
* ⚠️ **If you need this, you are probably doing something wrong. This is not intended for use. Your roles will be cached in your guild.**
|
||||
*/
|
||||
export async function getRoles(guildId: string) {
|
||||
export async function getRoles(guildId: bigint) {
|
||||
await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]);
|
||||
|
||||
const result = await rest.runMethod<Role[]>(
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user