mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-12 01:23:31 +01:00
Prepare for upcoming leave/deleteServer separation (fix #198)
This commit is contained in:
@@ -662,13 +662,13 @@ export default class Client extends EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Leaves a Discord Server, alias to `client.leaveServer`
|
||||
* Deletes a Discord Server
|
||||
* @param {ServerResolvable} server the server to leave
|
||||
* @param {function(err: Error)} [callback] callback to the method
|
||||
* @returns {Promise<null, Error>} resolves null if successful, otherwise rejects with an error.
|
||||
*/
|
||||
deleteServer(server, callback = (/*err, {}*/) => { }) {
|
||||
return this.internal.leaveServer(server)
|
||||
return this.internal.deleteServer(server)
|
||||
.then(dataCallback(callback), errorCallback(callback));
|
||||
}
|
||||
|
||||
|
||||
@@ -319,6 +319,24 @@ export default class InternalClient {
|
||||
return Promise.reject(new Error("server did not resolve"));
|
||||
}
|
||||
|
||||
return this.apiRequest("del", Endpoints.ME_SERVER(server.id), true)
|
||||
.then(() => {
|
||||
// remove channels of server then the server
|
||||
for (var chan of server.channels) {
|
||||
this.channels.remove(chan);
|
||||
}
|
||||
// remove server
|
||||
this.servers.remove(server);
|
||||
});
|
||||
}
|
||||
|
||||
//def deleteServer
|
||||
deleteServer(srv) {
|
||||
var server = this.resolver.resolveServer(srv);
|
||||
if (!server) {
|
||||
return Promise.reject(new Error("server did not resolve"));
|
||||
}
|
||||
|
||||
return this.apiRequest("del", Endpoints.SERVER(server.id), true)
|
||||
.then(() => {
|
||||
// remove channels of server then the server
|
||||
|
||||
@@ -6,6 +6,7 @@ export const Endpoints = {
|
||||
LOGIN: `${API}/auth/login`,
|
||||
LOGOUT: `${API}/auth/logout`,
|
||||
ME: `${API}/users/@me`,
|
||||
ME_SERVER: (serverID) => `${Endpoints.ME}/guilds/${serverID}`,
|
||||
GATEWAY: `${API}/gateway`,
|
||||
USER_CHANNELS: (userID) => `${API}/users/${userID}/channels`,
|
||||
AVATAR : (userID, avatar) => `${API}/users/${userID}/avatars/${avatar}.jpg`,
|
||||
|
||||
Reference in New Issue
Block a user