mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 16:43:31 +01:00
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:
@@ -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>}
|
||||
|
||||
Reference in New Issue
Block a user