mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
Added guild.createRole()
This commit is contained in:
10
README.md
10
README.md
@@ -1,6 +1,6 @@
|
|||||||
<p align="center">
|
<p align="center">
|
||||||
<a href="https://hydrabolt.github.io/discord.js">
|
<a href="https://hydrabolt.github.io/discord.js">
|
||||||
<img alt="discord.js" src="http://hydrabolt.github.io/discord.js/res/logo.png" width="546"><br />
|
<img alt="discord.js" src="http://hydrabolt.github.io/discord.js/res/logo.png" width="546"><br />
|
||||||
</a>
|
</a>
|
||||||
<div align="center"><h1><i>REWRITE</i></h1></div>
|
<div align="center"><h1><i>REWRITE</i></h1></div>
|
||||||
</p>
|
</p>
|
||||||
110
package.json
110
package.json
@@ -1,55 +1,55 @@
|
|||||||
{
|
{
|
||||||
"name": "discord.js",
|
"name": "discord.js",
|
||||||
"version": "7.0.0",
|
"version": "7.0.0",
|
||||||
"description": "A way to interface with the Discord API",
|
"description": "A way to interface with the Discord API",
|
||||||
"main": "./src/index",
|
"main": "./src/index",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "jscs src && node test/random"
|
"test": "jscs src && node test/random"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git+https://github.com/hydrabolt/discord.js.git"
|
"url": "git+https://github.com/hydrabolt/discord.js.git"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"discord",
|
"discord",
|
||||||
"api",
|
"api",
|
||||||
"bot",
|
"bot",
|
||||||
"client",
|
"client",
|
||||||
"node",
|
"node",
|
||||||
"discordapp"
|
"discordapp"
|
||||||
],
|
],
|
||||||
"author": "Amish Shah <amishshah.2k@gmail.com>",
|
"author": "Amish Shah <amishshah.2k@gmail.com>",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/hydrabolt/discord.js/issues"
|
"url": "https://github.com/hydrabolt/discord.js/issues"
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/hydrabolt/discord.js#readme",
|
"homepage": "https://github.com/hydrabolt/discord.js#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"babel-plugin-transform-runtime": "^6.6.0",
|
"babel-plugin-transform-runtime": "^6.6.0",
|
||||||
"object.values": "^1.0.3",
|
"object.values": "^1.0.3",
|
||||||
"superagent": "^1.5.0",
|
"superagent": "^1.5.0",
|
||||||
"unpipe": "^1.0.0",
|
"unpipe": "^1.0.0",
|
||||||
"ws": "^0.8.1"
|
"ws": "^0.8.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"babel-preset-es2015": "^6.6.0",
|
"babel-preset-es2015": "^6.6.0",
|
||||||
"babel-preset-stage-3": "^6.5.0",
|
"babel-preset-stage-3": "^6.5.0",
|
||||||
"grunt": "^0.4.5",
|
"grunt": "^0.4.5",
|
||||||
"grunt-babel": "^6.0.0",
|
"grunt-babel": "^6.0.0",
|
||||||
"grunt-browserify": "^4.0.1",
|
"grunt-browserify": "^4.0.1",
|
||||||
"grunt-contrib-uglify": "^0.11.0",
|
"grunt-contrib-uglify": "^0.11.0",
|
||||||
"grunt-jscs": "^2.8.0",
|
"grunt-jscs": "^2.8.0",
|
||||||
"jscs": "^2.11.0",
|
"jscs": "^2.11.0",
|
||||||
"load-grunt-tasks": "^3.3.0"
|
"load-grunt-tasks": "^3.3.0"
|
||||||
},
|
},
|
||||||
"optionalDependencies": {
|
"optionalDependencies": {
|
||||||
"node-opus": "^0.1.11"
|
"node-opus": "^0.1.11"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=0.12.7"
|
"node": ">=0.12.7"
|
||||||
},
|
},
|
||||||
"browser": {
|
"browser": {
|
||||||
"./src/Util/TokenCacher.js": "./src/Util/TokenCacher-shim.js",
|
"./src/Util/TokenCacher.js": "./src/Util/TokenCacher-shim.js",
|
||||||
"./lib/Util/TokenCacher.js": "./lib/Util/TokenCacher-shim.js"
|
"./lib/Util/TokenCacher.js": "./lib/Util/TokenCacher-shim.js"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
@@ -1,260 +1,273 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const Constants = require('../../util/Constants');
|
const Constants = require('../../util/Constants');
|
||||||
const Structure = name => require('../../structures/' + name);
|
const Structure = name => require('../../structures/' + name);
|
||||||
const User = Structure('User');
|
const User = Structure('User');
|
||||||
const GuildMember = Structure('GuildMember');
|
const GuildMember = Structure('GuildMember');
|
||||||
const Message = Structure('Message');
|
const Message = Structure('Message');
|
||||||
|
|
||||||
class RESTMethods{
|
class RESTMethods{
|
||||||
constructor(restManager) {
|
constructor(restManager) {
|
||||||
this.rest = restManager;
|
this.rest = restManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
LoginEmailPassword(email, password) {
|
LoginEmailPassword(email, password) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.rest.client.store.email = email;
|
this.rest.client.store.email = email;
|
||||||
this.rest.client.store.password = password;
|
this.rest.client.store.password = password;
|
||||||
this.rest.makeRequest('post', Constants.Endpoints.LOGIN, false, { email, password })
|
this.rest.makeRequest('post', Constants.Endpoints.LOGIN, false, { email, password })
|
||||||
.then(data => {
|
.then(data => {
|
||||||
this.rest.client.manager.connectToWebSocket(data.token, resolve, reject);
|
this.rest.client.manager.connectToWebSocket(data.token, resolve, reject);
|
||||||
})
|
})
|
||||||
.catch(reject);
|
.catch(reject);
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
LoginToken(token) {
|
LoginToken(token) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.rest.client.manager.connectToWebSocket(token, resolve, reject);
|
this.rest.client.manager.connectToWebSocket(token, resolve, reject);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
GetGateway() {
|
GetGateway() {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.rest.makeRequest('get', Constants.Endpoints.GATEWAY, true)
|
this.rest.makeRequest('get', Constants.Endpoints.GATEWAY, true)
|
||||||
.then(res => resolve(res.url))
|
.then(res => resolve(res.url))
|
||||||
.catch(reject);
|
.catch(reject);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
SendMessage(channel, content, tts, nonce) {
|
SendMessage(channel, content, tts, nonce) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
|
||||||
var _this = this;
|
var _this = this;
|
||||||
|
|
||||||
if (channel instanceof User || channel instanceof GuildMember) {
|
if (channel instanceof User || channel instanceof GuildMember) {
|
||||||
this.CreateDM(channel).then(chan => {
|
this.CreateDM(channel).then(chan => {
|
||||||
channel = chan;
|
channel = chan;
|
||||||
req();
|
req();
|
||||||
})
|
})
|
||||||
.catch(reject);
|
.catch(reject);
|
||||||
} else {
|
} else {
|
||||||
req();
|
req();
|
||||||
}
|
}
|
||||||
|
|
||||||
function req() {
|
function req() {
|
||||||
_this.rest.makeRequest('post', Constants.Endpoints.CHANNEL_MESSAGES(channel.id), true, {
|
_this.rest.makeRequest('post', Constants.Endpoints.CHANNEL_MESSAGES(channel.id), true, {
|
||||||
content, tts, nonce,
|
content, tts, nonce,
|
||||||
})
|
})
|
||||||
.then(data => resolve(_this.rest.client.actions.MessageCreate.handle(data).m))
|
.then(data => resolve(_this.rest.client.actions.MessageCreate.handle(data).m))
|
||||||
.catch(reject);
|
.catch(reject);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
DeleteMessage(message) {
|
DeleteMessage(message) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.rest.makeRequest('del', Constants.Endpoints.CHANNEL_MESSAGE(message.channel.id, message.id), true)
|
this.rest.makeRequest('del', Constants.Endpoints.CHANNEL_MESSAGE(message.channel.id, message.id), true)
|
||||||
.then(data => {
|
.then(data => {
|
||||||
resolve(this.rest.client.actions.MessageDelete.handle({
|
resolve(this.rest.client.actions.MessageDelete.handle({
|
||||||
id: message.id,
|
id: message.id,
|
||||||
channel_id: message.channel.id,
|
channel_id: message.channel.id,
|
||||||
}).m);
|
}).m);
|
||||||
})
|
})
|
||||||
.catch(reject);
|
.catch(reject);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateMessage(message, content) {
|
UpdateMessage(message, content) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.rest.makeRequest('patch', Constants.Endpoints.CHANNEL_MESSAGE(message.channel.id, message.id), true, {
|
this.rest.makeRequest('patch', Constants.Endpoints.CHANNEL_MESSAGE(message.channel.id, message.id), true, {
|
||||||
content,
|
content,
|
||||||
})
|
})
|
||||||
.then(data => {
|
.then(data => {
|
||||||
resolve(this.rest.client.actions.MessageUpdate.handle(data).updated);
|
resolve(this.rest.client.actions.MessageUpdate.handle(data).updated);
|
||||||
})
|
})
|
||||||
.catch(reject);
|
.catch(reject);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
CreateChannel(guild, channelName, channelType) {
|
CreateChannel(guild, channelName, channelType) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.rest.makeRequest('post', Constants.Endpoints.GUILD_CHANNELS(guild.id), true, {
|
this.rest.makeRequest('post', Constants.Endpoints.GUILD_CHANNELS(guild.id), true, {
|
||||||
name: channelName,
|
name: channelName,
|
||||||
type: channelType,
|
type: channelType,
|
||||||
})
|
})
|
||||||
.then(data => {
|
.then(data => {
|
||||||
resolve(this.rest.client.actions.ChannelCreate.handle(data).channel);
|
resolve(this.rest.client.actions.ChannelCreate.handle(data).channel);
|
||||||
})
|
})
|
||||||
.catch(reject);
|
.catch(reject);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
GetExistingDM(recipient) {
|
GetExistingDM(recipient) {
|
||||||
let dmChannel = this.rest.client.store.getAsArray('channels')
|
let dmChannel = this.rest.client.store.getAsArray('channels')
|
||||||
.filter(channel => channel.recipient)
|
.filter(channel => channel.recipient)
|
||||||
.filter(channel => channel.recipient.id === recipient.id);
|
.filter(channel => channel.recipient.id === recipient.id);
|
||||||
|
|
||||||
return dmChannel[0];
|
return dmChannel[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
CreateDM(recipient) {
|
CreateDM(recipient) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
|
||||||
let dmChannel = this.GetExistingDM(recipient);
|
let dmChannel = this.GetExistingDM(recipient);
|
||||||
|
|
||||||
if (dmChannel) {
|
if (dmChannel) {
|
||||||
return resolve(dmChannel);
|
return resolve(dmChannel);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.rest.makeRequest('post', Constants.Endpoints.USER_CHANNELS(this.rest.client.store.user.id), true, {
|
this.rest.makeRequest('post', Constants.Endpoints.USER_CHANNELS(this.rest.client.store.user.id), true, {
|
||||||
recipient_id: recipient.id,
|
recipient_id: recipient.id,
|
||||||
})
|
})
|
||||||
.then(data => resolve(this.rest.client.actions.ChannelCreate.handle(data).channel))
|
.then(data => resolve(this.rest.client.actions.ChannelCreate.handle(data).channel))
|
||||||
.catch(reject);
|
.catch(reject);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
DeleteChannel(channel) {
|
DeleteChannel(channel) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (channel instanceof User || channel instanceof GuildMember) {
|
if (channel instanceof User || channel instanceof GuildMember) {
|
||||||
channel = this.GetExistingDM(channel);
|
channel = this.GetExistingDM(channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.rest.makeRequest('del', Constants.Endpoints.CHANNEL(channel.id), true)
|
this.rest.makeRequest('del', Constants.Endpoints.CHANNEL(channel.id), true)
|
||||||
.then(data => {
|
.then(data => {
|
||||||
data.id = channel.id;
|
data.id = channel.id;
|
||||||
resolve(this.rest.client.actions.ChannelDelete.handle(data).channel);
|
resolve(this.rest.client.actions.ChannelDelete.handle(data).channel);
|
||||||
})
|
})
|
||||||
.catch(reject);
|
.catch(reject);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateChannel(channel, data) {
|
UpdateChannel(channel, data) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
data.name = (data.name || channel.name).trim();
|
data.name = (data.name || channel.name).trim();
|
||||||
data.topic = data.topic || channel.topic;
|
data.topic = data.topic || channel.topic;
|
||||||
data.position = data.position || channel.position;
|
data.position = data.position || channel.position;
|
||||||
data.bitrate = data.bitrate || channel.bitrate;
|
data.bitrate = data.bitrate || channel.bitrate;
|
||||||
|
|
||||||
this.rest.makeRequest('patch', Constants.Endpoints.CHANNEL(channel.id), true, data)
|
this.rest.makeRequest('patch', Constants.Endpoints.CHANNEL(channel.id), true, data)
|
||||||
.then(data => {
|
.then(data => {
|
||||||
resolve(this.rest.client.actions.ChannelUpdate.handle(data).updated);
|
resolve(this.rest.client.actions.ChannelUpdate.handle(data).updated);
|
||||||
})
|
})
|
||||||
.catch(reject);
|
.catch(reject);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
LeaveGuild(guild) {
|
LeaveGuild(guild) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.rest.makeRequest('del', Constants.Endpoints.ME_GUILD(guild.id), true)
|
this.rest.makeRequest('del', Constants.Endpoints.ME_GUILD(guild.id), true)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
resolve(this.rest.client.actions.GuildDelete.handle({ id:guild.id }).guild);
|
resolve(this.rest.client.actions.GuildDelete.handle({ id:guild.id }).guild);
|
||||||
})
|
})
|
||||||
.catch(reject);
|
.catch(reject);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// untested but probably will work
|
// untested but probably will work
|
||||||
DeleteGuild(guild) {
|
DeleteGuild(guild) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.rest.makeRequest('del', Constants.Endpoints.GUILD(guild.id), true)
|
this.rest.makeRequest('del', Constants.Endpoints.GUILD(guild.id), true)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
resolve(this.rest.client.actions.GuildDelete.handle({ id:guild.id }).guild);
|
resolve(this.rest.client.actions.GuildDelete.handle({ id:guild.id }).guild);
|
||||||
})
|
})
|
||||||
.catch(reject);
|
.catch(reject);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateCurrentUser(_data) {
|
UpdateCurrentUser(_data) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
let user = this.rest.client.store.user;
|
let user = this.rest.client.store.user;
|
||||||
let data = {};
|
let data = {};
|
||||||
|
|
||||||
data.username = _data.username || user.username;
|
data.username = _data.username || user.username;
|
||||||
data.avatar = this.rest.client.resolver.ResolveBase64(_data.avatar) || user.avatar;
|
data.avatar = this.rest.client.resolver.ResolveBase64(_data.avatar) || user.avatar;
|
||||||
if (!user.bot) {
|
if (!user.bot) {
|
||||||
data.password = this.rest.client.store.password;
|
data.password = this.rest.client.store.password;
|
||||||
data.email = _data.email || this.rest.client.store.email;
|
data.email = _data.email || this.rest.client.store.email;
|
||||||
data.new_password = _data.newPassword;
|
data.new_password = _data.newPassword;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.rest.makeRequest('patch', Constants.Endpoints.ME, true, data)
|
this.rest.makeRequest('patch', Constants.Endpoints.ME, true, data)
|
||||||
.then(data => resolve(this.rest.client.actions.UserUpdate.handle(data).updated))
|
.then(data => resolve(this.rest.client.actions.UserUpdate.handle(data).updated))
|
||||||
.catch(reject);
|
.catch(reject);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateGuild(guild, _data) {
|
UpdateGuild(guild, _data) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
/*
|
/*
|
||||||
can contain:
|
can contain:
|
||||||
name, region, verificationLevel, afkChannel, afkTimeout, icon, owner, splash
|
name, region, verificationLevel, afkChannel, afkTimeout, icon, owner, splash
|
||||||
*/
|
*/
|
||||||
|
|
||||||
let data = {};
|
let data = {};
|
||||||
|
|
||||||
if (_data.name) {
|
if (_data.name) {
|
||||||
data.name = _data.name;
|
data.name = _data.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_data.region) {
|
if (_data.region) {
|
||||||
data.region = _data.region;
|
data.region = _data.region;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_data.verificationLevel) {
|
if (_data.verificationLevel) {
|
||||||
data.verification_level = Number(_data.verificationLevel);
|
data.verification_level = Number(_data.verificationLevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_data.afkChannel) {
|
if (_data.afkChannel) {
|
||||||
data.afk_channel_id = this.rest.client.resolver.ResolveChannel(_data.afkChannel).id;
|
data.afk_channel_id = this.rest.client.resolver.ResolveChannel(_data.afkChannel).id;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_data.afkTimeout) {
|
if (_data.afkTimeout) {
|
||||||
data.afk_timeout = Number(_data.afkTimeout);
|
data.afk_timeout = Number(_data.afkTimeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_data.icon) {
|
if (_data.icon) {
|
||||||
data.icon = this.rest.client.resolver.ResolveBase64(_data.icon);
|
data.icon = this.rest.client.resolver.ResolveBase64(_data.icon);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_data.owner) {
|
if (_data.owner) {
|
||||||
data.owner_id = this.rest.client.resolver.ResolveUser(_data.owner).id;
|
data.owner_id = this.rest.client.resolver.ResolveUser(_data.owner).id;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_data.splash) {
|
if (_data.splash) {
|
||||||
data.splash = this.rest.client.resolver.ResolveBase64(_data.splash);
|
data.splash = this.rest.client.resolver.ResolveBase64(_data.splash);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.rest.makeRequest('patch', Constants.Endpoints.GUILD(guild.id), true, data)
|
this.rest.makeRequest('patch', Constants.Endpoints.GUILD(guild.id), true, data)
|
||||||
.then(data => resolve(this.rest.client.actions.GuildUpdate.handle(data).updated))
|
.then(data => resolve(this.rest.client.actions.GuildUpdate.handle(data).updated))
|
||||||
.catch(reject);
|
.catch(reject);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
KickGuildMember(guild, member) {
|
KickGuildMember(guild, member) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.rest.makeRequest('del', Constants.Endpoints.GUILD_MEMBER(guild.id, member.id), true)
|
this.rest.makeRequest('del', Constants.Endpoints.GUILD_MEMBER(guild.id, member.id), true)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
resolve(this.rest.client.actions.GuildMemberRemove.handle({
|
resolve(this.rest.client.actions.GuildMemberRemove.handle({
|
||||||
guild_id : guild.id,
|
guild_id : guild.id,
|
||||||
user : member.user,
|
user : member.user,
|
||||||
}).m);
|
}).m);
|
||||||
})
|
})
|
||||||
.catch(reject);
|
.catch(reject);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
CreateGuildRole(guild) {
|
||||||
module.exports = RESTMethods;
|
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;
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user