mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
Added channel.delete()
This commit is contained in:
@@ -10,6 +10,7 @@ class ActionsManager {
|
||||
this.register('MessageDelete');
|
||||
this.register('MessageUpdate');
|
||||
this.register('ChannelCreate');
|
||||
this.register('ChannelDelete');
|
||||
}
|
||||
|
||||
register(name) {
|
||||
|
||||
27
src/client/actions/ChannelDelete.js
Normal file
27
src/client/actions/ChannelDelete.js
Normal file
@@ -0,0 +1,27 @@
|
||||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const Constants = require('../../util/Constants');
|
||||
const Message = require('../../structures/Message');
|
||||
|
||||
class ChannelDeleteAction extends Action {
|
||||
|
||||
constructor(client) {
|
||||
super(client);
|
||||
}
|
||||
|
||||
handle(data) {
|
||||
let client = this.client;
|
||||
let channel = client.store.get('channels', data.id);
|
||||
|
||||
if (channel) {
|
||||
client.store.KillChannel(channel);
|
||||
}
|
||||
|
||||
return {
|
||||
channel,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = ChannelDeleteAction;
|
||||
@@ -85,6 +85,17 @@ class RESTMethods{
|
||||
.catch(reject);
|
||||
});
|
||||
}
|
||||
|
||||
DeleteChannel(channel) {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.rest.makeRequest('del', Constants.Endpoints.CHANNEL(channel.id), true)
|
||||
.then(data => {
|
||||
data.id = channel.id;
|
||||
resolve(this.rest.client.actions.ChannelDelete.handle(data).channel);
|
||||
})
|
||||
.catch(reject);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = RESTMethods;
|
||||
|
||||
@@ -19,10 +19,10 @@ class ChannelDeleteHandler extends AbstractHandler {
|
||||
let data = packet.d;
|
||||
let client = this.packetManager.client;
|
||||
|
||||
let channel = client.store.get('channels', data.id);
|
||||
let response = client.actions.ChannelCreate.handle(data);
|
||||
|
||||
if (channel) {
|
||||
client.store.KillChannel(channel);
|
||||
if (response.channel) {
|
||||
client.emit(Constants.Events.CHANNEL_DELETE, response.channel);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,10 @@ class Channel {
|
||||
setup(data) {
|
||||
this.id = data.id;
|
||||
}
|
||||
|
||||
delete() {
|
||||
return this.client.rest.methods.DeleteChannel(this);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Channel;
|
||||
|
||||
@@ -87,10 +87,6 @@ class ClientDataStore extends AbstractDataStore{
|
||||
if (channel instanceof ServerChannel) {
|
||||
channel.guild.store.remove('channels', channel);
|
||||
}
|
||||
|
||||
if (already && this.pastReady) {
|
||||
this.client.emit(Constants.Events.CHANNEL_DELETE, channel);
|
||||
}
|
||||
}
|
||||
|
||||
UpdateGuild(currentGuild, newData) {
|
||||
|
||||
@@ -23,7 +23,7 @@ client.on('channelCreate', channel => {
|
||||
// console.log(channel);
|
||||
});
|
||||
client.on('channelDelete', channel => {
|
||||
console.log(channel);
|
||||
console.log('channDel', channel);
|
||||
});
|
||||
|
||||
client.on('channelUpdate', (old, chan) => {
|
||||
@@ -75,6 +75,10 @@ client.on('message', message => {
|
||||
message.channel.guild.createChannel('hi', 'text').then(console.log);
|
||||
}
|
||||
}
|
||||
|
||||
if (message.content === 'delchann') {
|
||||
message.channel.delete();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user