add guild emoji methods (#742)

* add guild emoji methods

* run docs

* crawl pointed out some things about the docs, so i fixed

* actually run the docs on the changes 🤦
This commit is contained in:
Gus Caplan
2016-09-26 15:39:07 -05:00
committed by Amish Shah
parent b4f3575335
commit c8761d72de
4 changed files with 56 additions and 1 deletions

View File

@@ -552,6 +552,43 @@ class Guild {
return create.then(role => role.edit(data));
}
/**
* Creates a new custom emoji in the guild.
* @param {FileResolveable} attachment The image for the emoji.
* @param {string} name The name for the emoji.
* @returns {Promise<Emoji>} The created emoji.
* @example
* // create a new emoji from a url
* guild.createEmoji('https://i.imgur.com/w3duR07.png', 'rip')
* .then(emoji => console.log(`Created new emoji with name ${emoji.name}!`))
* .catch(console.log);
* @example
* // create a new emoji from a file on your computer
* guild.createEmoji('./memes/banana.png', 'banana')
* .then(emoji => console.log(`Created new emoji with name ${emoji.name}!`))
* .catch(console.log);
*/
createEmoji(attachment, name) {
return new Promise((resolve, reject) => {
this.client.resolver.resolveFile(attachment).then(file => {
let base64 = new Buffer(file, 'binary').toString('base64');
let dataURI = `data:;base64,${base64}`;
this.client.rest.methods.createEmoji(this, dataURI, name)
.then(resolve).catch(reject);
}).catch(reject);
});
}
/**
* Delete an emoji.
* @param {Emoji|string} emoji The emoji to delete.
* @returns {Promise}
*/
deleteEmoji(emoji) {
if (emoji instanceof Emoji) emoji = emoji.id;
return this.client.rest.methods.deleteEmoji(this, emoji);
}
/**
* Causes the Client to leave the guild.
* @returns {Promise<Guild>}