mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-15 11:03:30 +01:00
fix(GuildEmojiManager): throw an error if image resolving fails (#3934)
* fix(GuildEmojiManager): throw an error if image resolving fails * refactor(GuildEmojiManager): remove redundant if branch
This commit is contained in:
@@ -50,29 +50,28 @@ class GuildEmojiManager extends BaseManager {
|
|||||||
* .then(emoji => console.log(`Created new emoji with name ${emoji.name}!`))
|
* .then(emoji => console.log(`Created new emoji with name ${emoji.name}!`))
|
||||||
* .catch(console.error);
|
* .catch(console.error);
|
||||||
*/
|
*/
|
||||||
create(attachment, name, { roles, reason } = {}) {
|
async create(attachment, name, { roles, reason } = {}) {
|
||||||
if (typeof attachment === 'string' && attachment.startsWith('data:')) {
|
attachment = await DataResolver.resolveImage(attachment);
|
||||||
const data = { image: attachment, name };
|
if (!attachment) throw new TypeError('REQ_RESOURCE_TYPE');
|
||||||
if (roles) {
|
|
||||||
data.roles = [];
|
|
||||||
for (let role of roles instanceof Collection ? roles.values() : roles) {
|
|
||||||
role = this.guild.roles.resolve(role);
|
|
||||||
if (!role) {
|
|
||||||
return Promise.reject(
|
|
||||||
new TypeError('INVALID_TYPE', 'options.roles', 'Array or Collection of Roles or Snowflakes', true),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
data.roles.push(role.id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.client.api
|
const data = { image: attachment, name };
|
||||||
.guilds(this.guild.id)
|
if (roles) {
|
||||||
.emojis.post({ data, reason })
|
data.roles = [];
|
||||||
.then(emoji => this.client.actions.GuildEmojiCreate.handle(this.guild, emoji).emoji);
|
for (let role of roles instanceof Collection ? roles.values() : roles) {
|
||||||
|
role = this.guild.roles.resolve(role);
|
||||||
|
if (!role) {
|
||||||
|
return Promise.reject(
|
||||||
|
new TypeError('INVALID_TYPE', 'options.roles', 'Array or Collection of Roles or Snowflakes', true),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
data.roles.push(role.id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return DataResolver.resolveImage(attachment).then(image => this.create(image, name, { roles, reason }));
|
return this.client.api
|
||||||
|
.guilds(this.guild.id)
|
||||||
|
.emojis.post({ data, reason })
|
||||||
|
.then(emoji => this.client.actions.GuildEmojiCreate.handle(this.guild, emoji).emoji);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user