mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 11:28:15 +00:00
editBotProfile
This commit is contained in:
@@ -96,6 +96,7 @@ export const endpoints = {
|
|||||||
|
|
||||||
// User endpoints
|
// User endpoints
|
||||||
USER: (id: string) => `${baseEndpoints.BASE_URL}/users/${id}`,
|
USER: (id: string) => `${baseEndpoints.BASE_URL}/users/${id}`,
|
||||||
|
USER_BOT: `${baseEndpoints.BASE_URL}/users/@me`,
|
||||||
USER_AVATAR: (id: string, icon: string) =>
|
USER_AVATAR: (id: string, icon: string) =>
|
||||||
`${baseEndpoints.CDN_URL}/avatars/${id}/${icon}`,
|
`${baseEndpoints.CDN_URL}/avatars/${id}/${icon}`,
|
||||||
USER_DEFAULT_AVATAR: (icon: number) =>
|
USER_DEFAULT_AVATAR: (icon: number) =>
|
||||||
|
|||||||
+33
-1
@@ -15,6 +15,7 @@ import {
|
|||||||
higherRolePosition,
|
higherRolePosition,
|
||||||
highestRole,
|
highestRole,
|
||||||
} from "../utils/permissions.ts";
|
} from "../utils/permissions.ts";
|
||||||
|
import { urlToBase64 } from "../utils/utils.ts";
|
||||||
import { sendMessage } from "./channel.ts";
|
import { sendMessage } from "./channel.ts";
|
||||||
|
|
||||||
/** The users custom avatar or the default avatar if you don't have a member object. */
|
/** The users custom avatar or the default avatar if you don't have a member object. */
|
||||||
@@ -184,7 +185,7 @@ export function editMember(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Move a member from a voice channel to another.
|
* Move a member from a voice channel to another.
|
||||||
* @param guildID the id of the guild which the channel exists in
|
* @param guildID the id of the guild which the channel exists in
|
||||||
* @param memberID the id of the member to move.
|
* @param memberID the id of the member to move.
|
||||||
@@ -197,3 +198,34 @@ export function moveMember(
|
|||||||
) {
|
) {
|
||||||
return editMember(guildID, memberID, { channel_id: channelID });
|
return editMember(guildID, memberID, { channel_id: channelID });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Modifies the bot's username or avatar.
|
||||||
|
* NOTE: username: if changed may cause the bot's discriminator to be randomized.
|
||||||
|
*/
|
||||||
|
export function editBotProfile(username?: string, avatarURL?: string) {
|
||||||
|
// Nothing was edited
|
||||||
|
if (!username && !avatarURL) return;
|
||||||
|
// Check username requirements if username was provided
|
||||||
|
if (username) {
|
||||||
|
if (username.length > 32) {
|
||||||
|
throw new Error(Errors.USERNAME_MAX_LENGTH);
|
||||||
|
}
|
||||||
|
if (username.length < 2) {
|
||||||
|
throw new Error(Errors.USERNAME_MIN_LENGTH);
|
||||||
|
}
|
||||||
|
if (["@", "#", ":", "```"].some((char) => username.includes(char))) {
|
||||||
|
throw new Error(Errors.USERNAME_INVALID_CHARACTER);
|
||||||
|
}
|
||||||
|
if (["discordtag", "everyone", "here"].includes(username)) {
|
||||||
|
throw new Error(Errors.USERNAME_INVALID_USERNAME);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
RequestManager.patch(
|
||||||
|
endpoints.USER_BOT,
|
||||||
|
{
|
||||||
|
username: username?.trim(),
|
||||||
|
avatar: avatarURL ? urlToBase64(avatarURL) : undefined,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
@@ -33,4 +33,8 @@ export enum Errors {
|
|||||||
INVALID_WEBHOOK_OPTIONS = "INVALID_WEBHOOK_OPTIONS",
|
INVALID_WEBHOOK_OPTIONS = "INVALID_WEBHOOK_OPTIONS",
|
||||||
CHANNEL_NOT_FOUND = "CHANNEL_NOT_FOUND",
|
CHANNEL_NOT_FOUND = "CHANNEL_NOT_FOUND",
|
||||||
CHANNEL_NOT_TEXT_BASED = "CHANNEL_NOT_TEXT_BASED",
|
CHANNEL_NOT_TEXT_BASED = "CHANNEL_NOT_TEXT_BASED",
|
||||||
|
USERNAME_MAX_LENGTH = "USERNAME_MAX_LENGTH",
|
||||||
|
USERNAME_MIN_LENGTH = "USERNAME_MIN_LENGTH",
|
||||||
|
USERNAME_INVALID_CHARACTER = "USERNAME_INVALID_CHARACTER",
|
||||||
|
USERNAME_INVALID_USERNAME = "USERNAME_INVALID_USERNAME",
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user