mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-17 20:13:30 +01:00
Simplified image resolving and used an options object when creating webhooks (#1843)
This commit is contained in:
@@ -341,10 +341,10 @@ class ClientUser extends User {
|
|||||||
return undefined;
|
return undefined;
|
||||||
}, reject)
|
}, reject)
|
||||||
);
|
);
|
||||||
} else {
|
|
||||||
return this.client.resolver.resolveFile(icon)
|
|
||||||
.then(data => this.createGuild(name, { region, icon: this.client.resolver.resolveBase64(data) || null }));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return this.client.resolver.resolveImage(icon)
|
||||||
|
.then(data => this.createGuild(name, { region, icon: data || null }));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1044,11 +1044,8 @@ class Guild extends Base {
|
|||||||
.then(emoji => this.client.actions.GuildEmojiCreate.handle(this, emoji).emoji);
|
.then(emoji => this.client.actions.GuildEmojiCreate.handle(this, emoji).emoji);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.client.resolver.resolveFile(attachment)
|
return this.client.resolver.resolveImage(attachment)
|
||||||
.then(data => {
|
.then(image => this.createEmoji(image, name, { roles, reason }));
|
||||||
const dataURI = this.client.resolver.resolveBase64(data);
|
|
||||||
return this.createEmoji(dataURI, name, { roles, reason });
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -51,23 +51,23 @@ class TextChannel extends GuildChannel {
|
|||||||
/**
|
/**
|
||||||
* Create a webhook for the channel.
|
* Create a webhook for the channel.
|
||||||
* @param {string} name The name of the webhook
|
* @param {string} name The name of the webhook
|
||||||
* @param {BufferResolvable|Base64Resolvable} avatar The avatar for the webhook
|
* @param {Object} [options] Options for creating the webhook
|
||||||
* @param {string} [reason] Reason for creating this webhook
|
* @param {BufferResolvable|Base64Resolvable} [options.avatar] Avatar for the webhook
|
||||||
|
* @param {string} [options.reason] Reason for creating the webhook
|
||||||
* @returns {Promise<Webhook>} webhook The created webhook
|
* @returns {Promise<Webhook>} webhook The created webhook
|
||||||
* @example
|
* @example
|
||||||
* channel.createWebhook('Snek', 'https://i.imgur.com/mI8XcpG.jpg')
|
* channel.createWebhook('Snek', 'https://i.imgur.com/mI8XcpG.jpg')
|
||||||
* .then(webhook => console.log(`Created webhook ${webhook}`))
|
* .then(webhook => console.log(`Created webhook ${webhook}`))
|
||||||
* .catch(console.error)
|
* .catch(console.error)
|
||||||
*/
|
*/
|
||||||
createWebhook(name, avatar, reason) {
|
createWebhook(name, { avatar, reason } = {}) {
|
||||||
if (typeof avatar === 'string' && avatar.startsWith('data:')) {
|
if (typeof avatar === 'string' && avatar.startsWith('data:')) {
|
||||||
return this.client.api.channels[this.id].webhooks.post({ data: {
|
return this.client.api.channels[this.id].webhooks.post({ data: {
|
||||||
name, avatar,
|
name, avatar,
|
||||||
}, reason }).then(data => new Webhook(this.client, data));
|
}, reason }).then(data => new Webhook(this.client, data));
|
||||||
} else {
|
|
||||||
return this.client.resolver.resolveFile(avatar).then(data =>
|
|
||||||
this.createWebhook(name, this.client.resolver.resolveBase64(data) || null));
|
|
||||||
}
|
}
|
||||||
|
return this.client.resolver.resolveImage(avatar).then(image =>
|
||||||
|
this.createWebhook(name, { avatar: image, reason }));
|
||||||
}
|
}
|
||||||
|
|
||||||
// These are here only for documentation purposes - they are implemented by TextBasedChannel
|
// These are here only for documentation purposes - they are implemented by TextBasedChannel
|
||||||
|
|||||||
@@ -254,10 +254,9 @@ class Webhook {
|
|||||||
*/
|
*/
|
||||||
edit({ name = this.name, avatar }, reason) {
|
edit({ name = this.name, avatar }, reason) {
|
||||||
if (avatar && (typeof avatar === 'string' && !avatar.startsWith('data:'))) {
|
if (avatar && (typeof avatar === 'string' && !avatar.startsWith('data:'))) {
|
||||||
return this.client.resolver.resolveFile(avatar).then(file => {
|
return this.client.resolver.resolveImage(avatar).then(image =>
|
||||||
const dataURI = this.client.resolver.resolveBase64(file);
|
this.edit({ name, avatar: image }, reason)
|
||||||
return this.edit({ name, avatar: dataURI }, reason);
|
);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
return this.client.api.webhooks(this.id, this.token).patch({
|
return this.client.api.webhooks(this.id, this.token).patch({
|
||||||
data: { name, avatar },
|
data: { name, avatar },
|
||||||
|
|||||||
Reference in New Issue
Block a user