From a69988b6531b821c9a1ce8376e00c3d8f0e5d79c Mon Sep 17 00:00:00 2001 From: ayntee Date: Sat, 26 Dec 2020 10:34:15 +0400 Subject: [PATCH] ci: add Emoji#id check --- src/structures/emoji.ts | 8 +++++--- src/types/emoji.ts | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/structures/emoji.ts b/src/structures/emoji.ts index 7e78e1e..3ac4bba 100644 --- a/src/structures/emoji.ts +++ b/src/structures/emoji.ts @@ -7,8 +7,8 @@ import { Role } from './role.ts' import { User } from './user.ts' export class Emoji extends Base { - id: string - name: string + id: string | null + name: string | null roles?: string[] user?: User guild?: Guild @@ -41,8 +41,9 @@ export class Emoji extends Base { /** Modify the given emoji. Requires the MANAGE_EMOJIS permission. Returns the updated emoji object on success. Fires a Guild Emojis Update Gateway event. */ async edit(data: ModifyGuildEmojiParams): Promise { + if (this.id === null) throw new Error("Emoji ID is not valid."); if (this.guild === undefined) throw new Error('Guild is undefined') - const res = await this.client.rest.patch(EMOJI(this.guild.id, this.id), { + const res = await this.client.rest.patch(EMOJI(this.guild.id, this.id!), { ...data, roles: data.roles?.map((role) => role.id) }) @@ -51,6 +52,7 @@ export class Emoji extends Base { /** Delete the given emoji. Requires the MANAGE_EMOJIS permission. Returns `true` on success. Fires a Guild Emojis Update Gateway event. */ async delete(): Promise { + if (this.id === null) return false; if (this.guild === undefined) return false await this.client.rest.delete(EMOJI(this.guild.id, this.id)) return true diff --git a/src/types/emoji.ts b/src/types/emoji.ts index ab0216c..c50f238 100644 --- a/src/types/emoji.ts +++ b/src/types/emoji.ts @@ -1,8 +1,8 @@ import { UserPayload } from './user.ts' export interface EmojiPayload { - id: string - name: string + id: string | null + name: string | null roles?: string[] user?: UserPayload require_colons?: boolean