mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
fix(GuildEmojiManager): check for guild in methods that use it (#4886)
This commit is contained in:
@@ -103,6 +103,8 @@ const Messages = {
|
|||||||
FETCH_GROUP_DM_CHANNEL: "Bots don't have access to Group DM Channels and cannot fetch them",
|
FETCH_GROUP_DM_CHANNEL: "Bots don't have access to Group DM Channels and cannot fetch them",
|
||||||
|
|
||||||
MEMBER_FETCH_NONCE_LENGTH: 'Nonce length must not exceed 32 characters.',
|
MEMBER_FETCH_NONCE_LENGTH: 'Nonce length must not exceed 32 characters.',
|
||||||
|
|
||||||
|
GUILDEMOJIMANAGER_NO_GUILD: 'Method cannot be called from a Client instance.',
|
||||||
};
|
};
|
||||||
|
|
||||||
for (const [name, message] of Object.entries(Messages)) register(name, message);
|
for (const [name, message] of Object.entries(Messages)) register(name, message);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const BaseManager = require('./BaseManager');
|
const BaseManager = require('./BaseManager');
|
||||||
const { TypeError } = require('../errors');
|
const { Error, TypeError } = require('../errors');
|
||||||
const GuildEmoji = require('../structures/GuildEmoji');
|
const GuildEmoji = require('../structures/GuildEmoji');
|
||||||
const ReactionEmoji = require('../structures/ReactionEmoji');
|
const ReactionEmoji = require('../structures/ReactionEmoji');
|
||||||
const Collection = require('../util/Collection');
|
const Collection = require('../util/Collection');
|
||||||
@@ -16,9 +16,9 @@ class GuildEmojiManager extends BaseManager {
|
|||||||
super(guild.client, iterable, GuildEmoji);
|
super(guild.client, iterable, GuildEmoji);
|
||||||
/**
|
/**
|
||||||
* The guild this manager belongs to
|
* The guild this manager belongs to
|
||||||
* @type {Guild}
|
* @type {?Guild}
|
||||||
*/
|
*/
|
||||||
this.guild = guild;
|
this.guild = 'name' in guild ? guild : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -28,6 +28,7 @@ class GuildEmojiManager extends BaseManager {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
add(data, cache) {
|
add(data, cache) {
|
||||||
|
if (!this.guild) throw new Error('GUILDEMOJIMANAGER_NO_GUILD');
|
||||||
return super.add(data, cache, { extras: [this.guild] });
|
return super.add(data, cache, { extras: [this.guild] });
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,6 +52,7 @@ class GuildEmojiManager extends BaseManager {
|
|||||||
* .catch(console.error);
|
* .catch(console.error);
|
||||||
*/
|
*/
|
||||||
async create(attachment, name, { roles, reason } = {}) {
|
async create(attachment, name, { roles, reason } = {}) {
|
||||||
|
if (!this.guild) throw new Error('GUILDEMOJIMANAGER_NO_GUILD');
|
||||||
attachment = await DataResolver.resolveImage(attachment);
|
attachment = await DataResolver.resolveImage(attachment);
|
||||||
if (!attachment) throw new TypeError('REQ_RESOURCE_TYPE');
|
if (!attachment) throw new TypeError('REQ_RESOURCE_TYPE');
|
||||||
|
|
||||||
|
|||||||
2
typings/index.d.ts
vendored
2
typings/index.d.ts
vendored
@@ -1917,7 +1917,7 @@ declare module 'discord.js' {
|
|||||||
|
|
||||||
export class GuildEmojiManager extends BaseManager<Snowflake, GuildEmoji, EmojiResolvable> {
|
export class GuildEmojiManager extends BaseManager<Snowflake, GuildEmoji, EmojiResolvable> {
|
||||||
constructor(guild: Guild, iterable?: Iterable<any>);
|
constructor(guild: Guild, iterable?: Iterable<any>);
|
||||||
public guild: Guild;
|
public guild: Guild | null;
|
||||||
public create(
|
public create(
|
||||||
attachment: BufferResolvable | Base64Resolvable,
|
attachment: BufferResolvable | Base64Resolvable,
|
||||||
name: string,
|
name: string,
|
||||||
|
|||||||
Reference in New Issue
Block a user