mirror of
https://github.com/danbulant/discord.js
synced 2026-07-06 03:31:03 +00:00
Added guild.createRole()
This commit is contained in:
parent
bbf0b0683a
commit
849b8df2da
8 changed files with 382 additions and 332 deletions
|
|
@ -15,6 +15,7 @@ class ActionsManager {
|
||||||
this.register('GuildDelete');
|
this.register('GuildDelete');
|
||||||
this.register('GuildUpdate');
|
this.register('GuildUpdate');
|
||||||
this.register('GuildMemberRemove');
|
this.register('GuildMemberRemove');
|
||||||
|
this.register('GuildRoleCreate');
|
||||||
this.register('UserUpdate');
|
this.register('UserUpdate');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
38
src/client/actions/GuildRoleCreate.js
Normal file
38
src/client/actions/GuildRoleCreate.js
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
const Action = require('./Action');
|
||||||
|
const Constants = require('../../util/Constants');
|
||||||
|
const Role = require('../../structures/Role');
|
||||||
|
|
||||||
|
class GuildRoleCreate extends Action {
|
||||||
|
|
||||||
|
constructor(client) {
|
||||||
|
super(client);
|
||||||
|
}
|
||||||
|
|
||||||
|
handle(data) {
|
||||||
|
|
||||||
|
let client = this.client;
|
||||||
|
let guild = client.store.get('guilds', data.guild_id);
|
||||||
|
|
||||||
|
if (guild) {
|
||||||
|
let already = guild.store.get('roles', data.role.id);
|
||||||
|
let role = new Role(guild, data.role);
|
||||||
|
guild.store.add('roles', role);
|
||||||
|
|
||||||
|
if (!already) {
|
||||||
|
client.emit(Constants.Events.GUILD_ROLE_CREATE, guild, role);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
role,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
role: null,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = GuildRoleCreate;
|
||||||
|
|
@ -255,6 +255,19 @@ class RESTMethods{
|
||||||
.catch(reject);
|
.catch(reject);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CreateGuildRole(guild) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
this.rest.makeRequest('post', Constants.Endpoints.GUILD_ROLES(guild.id), true)
|
||||||
|
.then(role => {
|
||||||
|
resolve(this.rest.client.actions.GuildRoleCreate.handle({
|
||||||
|
guild_id : guild.id,
|
||||||
|
role,
|
||||||
|
}).role);
|
||||||
|
})
|
||||||
|
.catch(reject);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = RESTMethods;
|
module.exports = RESTMethods;
|
||||||
|
|
|
||||||
|
|
@ -17,18 +17,7 @@ class GuildRoleCreateHandler extends AbstractHandler {
|
||||||
let data = packet.d;
|
let data = packet.d;
|
||||||
let client = this.packetManager.client;
|
let client = this.packetManager.client;
|
||||||
|
|
||||||
let guild = client.store.get('guilds', data.guild_id);
|
let response = client.actions.GuildRoleCreate.handle(data);
|
||||||
|
|
||||||
if (guild) {
|
|
||||||
let already = guild.store.get('roles', data.role.id);
|
|
||||||
let role = new Role(guild, data.role);
|
|
||||||
guild.store.add('roles', role);
|
|
||||||
|
|
||||||
if (!already) {
|
|
||||||
client.emit(Constants.Events.GUILD_ROLE_CREATE, guild, role);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -180,6 +180,10 @@ class Guild {
|
||||||
return this.client.rest.methods.CreateChannel(this, name, type);
|
return this.client.rest.methods.CreateChannel(this, name, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
createRole() {
|
||||||
|
return this.client.rest.methods.CreateGuildRole(this);
|
||||||
|
}
|
||||||
|
|
||||||
leave() {
|
leave() {
|
||||||
return this.client.rest.methods.LeaveGuild(this);
|
return this.client.rest.methods.LeaveGuild(this);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -135,6 +135,11 @@ client.on('message', message => {
|
||||||
}).catch(console.log);
|
}).catch(console.log);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (message.content === 'makerole') {
|
||||||
|
message.guild.createRole().then(role => {
|
||||||
|
message.channel.sendMessage(`Made role ${role.name}`);
|
||||||
|
}).catch(console.log);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue