mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-11 00:53:31 +01:00
add clientUser#createGuild (#832)
* add clientUser#createGuild merge docs * almost caused a memory leak! * muh triggers
This commit is contained in:
@@ -205,6 +205,26 @@ class RESTMethods {
|
||||
});
|
||||
}
|
||||
|
||||
createGuild(options) {
|
||||
options.icon = this.rest.client.resolver.resolveBase64(options.icon) || null;
|
||||
options.region = options.region || 'us-central';
|
||||
return new Promise((resolve, reject) => {
|
||||
this.rest.makeRequest('post', Constants.Endpoints.guilds, true, options)
|
||||
.then(data => {
|
||||
if (this.rest.client.guilds.has(data.id)) resolve(this.rest.client.guilds.get(data.id));
|
||||
const handleGuild = guild => {
|
||||
if (guild.id === data.id) resolve(guild);
|
||||
this.rest.client.removeListener('guildCreate', handleGuild);
|
||||
};
|
||||
this.rest.client.on('guildCreate', handleGuild);
|
||||
this.rest.client.setTimeout(() => {
|
||||
this.rest.client.removeListener('guildCreate', handleGuild);
|
||||
reject(new Error('Took too long to receive guild data'));
|
||||
}, 10000);
|
||||
}).catch(reject);
|
||||
});
|
||||
}
|
||||
|
||||
// untested but probably will work
|
||||
deleteGuild(guild) {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
Reference in New Issue
Block a user