feat: editProfile()

This commit is contained in:
socram03 2022-07-17 15:00:43 -04:00
parent 425a80eee3
commit 7ac20b2a27
2 changed files with 12 additions and 1 deletions

View File

@ -3,7 +3,8 @@ import type { Snowflake } from "./Snowflake.ts";
// cdn endpoints // cdn endpoints
export * from "./Cdn.ts"; export * from "./Cdn.ts";
export function USER(userId: Snowflake): string { export function USER(userId?: Snowflake): string {
if (!userId) return "/users/@me";
return `/users/${userId}`; return `/users/${userId}`;
} }

View File

@ -28,6 +28,7 @@ import {
} from "../discordeno/mod.ts"; } from "../discordeno/mod.ts";
import User from "./structures/User.ts"; import User from "./structures/User.ts";
import { urlToBase64 } from "./util/urlToBase64.ts";
import * as Routes from "./Routes.ts"; import * as Routes from "./Routes.ts";
import * as Actions from "./Actions.ts"; import * as Actions from "./Actions.ts";
@ -200,6 +201,15 @@ export class Session extends EventEmitter {
return super.emit(event, ...params); return super.emit(event, ...params);
} }
async editProfile(nick?: string, avatarURL?: string | null ): Promise<User> {
const avatar = avatarURL ? await urlToBase64(avatarURL) : avatarURL;
const user = await this.rest.runMethod<DiscordUser>(this.rest, 'PATCH', Routes.USER(), {
username: nick,
avatar: avatar
});
return new User(this, user);
}
/** /**
* Edit bot's status * Edit bot's status
* tip: execute this on the ready event if possible * tip: execute this on the ready event if possible