mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-15 02:53:31 +01:00
Add role support to emoji creation (#1141)
* add role support to emojis * specify types
This commit is contained in:
committed by
Schuyler Cebulskie
parent
18729b25c7
commit
565c640bc6
@@ -559,9 +559,11 @@ class RESTMethods {
|
|||||||
.then(data => data.pruned);
|
.then(data => data.pruned);
|
||||||
}
|
}
|
||||||
|
|
||||||
createEmoji(guild, image, name) {
|
createEmoji(guild, image, name, roles) {
|
||||||
return this.rest.makeRequest('post', `${Constants.Endpoints.guildEmojis(guild.id)}`, true, { name, image })
|
const data = { image, name };
|
||||||
.then(data => this.client.actions.GuildEmojiCreate.handle(data, guild).emoji);
|
if (roles) data.roles = roles.map(r => r.id ? r.id : r);
|
||||||
|
return this.rest.makeRequest('post', `${Constants.Endpoints.guildEmojis(guild.id)}`, true, data)
|
||||||
|
.then(emoji => this.client.actions.GuildEmojiCreate.handle(emoji, guild).emoji);
|
||||||
}
|
}
|
||||||
|
|
||||||
updateEmoji(emoji, _data) {
|
updateEmoji(emoji, _data) {
|
||||||
|
|||||||
@@ -682,6 +682,7 @@ class Guild {
|
|||||||
* Creates a new custom emoji in the guild.
|
* Creates a new custom emoji in the guild.
|
||||||
* @param {BufferResolvable|Base64Resolvable} attachment The image for the emoji.
|
* @param {BufferResolvable|Base64Resolvable} attachment The image for the emoji.
|
||||||
* @param {string} name The name for the emoji.
|
* @param {string} name The name for the emoji.
|
||||||
|
* @param {Collection<Role>|Role[]} [roles] Roles to limit the emoji to
|
||||||
* @returns {Promise<Emoji>} The created emoji.
|
* @returns {Promise<Emoji>} The created emoji.
|
||||||
* @example
|
* @example
|
||||||
* // create a new emoji from a url
|
* // create a new emoji from a url
|
||||||
@@ -694,13 +695,13 @@ class Guild {
|
|||||||
* .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);
|
||||||
*/
|
*/
|
||||||
createEmoji(attachment, name) {
|
createEmoji(attachment, name, roles) {
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
if (typeof attachment === 'string' && attachment.startsWith('data:')) {
|
if (typeof attachment === 'string' && attachment.startsWith('data:')) {
|
||||||
resolve(this.client.rest.methods.createEmoji(this, attachment, name));
|
resolve(this.client.rest.methods.createEmoji(this, attachment, name, roles));
|
||||||
} else {
|
} else {
|
||||||
this.client.resolver.resolveBuffer(attachment).then(data =>
|
this.client.resolver.resolveBuffer(attachment).then(data =>
|
||||||
resolve(this.client.rest.methods.createEmoji(this, data, name))
|
resolve(this.client.rest.methods.createEmoji(this, data, name, roles))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user