editBotProfile

This commit is contained in:
Skillz
2020-11-12 08:32:32 -05:00
parent 2530054b65
commit 1fa5d08370
3 changed files with 38 additions and 1 deletions
+1
View File
@@ -96,6 +96,7 @@ export const endpoints = {
// User endpoints
USER: (id: string) => `${baseEndpoints.BASE_URL}/users/${id}`,
USER_BOT: `${baseEndpoints.BASE_URL}/users/@me`,
USER_AVATAR: (id: string, icon: string) =>
`${baseEndpoints.CDN_URL}/avatars/${id}/${icon}`,
USER_DEFAULT_AVATAR: (icon: number) =>
+33 -1
View File
@@ -15,6 +15,7 @@ import {
higherRolePosition,
highestRole,
} from "../utils/permissions.ts";
import { urlToBase64 } from "../utils/utils.ts";
import { sendMessage } from "./channel.ts";
/** 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.
* @param guildID the id of the guild which the channel exists in
* @param memberID the id of the member to move.
@@ -197,3 +198,34 @@ export function moveMember(
) {
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,
},
);
}
+4
View File
@@ -33,4 +33,8 @@ export enum Errors {
INVALID_WEBHOOK_OPTIONS = "INVALID_WEBHOOK_OPTIONS",
CHANNEL_NOT_FOUND = "CHANNEL_NOT_FOUND",
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",
}