Skip to content

Commit 728b3f9

Browse files
authored
fix(GuildEmojiManager): check for guild in methods that use it (#4886)
1 parent 7db6978 commit 728b3f9

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

src/errors/Messages.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ const Messages = {
103103
FETCH_GROUP_DM_CHANNEL: "Bots don't have access to Group DM Channels and cannot fetch them",
104104

105105
MEMBER_FETCH_NONCE_LENGTH: 'Nonce length must not exceed 32 characters.',
106+
107+
GUILDEMOJIMANAGER_NO_GUILD: 'Method cannot be called from a Client instance.',
106108
};
107109

108110
for (const [name, message] of Object.entries(Messages)) register(name, message);

src/managers/GuildEmojiManager.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
const BaseManager = require('./BaseManager');
4-
const { TypeError } = require('../errors');
4+
const { Error, TypeError } = require('../errors');
55
const GuildEmoji = require('../structures/GuildEmoji');
66
const ReactionEmoji = require('../structures/ReactionEmoji');
77
const Collection = require('../util/Collection');
@@ -16,9 +16,9 @@ class GuildEmojiManager extends BaseManager {
1616
super(guild.client, iterable, GuildEmoji);
1717
/**
1818
* The guild this manager belongs to
19-
* @type {Guild}
19+
* @type {?Guild}
2020
*/
21-
this.guild = guild;
21+
this.guild = 'name' in guild ? guild : null;
2222
}
2323

2424
/**
@@ -28,6 +28,7 @@ class GuildEmojiManager extends BaseManager {
2828
*/
2929

3030
add(data, cache) {
31+
if (!this.guild) throw new Error('GUILDEMOJIMANAGER_NO_GUILD');
3132
return super.add(data, cache, { extras: [this.guild] });
3233
}
3334

@@ -51,6 +52,7 @@ class GuildEmojiManager extends BaseManager {
5152
* .catch(console.error);
5253
*/
5354
async create(attachment, name, { roles, reason } = {}) {
55+
if (!this.guild) throw new Error('GUILDEMOJIMANAGER_NO_GUILD');
5456
attachment = await DataResolver.resolveImage(attachment);
5557
if (!attachment) throw new TypeError('REQ_RESOURCE_TYPE');
5658

typings/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1917,7 +1917,7 @@ declare module 'discord.js' {
19171917

19181918
export class GuildEmojiManager extends BaseManager<Snowflake, GuildEmoji, EmojiResolvable> {
19191919
constructor(guild: Guild, iterable?: Iterable<any>);
1920-
public guild: Guild;
1920+
public guild: Guild | null;
19211921
public create(
19221922
attachment: BufferResolvable | Base64Resolvable,
19231923
name: string,

0 commit comments

Comments
 (0)