discord.js-selfv13 13.0.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of discord.js-selfv13 might be problematic. Click here for more details.
- package/.dccache +1 -0
- package/LICENSE +190 -0
- package/README.md +87 -0
- package/browser.js +9 -0
- package/deploy/deploy-key.enc +0 -0
- package/deploy/deploy.sh +90 -0
- package/deploy/test.sh +34 -0
- package/docs/README.md +1 -0
- package/docs/examples/attachments.md +163 -0
- package/docs/examples/avatars.js +29 -0
- package/docs/examples/embed.js +38 -0
- package/docs/examples/greeting.js +30 -0
- package/docs/examples/moderation.md +145 -0
- package/docs/examples/ping.js +29 -0
- package/docs/examples/webhook.js +12 -0
- package/docs/general/faq.md +23 -0
- package/docs/general/updating.md +181 -0
- package/docs/general/welcome.md +95 -0
- package/docs/index.yml +30 -0
- package/docs/logo.svg +19 -0
- package/docs/topics/voice.md +113 -0
- package/docs/topics/web.md +38 -0
- package/package.json +147 -0
- package/src/client/Client.js +564 -0
- package/src/client/ClientDataManager.js +150 -0
- package/src/client/ClientDataResolver.js +376 -0
- package/src/client/ClientManager.js +74 -0
- package/src/client/WebhookClient.js +118 -0
- package/src/client/actions/Action.js +23 -0
- package/src/client/actions/ActionsManager.js +40 -0
- package/src/client/actions/ChannelCreate.js +11 -0
- package/src/client/actions/ChannelDelete.js +30 -0
- package/src/client/actions/ChannelUpdate.js +74 -0
- package/src/client/actions/GuildBanRemove.js +13 -0
- package/src/client/actions/GuildChannelsPositionUpdate.js +19 -0
- package/src/client/actions/GuildDelete.js +57 -0
- package/src/client/actions/GuildEmojiCreate.js +17 -0
- package/src/client/actions/GuildEmojiDelete.js +18 -0
- package/src/client/actions/GuildEmojiUpdate.js +17 -0
- package/src/client/actions/GuildEmojisUpdate.js +38 -0
- package/src/client/actions/GuildMemberGet.js +10 -0
- package/src/client/actions/GuildMemberRemove.js +41 -0
- package/src/client/actions/GuildRoleCreate.js +26 -0
- package/src/client/actions/GuildRoleDelete.js +42 -0
- package/src/client/actions/GuildRoleUpdate.js +41 -0
- package/src/client/actions/GuildRolesPositionUpdate.js +19 -0
- package/src/client/actions/GuildSync.js +29 -0
- package/src/client/actions/GuildUpdate.js +34 -0
- package/src/client/actions/MessageCreate.js +53 -0
- package/src/client/actions/MessageDelete.js +35 -0
- package/src/client/actions/MessageDeleteBulk.js +26 -0
- package/src/client/actions/MessageReactionAdd.js +37 -0
- package/src/client/actions/MessageReactionRemove.js +37 -0
- package/src/client/actions/MessageReactionRemoveAll.js +25 -0
- package/src/client/actions/MessageUpdate.js +40 -0
- package/src/client/actions/Ready.js +1 -0
- package/src/client/actions/Ready.js.bak +65 -0
- package/src/client/actions/UserGet.js +11 -0
- package/src/client/actions/UserNoteUpdate.js +30 -0
- package/src/client/actions/UserUpdate.js +33 -0
- package/src/client/rest/APIRequest.js +56 -0
- package/src/client/rest/DiscordAPIError.js +60 -0
- package/src/client/rest/RESTManager.js +58 -0
- package/src/client/rest/RESTMethods.js +1006 -0
- package/src/client/rest/RequestHandlers/Burst.js +90 -0
- package/src/client/rest/RequestHandlers/RequestHandler.js +54 -0
- package/src/client/rest/RequestHandlers/Sequential.js +132 -0
- package/src/client/rest/UserAgentManager.js +25 -0
- package/src/client/voice/ClientVoiceManager.js +81 -0
- package/src/client/voice/VoiceBroadcast.js +366 -0
- package/src/client/voice/VoiceConnection.js +530 -0
- package/src/client/voice/VoiceUDPClient.js +127 -0
- package/src/client/voice/VoiceWebSocket.js +246 -0
- package/src/client/voice/dispatcher/StreamDispatcher.js +331 -0
- package/src/client/voice/opus/BaseOpusEngine.js +60 -0
- package/src/client/voice/opus/NodeOpusEngine.js +40 -0
- package/src/client/voice/opus/OpusEngineList.js +28 -0
- package/src/client/voice/opus/OpusScriptEngine.js +45 -0
- package/src/client/voice/player/AudioPlayer.js +170 -0
- package/src/client/voice/receiver/VoiceReadable.js +17 -0
- package/src/client/voice/receiver/VoiceReceiver.js +219 -0
- package/src/client/voice/util/SecretKey.js +16 -0
- package/src/client/voice/util/Secretbox.js +33 -0
- package/src/client/voice/util/VolumeInterface.js +86 -0
- package/src/client/websocket/WebSocketConnection.js +506 -0
- package/src/client/websocket/WebSocketManager.js +90 -0
- package/src/client/websocket/packets/WebSocketPacketManager.js +110 -0
- package/src/client/websocket/packets/handlers/AbstractHandler.js +11 -0
- package/src/client/websocket/packets/handlers/ChannelCreate.js +17 -0
- package/src/client/websocket/packets/handlers/ChannelDelete.js +20 -0
- package/src/client/websocket/packets/handlers/ChannelPinsUpdate.js +37 -0
- package/src/client/websocket/packets/handlers/ChannelUpdate.js +11 -0
- package/src/client/websocket/packets/handlers/GuildBanAdd.js +23 -0
- package/src/client/websocket/packets/handlers/GuildBanRemove.js +20 -0
- package/src/client/websocket/packets/handlers/GuildCreate.js +22 -0
- package/src/client/websocket/packets/handlers/GuildDelete.js +19 -0
- package/src/client/websocket/packets/handlers/GuildEmojisUpdate.js +11 -0
- package/src/client/websocket/packets/handlers/GuildIntegrationsUpdate.js +19 -0
- package/src/client/websocket/packets/handlers/GuildMemberAdd.js +17 -0
- package/src/client/websocket/packets/handlers/GuildMemberRemove.js +13 -0
- package/src/client/websocket/packets/handlers/GuildMemberUpdate.js +18 -0
- package/src/client/websocket/packets/handlers/GuildMembersChunk.js +33 -0
- package/src/client/websocket/packets/handlers/GuildRoleCreate.js +11 -0
- package/src/client/websocket/packets/handlers/GuildRoleDelete.js +11 -0
- package/src/client/websocket/packets/handlers/GuildRoleUpdate.js +11 -0
- package/src/client/websocket/packets/handlers/GuildSync.js +11 -0
- package/src/client/websocket/packets/handlers/GuildUpdate.js +11 -0
- package/src/client/websocket/packets/handlers/MessageCreate.js +19 -0
- package/src/client/websocket/packets/handlers/MessageDelete.js +19 -0
- package/src/client/websocket/packets/handlers/MessageDeleteBulk.js +17 -0
- package/src/client/websocket/packets/handlers/MessageReactionAdd.js +11 -0
- package/src/client/websocket/packets/handlers/MessageReactionRemove.js +11 -0
- package/src/client/websocket/packets/handlers/MessageReactionRemoveAll.js +11 -0
- package/src/client/websocket/packets/handlers/MessageUpdate.js +11 -0
- package/src/client/websocket/packets/handlers/PresenceUpdate.js +76 -0
- package/src/client/websocket/packets/handlers/Ready.js +83 -0
- package/src/client/websocket/packets/handlers/RelationshipAdd.js +19 -0
- package/src/client/websocket/packets/handlers/RelationshipRemove.js +19 -0
- package/src/client/websocket/packets/handlers/Resumed.js +28 -0
- package/src/client/websocket/packets/handlers/TypingStart.js +68 -0
- package/src/client/websocket/packets/handlers/UserGuildSettingsUpdate.js +21 -0
- package/src/client/websocket/packets/handlers/UserNoteUpdate.js +12 -0
- package/src/client/websocket/packets/handlers/UserSettingsUpdate.js +18 -0
- package/src/client/websocket/packets/handlers/UserUpdate.js +11 -0
- package/src/client/websocket/packets/handlers/VoiceServerUpdate.js +19 -0
- package/src/client/websocket/packets/handlers/VoiceStateUpdate.js +52 -0
- package/src/client/websocket/packets/handlers/WebhooksUpdate.js +19 -0
- package/src/index.js +66 -0
- package/src/sharding/Shard.js +282 -0
- package/src/sharding/ShardClientUtil.js +146 -0
- package/src/sharding/ShardingManager.js +220 -0
- package/src/structures/Attachment.js +75 -0
- package/src/structures/CategoryChannel.js +22 -0
- package/src/structures/Channel.js +78 -0
- package/src/structures/ClientUser.js +447 -0
- package/src/structures/ClientUserChannelOverride.js +30 -0
- package/src/structures/ClientUserGuildSettings.js +60 -0
- package/src/structures/ClientUserSettings.js +80 -0
- package/src/structures/DMChannel.js +76 -0
- package/src/structures/Emoji.js +256 -0
- package/src/structures/GroupDMChannel.js +246 -0
- package/src/structures/Guild.js +1461 -0
- package/src/structures/GuildAuditLogs.js +371 -0
- package/src/structures/GuildChannel.js +537 -0
- package/src/structures/GuildMember.js +613 -0
- package/src/structures/Invite.js +164 -0
- package/src/structures/Message.js +605 -0
- package/src/structures/MessageAttachment.js +68 -0
- package/src/structures/MessageCollector.js +100 -0
- package/src/structures/MessageEmbed.js +386 -0
- package/src/structures/MessageMentions.js +144 -0
- package/src/structures/MessageReaction.js +96 -0
- package/src/structures/NewsChannel.js +24 -0
- package/src/structures/OAuth2Application.js +148 -0
- package/src/structures/PartialGuild.js +51 -0
- package/src/structures/PartialGuildChannel.js +44 -0
- package/src/structures/PermissionOverwrites.js +69 -0
- package/src/structures/Presence.js +241 -0
- package/src/structures/ReactionCollector.js +85 -0
- package/src/structures/ReactionEmoji.js +49 -0
- package/src/structures/RichEmbed.js +295 -0
- package/src/structures/Role.js +376 -0
- package/src/structures/StoreChannel.js +25 -0
- package/src/structures/TextChannel.js +154 -0
- package/src/structures/User.js +329 -0
- package/src/structures/UserConnection.js +48 -0
- package/src/structures/UserProfile.js +62 -0
- package/src/structures/VoiceChannel.js +146 -0
- package/src/structures/VoiceRegion.js +50 -0
- package/src/structures/Webhook.js +304 -0
- package/src/structures/interfaces/Collector.js +179 -0
- package/src/structures/interfaces/TextBasedChannel.js +635 -0
- package/src/structures/shared/resolvePermissions.js +26 -0
- package/src/util/Collection.js +532 -0
- package/src/util/Constants.js +845 -0
- package/src/util/Permissions.js +306 -0
- package/src/util/Snowflake.js +82 -0
- package/src/util/Util.js +221 -0
- package/test/random.js +207 -0
- package/test/shard.js +31 -0
- package/test/sharder.js +7 -0
- package/test/voice.js +78 -0
- package/test/webpack.html +31 -0
- package/tsconfig.json +13 -0
- package/tslint.json +62 -0
- package/typings/discord.js-test.ts +69 -0
- package/typings/index.d.ts +2190 -0
- package/webpack.config.js +62 -0
@@ -0,0 +1,1461 @@
|
|
1
|
+
const util = require('util');
|
2
|
+
const Long = require('long');
|
3
|
+
const User = require('./User');
|
4
|
+
const Role = require('./Role');
|
5
|
+
const Emoji = require('./Emoji');
|
6
|
+
const Presence = require('./Presence').Presence;
|
7
|
+
const GuildMember = require('./GuildMember');
|
8
|
+
const Constants = require('../util/Constants');
|
9
|
+
const Collection = require('../util/Collection');
|
10
|
+
const Util = require('../util/Util');
|
11
|
+
const Snowflake = require('../util/Snowflake');
|
12
|
+
|
13
|
+
/**
|
14
|
+
* Represents a guild (or a server) on Discord.
|
15
|
+
* <info>It's recommended to see if a guild is available before performing operations or reading data from it. You can
|
16
|
+
* check this with `guild.available`.</info>
|
17
|
+
*/
|
18
|
+
class Guild {
|
19
|
+
constructor(client, data) {
|
20
|
+
/**
|
21
|
+
* The client that created the instance of the guild
|
22
|
+
* @name Guild#client
|
23
|
+
* @type {Client}
|
24
|
+
* @readonly
|
25
|
+
*/
|
26
|
+
Object.defineProperty(this, 'client', { value: client });
|
27
|
+
|
28
|
+
/**
|
29
|
+
* A collection of members that are in this guild. The key is the member's ID, the value is the member
|
30
|
+
* @type {Collection<Snowflake, GuildMember>}
|
31
|
+
*/
|
32
|
+
this.members = new Collection();
|
33
|
+
|
34
|
+
/**
|
35
|
+
* A collection of channels that are in this guild. The key is the channel's ID, the value is the channel
|
36
|
+
* @type {Collection<Snowflake, GuildChannel>}
|
37
|
+
*/
|
38
|
+
this.channels = new Collection();
|
39
|
+
|
40
|
+
/**
|
41
|
+
* A collection of roles that are in this guild. The key is the role's ID, the value is the role
|
42
|
+
* @type {Collection<Snowflake, Role>}
|
43
|
+
*/
|
44
|
+
this.roles = new Collection();
|
45
|
+
|
46
|
+
/**
|
47
|
+
* A collection of presences in this guild
|
48
|
+
* @type {Collection<Snowflake, Presence>}
|
49
|
+
*/
|
50
|
+
this.presences = new Collection();
|
51
|
+
|
52
|
+
/**
|
53
|
+
* Whether the bot has been removed from the guild
|
54
|
+
* @type {boolean}
|
55
|
+
*/
|
56
|
+
this.deleted = false;
|
57
|
+
|
58
|
+
if (!data) return;
|
59
|
+
if (data.unavailable) {
|
60
|
+
/**
|
61
|
+
* Whether the guild is available to access. If it is not available, it indicates a server outage
|
62
|
+
* @type {boolean}
|
63
|
+
*/
|
64
|
+
this.available = false;
|
65
|
+
|
66
|
+
/**
|
67
|
+
* The Unique ID of the guild, useful for comparisons
|
68
|
+
* @type {Snowflake}
|
69
|
+
*/
|
70
|
+
this.id = data.id;
|
71
|
+
} else {
|
72
|
+
this.setup(data);
|
73
|
+
if (!data.channels) this.available = false;
|
74
|
+
}
|
75
|
+
}
|
76
|
+
|
77
|
+
/* eslint-disable complexity */
|
78
|
+
/**
|
79
|
+
* Sets up the guild.
|
80
|
+
* @param {*} data The raw data of the guild
|
81
|
+
* @private
|
82
|
+
*/
|
83
|
+
setup(data) {
|
84
|
+
/**
|
85
|
+
* The name of the guild
|
86
|
+
* @type {string}
|
87
|
+
*/
|
88
|
+
this.name = data.name;
|
89
|
+
|
90
|
+
/**
|
91
|
+
* The hash of the guild icon
|
92
|
+
* @type {?string}
|
93
|
+
*/
|
94
|
+
this.icon = data.icon;
|
95
|
+
|
96
|
+
/**
|
97
|
+
* The hash of the guild splash image (VIP only)
|
98
|
+
* @type {?string}
|
99
|
+
*/
|
100
|
+
this.splash = data.splash;
|
101
|
+
|
102
|
+
/**
|
103
|
+
* The region the guild is located in
|
104
|
+
* @type {string}
|
105
|
+
*/
|
106
|
+
this.region = data.region;
|
107
|
+
|
108
|
+
/**
|
109
|
+
* The full amount of members in this guild
|
110
|
+
* @type {number}
|
111
|
+
*/
|
112
|
+
this.memberCount = data.member_count || this.memberCount;
|
113
|
+
|
114
|
+
/**
|
115
|
+
* Whether the guild is "large" (has more than 250 members)
|
116
|
+
* @type {boolean}
|
117
|
+
*/
|
118
|
+
this.large = Boolean('large' in data ? data.large : this.large);
|
119
|
+
|
120
|
+
/**
|
121
|
+
* An array of guild features
|
122
|
+
* @type {Object[]}
|
123
|
+
*/
|
124
|
+
this.features = data.features;
|
125
|
+
|
126
|
+
/**
|
127
|
+
* The ID of the application that created this guild (if applicable)
|
128
|
+
* @type {?Snowflake}
|
129
|
+
*/
|
130
|
+
this.applicationID = data.application_id;
|
131
|
+
|
132
|
+
/**
|
133
|
+
* The time in seconds before a user is counted as "away from keyboard"
|
134
|
+
* @type {?number}
|
135
|
+
*/
|
136
|
+
this.afkTimeout = data.afk_timeout;
|
137
|
+
|
138
|
+
/**
|
139
|
+
* The ID of the voice channel where AFK members are moved
|
140
|
+
* @type {?string}
|
141
|
+
*/
|
142
|
+
this.afkChannelID = data.afk_channel_id;
|
143
|
+
|
144
|
+
/**
|
145
|
+
* The ID of the system channel
|
146
|
+
* @type {?Snowflake}
|
147
|
+
*/
|
148
|
+
this.systemChannelID = data.system_channel_id;
|
149
|
+
|
150
|
+
/**
|
151
|
+
* Whether embedded images are enabled on this guild
|
152
|
+
* @type {boolean}
|
153
|
+
*/
|
154
|
+
this.embedEnabled = data.embed_enabled;
|
155
|
+
|
156
|
+
/**
|
157
|
+
* The verification level of the guild
|
158
|
+
* @type {number}
|
159
|
+
*/
|
160
|
+
this.verificationLevel = data.verification_level;
|
161
|
+
|
162
|
+
/**
|
163
|
+
* The explicit content filter level of the guild
|
164
|
+
* @type {number}
|
165
|
+
*/
|
166
|
+
this.explicitContentFilter = data.explicit_content_filter;
|
167
|
+
|
168
|
+
/**
|
169
|
+
* The required MFA level for the guild
|
170
|
+
* @type {number}
|
171
|
+
*/
|
172
|
+
this.mfaLevel = data.mfa_level;
|
173
|
+
|
174
|
+
/**
|
175
|
+
* The timestamp the client user joined the guild at
|
176
|
+
* @type {number}
|
177
|
+
*/
|
178
|
+
this.joinedTimestamp = data.joined_at ? new Date(data.joined_at).getTime() : this.joinedTimestamp;
|
179
|
+
|
180
|
+
/**
|
181
|
+
* The value set for a guild's default message notifications
|
182
|
+
* @type {DefaultMessageNotifications|number}
|
183
|
+
*/
|
184
|
+
this.defaultMessageNotifications = Constants.DefaultMessageNotifications[data.default_message_notifications] ||
|
185
|
+
data.default_message_notifications;
|
186
|
+
|
187
|
+
this.id = data.id;
|
188
|
+
this.available = !data.unavailable;
|
189
|
+
this.features = data.features || this.features || [];
|
190
|
+
|
191
|
+
if (data.members) {
|
192
|
+
this.members.clear();
|
193
|
+
for (const guildUser of data.members) this._addMember(guildUser, false);
|
194
|
+
}
|
195
|
+
|
196
|
+
if (data.owner_id) {
|
197
|
+
/**
|
198
|
+
* The user ID of this guild's owner
|
199
|
+
* @type {Snowflake}
|
200
|
+
*/
|
201
|
+
this.ownerID = data.owner_id;
|
202
|
+
}
|
203
|
+
|
204
|
+
if (data.channels) {
|
205
|
+
this.channels.clear();
|
206
|
+
for (const channel of data.channels) this.client.dataManager.newChannel(channel, this);
|
207
|
+
}
|
208
|
+
|
209
|
+
if (data.roles) {
|
210
|
+
this.roles.clear();
|
211
|
+
for (const role of data.roles) {
|
212
|
+
const newRole = new Role(this, role);
|
213
|
+
this.roles.set(newRole.id, newRole);
|
214
|
+
}
|
215
|
+
}
|
216
|
+
|
217
|
+
if (data.presences) {
|
218
|
+
for (const presence of data.presences) {
|
219
|
+
this._setPresence(presence.user.id, presence);
|
220
|
+
}
|
221
|
+
}
|
222
|
+
|
223
|
+
this._rawVoiceStates = new Collection();
|
224
|
+
if (data.voice_states) {
|
225
|
+
for (const voiceState of data.voice_states) {
|
226
|
+
this._rawVoiceStates.set(voiceState.user_id, voiceState);
|
227
|
+
const member = this.members.get(voiceState.user_id);
|
228
|
+
const voiceChannel = this.channels.get(voiceState.channel_id);
|
229
|
+
if (member && voiceChannel) {
|
230
|
+
member.serverMute = voiceState.mute;
|
231
|
+
member.serverDeaf = voiceState.deaf;
|
232
|
+
member.selfMute = voiceState.self_mute;
|
233
|
+
member.selfDeaf = voiceState.self_deaf;
|
234
|
+
member.voiceSessionID = voiceState.session_id;
|
235
|
+
member.voiceChannelID = voiceState.channel_id;
|
236
|
+
voiceChannel.members.set(member.user.id, member);
|
237
|
+
}
|
238
|
+
}
|
239
|
+
}
|
240
|
+
|
241
|
+
if (!this.emojis) {
|
242
|
+
/**
|
243
|
+
* A collection of emojis that are in this guild
|
244
|
+
* The key is the emoji's ID, the value is the emoji
|
245
|
+
* @type {Collection<Snowflake, Emoji>}
|
246
|
+
*/
|
247
|
+
this.emojis = new Collection();
|
248
|
+
for (const emoji of data.emojis) this.emojis.set(emoji.id, new Emoji(this, emoji));
|
249
|
+
} else {
|
250
|
+
this.client.actions.GuildEmojisUpdate.handle({
|
251
|
+
guild_id: this.id,
|
252
|
+
emojis: data.emojis,
|
253
|
+
});
|
254
|
+
}
|
255
|
+
}
|
256
|
+
|
257
|
+
/**
|
258
|
+
* The timestamp the guild was created at
|
259
|
+
* @type {number}
|
260
|
+
* @readonly
|
261
|
+
*/
|
262
|
+
get createdTimestamp() {
|
263
|
+
return Snowflake.deconstruct(this.id).timestamp;
|
264
|
+
}
|
265
|
+
|
266
|
+
/**
|
267
|
+
* The time the guild was created
|
268
|
+
* @type {Date}
|
269
|
+
* @readonly
|
270
|
+
*/
|
271
|
+
get createdAt() {
|
272
|
+
return new Date(this.createdTimestamp);
|
273
|
+
}
|
274
|
+
|
275
|
+
/**
|
276
|
+
* The time the client user joined the guild
|
277
|
+
* @type {Date}
|
278
|
+
* @readonly
|
279
|
+
*/
|
280
|
+
get joinedAt() {
|
281
|
+
return new Date(this.joinedTimestamp);
|
282
|
+
}
|
283
|
+
|
284
|
+
/**
|
285
|
+
* If this guild is verified
|
286
|
+
* @type {boolean}
|
287
|
+
* @readonly
|
288
|
+
*/
|
289
|
+
get verified() {
|
290
|
+
return this.features.includes('VERIFIED');
|
291
|
+
}
|
292
|
+
|
293
|
+
/**
|
294
|
+
* The URL to this guild's icon
|
295
|
+
* @type {?string}
|
296
|
+
* @readonly
|
297
|
+
*/
|
298
|
+
get iconURL() {
|
299
|
+
if (!this.icon) return null;
|
300
|
+
return Constants.Endpoints.Guild(this).Icon(this.client.options.http.cdn, this.icon);
|
301
|
+
}
|
302
|
+
|
303
|
+
/**
|
304
|
+
* The acronym that shows up in place of a guild icon.
|
305
|
+
* @type {string}
|
306
|
+
* @readonly
|
307
|
+
*/
|
308
|
+
get nameAcronym() {
|
309
|
+
return this.name.replace(/\w+/g, name => name[0]).replace(/\s/g, '');
|
310
|
+
}
|
311
|
+
|
312
|
+
/**
|
313
|
+
* The URL to this guild's splash
|
314
|
+
* @type {?string}
|
315
|
+
* @readonly
|
316
|
+
*/
|
317
|
+
get splashURL() {
|
318
|
+
if (!this.splash) return null;
|
319
|
+
return Constants.Endpoints.Guild(this).Splash(this.client.options.http.cdn, this.splash);
|
320
|
+
}
|
321
|
+
|
322
|
+
/**
|
323
|
+
* The owner of the guild
|
324
|
+
* @type {?GuildMember}
|
325
|
+
* @readonly
|
326
|
+
*/
|
327
|
+
get owner() {
|
328
|
+
return this.members.get(this.ownerID);
|
329
|
+
}
|
330
|
+
|
331
|
+
/**
|
332
|
+
* AFK voice channel for this guild
|
333
|
+
* @type {?VoiceChannel}
|
334
|
+
* @readonly
|
335
|
+
*/
|
336
|
+
get afkChannel() {
|
337
|
+
return this.client.channels.get(this.afkChannelID) || null;
|
338
|
+
}
|
339
|
+
|
340
|
+
/**
|
341
|
+
* System channel for this guild
|
342
|
+
* @type {?GuildChannel}
|
343
|
+
* @readonly
|
344
|
+
*/
|
345
|
+
get systemChannel() {
|
346
|
+
return this.client.channels.get(this.systemChannelID) || null;
|
347
|
+
}
|
348
|
+
|
349
|
+
/**
|
350
|
+
* If the client is connected to any voice channel in this guild, this will be the relevant VoiceConnection
|
351
|
+
* @type {?VoiceConnection}
|
352
|
+
* @readonly
|
353
|
+
*/
|
354
|
+
get voiceConnection() {
|
355
|
+
if (this.client.browser) return null;
|
356
|
+
return this.client.voice.connections.get(this.id) || null;
|
357
|
+
}
|
358
|
+
|
359
|
+
/**
|
360
|
+
* The position of this guild
|
361
|
+
* <warn>This is only available when using a user account.</warn>
|
362
|
+
* @type {?number}
|
363
|
+
* @readonly
|
364
|
+
* @deprecated
|
365
|
+
*/
|
366
|
+
get position() {
|
367
|
+
if (this.client.user.bot) return null;
|
368
|
+
if (!this.client.user.settings.guildPositions) return null;
|
369
|
+
return this.client.user.settings.guildPositions.indexOf(this.id);
|
370
|
+
}
|
371
|
+
|
372
|
+
/**
|
373
|
+
* Whether the guild is muted
|
374
|
+
* <warn>This is only available when using a user account.</warn>
|
375
|
+
* @type {?boolean}
|
376
|
+
* @readonly
|
377
|
+
* @deprecated
|
378
|
+
*/
|
379
|
+
get muted() {
|
380
|
+
if (this.client.user.bot) return null;
|
381
|
+
try {
|
382
|
+
return this.client.user.guildSettings.get(this.id).muted;
|
383
|
+
} catch (err) {
|
384
|
+
return false;
|
385
|
+
}
|
386
|
+
}
|
387
|
+
|
388
|
+
/**
|
389
|
+
* The type of message that should notify you
|
390
|
+
* <warn>This is only available when using a user account.</warn>
|
391
|
+
* @type {?MessageNotificationType}
|
392
|
+
* @readonly
|
393
|
+
* @deprecated
|
394
|
+
*/
|
395
|
+
get messageNotifications() {
|
396
|
+
if (this.client.user.bot) return null;
|
397
|
+
try {
|
398
|
+
return this.client.user.guildSettings.get(this.id).messageNotifications;
|
399
|
+
} catch (err) {
|
400
|
+
return null;
|
401
|
+
}
|
402
|
+
}
|
403
|
+
|
404
|
+
/**
|
405
|
+
* Whether to receive mobile push notifications
|
406
|
+
* <warn>This is only available when using a user account.</warn>
|
407
|
+
* @type {?boolean}
|
408
|
+
* @readonly
|
409
|
+
* @deprecated
|
410
|
+
*/
|
411
|
+
get mobilePush() {
|
412
|
+
if (this.client.user.bot) return null;
|
413
|
+
try {
|
414
|
+
return this.client.user.guildSettings.get(this.id).mobilePush;
|
415
|
+
} catch (err) {
|
416
|
+
return false;
|
417
|
+
}
|
418
|
+
}
|
419
|
+
|
420
|
+
/**
|
421
|
+
* Whether to suppress everyone messages
|
422
|
+
* <warn>This is only available when using a user account.</warn>
|
423
|
+
* @type {?boolean}
|
424
|
+
* @readonly
|
425
|
+
* @deprecated
|
426
|
+
*/
|
427
|
+
get suppressEveryone() {
|
428
|
+
if (this.client.user.bot) return null;
|
429
|
+
try {
|
430
|
+
return this.client.user.guildSettings.get(this.id).suppressEveryone;
|
431
|
+
} catch (err) {
|
432
|
+
return null;
|
433
|
+
}
|
434
|
+
}
|
435
|
+
|
436
|
+
/**
|
437
|
+
* The `@everyone` role of the guild
|
438
|
+
* @type {Role}
|
439
|
+
* @readonly
|
440
|
+
*/
|
441
|
+
get defaultRole() {
|
442
|
+
return this.roles.get(this.id);
|
443
|
+
}
|
444
|
+
|
445
|
+
/**
|
446
|
+
* The client user as a GuildMember of this guild
|
447
|
+
* @type {?GuildMember}
|
448
|
+
* @readonly
|
449
|
+
*/
|
450
|
+
get me() {
|
451
|
+
return this.members.get(this.client.user.id);
|
452
|
+
}
|
453
|
+
|
454
|
+
/**
|
455
|
+
* Fetches a collection of roles in the current guild sorted by position
|
456
|
+
* @type {Collection<Snowflake, Role>}
|
457
|
+
* @readonly
|
458
|
+
* @private
|
459
|
+
*/
|
460
|
+
get _sortedRoles() {
|
461
|
+
return this._sortPositionWithID(this.roles);
|
462
|
+
}
|
463
|
+
|
464
|
+
/**
|
465
|
+
* Returns the GuildMember form of a User object, if the user is present in the guild.
|
466
|
+
* @param {UserResolvable} user The user that you want to obtain the GuildMember of
|
467
|
+
* @returns {?GuildMember}
|
468
|
+
* @example
|
469
|
+
* // Get the guild member of a user
|
470
|
+
* const member = guild.member(message.author);
|
471
|
+
*/
|
472
|
+
member(user) {
|
473
|
+
return this.client.resolver.resolveGuildMember(this, user);
|
474
|
+
}
|
475
|
+
|
476
|
+
/**
|
477
|
+
* An object containing information about a guild member's ban.
|
478
|
+
* @typedef {Object} BanInfo
|
479
|
+
* @property {User} user User that was banned
|
480
|
+
* @property {?string} reason Reason the user was banned
|
481
|
+
*/
|
482
|
+
|
483
|
+
/**
|
484
|
+
* Fetch a ban for a user.
|
485
|
+
* @returns {Promise<BanInfo>}
|
486
|
+
* @param {UserResolvable} user The user to fetch the ban for
|
487
|
+
* @example
|
488
|
+
* // Get ban
|
489
|
+
* guild.fetchBan(message.author)
|
490
|
+
* .then(({ user, reason }) => console.log(`${user.tag} was banned for the reason: ${reason}.`))
|
491
|
+
* .catch(console.error);
|
492
|
+
*/
|
493
|
+
fetchBan(user) {
|
494
|
+
return this.client.rest.methods.getGuildBan(this, user);
|
495
|
+
}
|
496
|
+
|
497
|
+
/**
|
498
|
+
* Fetch a collection of banned users in this guild.
|
499
|
+
* @returns {Promise<Collection<Snowflake, User|BanInfo>>}
|
500
|
+
* @param {boolean} [withReasons=false] Whether or not to include the ban reason(s)
|
501
|
+
* @example
|
502
|
+
* // Fetch bans in guild
|
503
|
+
* guild.fetchBans()
|
504
|
+
* .then(bans => console.log(`This guild has ${bans.size} bans`))
|
505
|
+
* .catch(console.error);
|
506
|
+
*/
|
507
|
+
fetchBans(withReasons = false) {
|
508
|
+
if (withReasons) return this.client.rest.methods.getGuildBans(this);
|
509
|
+
return this.client.rest.methods.getGuildBans(this)
|
510
|
+
.then(bans => {
|
511
|
+
const users = new Collection();
|
512
|
+
for (const ban of bans.values()) users.set(ban.user.id, ban.user);
|
513
|
+
return users;
|
514
|
+
});
|
515
|
+
}
|
516
|
+
|
517
|
+
/**
|
518
|
+
* Fetch a collection of invites to this guild.
|
519
|
+
* Resolves with a collection mapping invites by their codes.
|
520
|
+
* @returns {Promise<Collection<string, Invite>>}
|
521
|
+
* @example
|
522
|
+
* // Fetch invites
|
523
|
+
* guild.fetchInvites()
|
524
|
+
* .then(invites => console.log(`Fetched ${invites.size} invites`))
|
525
|
+
* .catch(console.error);
|
526
|
+
* @example
|
527
|
+
* // Fetch invite creator by their id
|
528
|
+
* guild.fetchInvites()
|
529
|
+
* .then(invites => console.log(invites.find(invite => invite.inviter.id === '84484653687267328')))
|
530
|
+
* .catch(console.error);
|
531
|
+
*/
|
532
|
+
fetchInvites() {
|
533
|
+
return this.client.rest.methods.getGuildInvites(this);
|
534
|
+
}
|
535
|
+
|
536
|
+
/**
|
537
|
+
* Fetches the vanity url invite code to this guild.
|
538
|
+
* Resolves with a string matching the vanity url invite code, not the full url.
|
539
|
+
* @returns {Promise<string>}
|
540
|
+
* @example
|
541
|
+
* // Fetch invites
|
542
|
+
* guild.fetchVanityCode()
|
543
|
+
* .then(code => {
|
544
|
+
* console.log(`Vanity URL: https://discord.gg/${code}`);
|
545
|
+
* })
|
546
|
+
* .catch(console.error);
|
547
|
+
*/
|
548
|
+
fetchVanityCode() {
|
549
|
+
if (!this.features.includes('VANITY_URL')) {
|
550
|
+
return Promise.reject(new Error('This guild does not have the VANITY_URL feature enabled.'));
|
551
|
+
}
|
552
|
+
return this.client.rest.methods.getGuildVanityCode(this);
|
553
|
+
}
|
554
|
+
|
555
|
+
|
556
|
+
/**
|
557
|
+
* Fetch all webhooks for the guild.
|
558
|
+
* @returns {Promise<Collection<Snowflake, Webhook>>}
|
559
|
+
* @example
|
560
|
+
* // Fetch webhooks
|
561
|
+
* guild.fetchWebhooks()
|
562
|
+
* .then(webhooks => console.log(`Fetched ${webhooks.size} webhooks`))
|
563
|
+
* .catch(console.error);
|
564
|
+
*/
|
565
|
+
fetchWebhooks() {
|
566
|
+
return this.client.rest.methods.getGuildWebhooks(this);
|
567
|
+
}
|
568
|
+
|
569
|
+
/**
|
570
|
+
* Fetch available voice regions.
|
571
|
+
* @returns {Promise<Collection<string, VoiceRegion>>}
|
572
|
+
* @example
|
573
|
+
* // Fetch voice regions
|
574
|
+
* guild.fetchVoiceRegions()
|
575
|
+
* .then(console.log)
|
576
|
+
* .catch(console.error);
|
577
|
+
*/
|
578
|
+
fetchVoiceRegions() {
|
579
|
+
return this.client.rest.methods.fetchVoiceRegions(this.id);
|
580
|
+
}
|
581
|
+
|
582
|
+
/**
|
583
|
+
* The Guild Embed object
|
584
|
+
* @typedef {Object} GuildEmbedData
|
585
|
+
* @property {boolean} enabled Whether the embed is enabled
|
586
|
+
* @property {?ChannelResolvable} channel The embed channel
|
587
|
+
*/
|
588
|
+
|
589
|
+
/**
|
590
|
+
* Fetches the guild embed.
|
591
|
+
* @returns {Promise<GuildEmbedData>}
|
592
|
+
* @example
|
593
|
+
* // Fetches the guild embed
|
594
|
+
* guild.fetchEmbed()
|
595
|
+
* .then(embed => console.log(`The embed is ${embed.enabled ? 'enabled' : 'disabled'}`))
|
596
|
+
* .catch(console.error);
|
597
|
+
*/
|
598
|
+
fetchEmbed() {
|
599
|
+
return this.client.rest.methods.fetchEmbed(this.id);
|
600
|
+
}
|
601
|
+
|
602
|
+
/**
|
603
|
+
* Fetch audit logs for this guild.
|
604
|
+
* @param {Object} [options={}] Options for fetching audit logs
|
605
|
+
* @param {Snowflake|GuildAuditLogsEntry} [options.before] Limit to entries from before specified entry
|
606
|
+
* @param {Snowflake|GuildAuditLogsEntry} [options.after] Limit to entries from after specified entry
|
607
|
+
* @param {number} [options.limit] Limit number of entries
|
608
|
+
* @param {UserResolvable} [options.user] Only show entries involving this user
|
609
|
+
* @param {AuditLogAction} [options.type] Only show entries involving this action type
|
610
|
+
* @returns {Promise<GuildAuditLogs>}
|
611
|
+
* @example
|
612
|
+
* // Output audit log entries
|
613
|
+
* guild.fetchAuditLogs()
|
614
|
+
* .then(audit => console.log(audit.entries.first()))
|
615
|
+
* .catch(console.error);
|
616
|
+
*/
|
617
|
+
fetchAuditLogs(options) {
|
618
|
+
return this.client.rest.methods.getGuildAuditLogs(this, options);
|
619
|
+
}
|
620
|
+
|
621
|
+
/**
|
622
|
+
* Adds a user to the guild using OAuth2. Requires the `CREATE_INSTANT_INVITE` permission.
|
623
|
+
* @param {UserResolvable} user User to add to the guild
|
624
|
+
* @param {Object} options Options for the addition
|
625
|
+
* @param {string} options.accessToken An OAuth2 access token for the user with the `guilds.join` scope granted to the
|
626
|
+
* bot's application
|
627
|
+
* @param {string} [options.nick] Nickname to give the member (requires `MANAGE_NICKNAMES`)
|
628
|
+
* @param {Collection<Snowflake, Role>|Role[]|Snowflake[]} [options.roles] Roles to add to the member
|
629
|
+
* (requires `MANAGE_ROLES`)
|
630
|
+
* @param {boolean} [options.mute] Whether the member should be muted (requires `MUTE_MEMBERS`)
|
631
|
+
* @param {boolean} [options.deaf] Whether the member should be deafened (requires `DEAFEN_MEMBERS`)
|
632
|
+
* @returns {Promise<GuildMember>}
|
633
|
+
*/
|
634
|
+
addMember(user, options) {
|
635
|
+
user = this.client.resolver.resolveUserID(user);
|
636
|
+
if (this.members.has(user)) return Promise.resolve(this.members.get(user));
|
637
|
+
return this.client.rest.methods.putGuildMember(this, user, options);
|
638
|
+
}
|
639
|
+
|
640
|
+
/**
|
641
|
+
* Fetch a single guild member from a user.
|
642
|
+
* @param {UserResolvable} user The user to fetch the member for
|
643
|
+
* @param {boolean} [cache=true] Insert the member into the members cache
|
644
|
+
* @returns {Promise<GuildMember>}
|
645
|
+
* @example
|
646
|
+
* // Fetch a guild member
|
647
|
+
* guild.fetchMember(message.author)
|
648
|
+
* .then(console.log)
|
649
|
+
* .catch(console.error);
|
650
|
+
*/
|
651
|
+
fetchMember(user, cache = true) {
|
652
|
+
user = this.client.resolver.resolveUser(user);
|
653
|
+
if (!user) return Promise.reject(new Error('Invalid or uncached id provided.'));
|
654
|
+
const member = this.members.get(user.id);
|
655
|
+
if (member && member.joinedTimestamp) return Promise.resolve(member);
|
656
|
+
return this.client.rest.methods.getGuildMember(this, user, cache);
|
657
|
+
}
|
658
|
+
|
659
|
+
/**
|
660
|
+
* Fetches all the members in the guild, even if they are offline. If the guild has less than 250 members,
|
661
|
+
* this should not be necessary.
|
662
|
+
* @param {string} [query=''] Limit fetch to members with similar usernames
|
663
|
+
* @param {number} [limit=0] Maximum number of members to request
|
664
|
+
* @returns {Promise<Guild>}
|
665
|
+
* @example
|
666
|
+
* // Fetch guild members
|
667
|
+
* guild.fetchMembers()
|
668
|
+
* .then(console.log)
|
669
|
+
* .catch(console.error);
|
670
|
+
* @example
|
671
|
+
* // Fetches a maximum of 1 member with the given query
|
672
|
+
* guild.fetchMembers('hydrabolt', 1)
|
673
|
+
* .then(console.log)
|
674
|
+
* .catch(console.error);
|
675
|
+
*/
|
676
|
+
fetchMembers(query = '', limit = 0) {
|
677
|
+
return new Promise((resolve, reject) => {
|
678
|
+
if (this.memberCount === this.members.size) {
|
679
|
+
resolve(this);
|
680
|
+
return;
|
681
|
+
}
|
682
|
+
this.client.ws.send({
|
683
|
+
op: Constants.OPCodes.REQUEST_GUILD_MEMBERS,
|
684
|
+
d: {
|
685
|
+
guild_id: this.id,
|
686
|
+
query,
|
687
|
+
limit,
|
688
|
+
},
|
689
|
+
});
|
690
|
+
const handler = (members, guild) => {
|
691
|
+
if (guild.id !== this.id) return;
|
692
|
+
if (this.memberCount === this.members.size || members.length < 1000) {
|
693
|
+
this.client.removeListener(Constants.Events.GUILD_MEMBERS_CHUNK, handler);
|
694
|
+
resolve(this);
|
695
|
+
}
|
696
|
+
};
|
697
|
+
this.client.on(Constants.Events.GUILD_MEMBERS_CHUNK, handler);
|
698
|
+
this.client.setTimeout(() => reject(new Error('Members didn\'t arrive in time.')), 120 * 1000);
|
699
|
+
});
|
700
|
+
}
|
701
|
+
|
702
|
+
/**
|
703
|
+
* Performs a search within the entire guild.
|
704
|
+
* <warn>This is only available when using a user account.</warn>
|
705
|
+
* @param {MessageSearchOptions} [options={}] Options to pass to the search
|
706
|
+
* @returns {Promise<MessageSearchResult>}
|
707
|
+
* @deprecated
|
708
|
+
* @example
|
709
|
+
* guild.search({
|
710
|
+
* content: 'discord.js',
|
711
|
+
* before: '2016-11-17'
|
712
|
+
* })
|
713
|
+
* .then(res => {
|
714
|
+
* const hit = res.messages[0].find(m => m.hit).content;
|
715
|
+
* console.log(`I found: **${hit}**, total results: ${res.totalResults}`);
|
716
|
+
* })
|
717
|
+
* .catch(console.error);
|
718
|
+
*/
|
719
|
+
search(options = {}) {
|
720
|
+
return this.client.rest.methods.search(this, options);
|
721
|
+
}
|
722
|
+
|
723
|
+
/**
|
724
|
+
* The data for editing a guild.
|
725
|
+
* @typedef {Object} GuildEditData
|
726
|
+
* @property {string} [name] The name of the guild
|
727
|
+
* @property {string} [region] The region of the guild
|
728
|
+
* @property {number} [verificationLevel] The verification level of the guild
|
729
|
+
* @property {number} [explicitContentFilter] The level of the explicit content filter
|
730
|
+
* @property {ChannelResolvable} [afkChannel] The AFK channel of the guild
|
731
|
+
* @property {ChannelResolvable} [systemChannel] The system channel of the guild
|
732
|
+
* @property {number} [afkTimeout] The AFK timeout of the guild
|
733
|
+
* @property {Base64Resolvable} [icon] The icon of the guild
|
734
|
+
* @property {GuildMemberResolvable} [owner] The owner of the guild
|
735
|
+
* @property {Base64Resolvable} [splash] The splash screen of the guild
|
736
|
+
*/
|
737
|
+
|
738
|
+
/**
|
739
|
+
* Updates the guild with new information - e.g. a new name.
|
740
|
+
* @param {GuildEditData} data The data to update the guild with
|
741
|
+
* @param {string} [reason] Reason for editing the guild
|
742
|
+
* @returns {Promise<Guild>}
|
743
|
+
* @example
|
744
|
+
* // Set the guild name and region
|
745
|
+
* guild.edit({
|
746
|
+
* name: 'Discord Guild',
|
747
|
+
* region: 'london',
|
748
|
+
* })
|
749
|
+
* .then(g => console.log(`Changed guild name to ${g} and region to ${g.region}`))
|
750
|
+
* .catch(console.error);
|
751
|
+
*/
|
752
|
+
edit(data, reason) {
|
753
|
+
const _data = {};
|
754
|
+
if (data.name) _data.name = data.name;
|
755
|
+
if (data.region) _data.region = data.region;
|
756
|
+
if (typeof data.verificationLevel !== 'undefined') _data.verification_level = Number(data.verificationLevel);
|
757
|
+
if (typeof data.afkChannel !== 'undefined') {
|
758
|
+
_data.afk_channel_id = this.client.resolver.resolveChannelID(data.afkChannel);
|
759
|
+
}
|
760
|
+
if (typeof data.systemChannel !== 'undefined') {
|
761
|
+
_data.system_channel_id = this.client.resolver.resolveChannelID(data.systemChannel);
|
762
|
+
}
|
763
|
+
if (data.afkTimeout) _data.afk_timeout = Number(data.afkTimeout);
|
764
|
+
if (typeof data.icon !== 'undefined') _data.icon = data.icon;
|
765
|
+
if (data.owner) _data.owner_id = this.client.resolver.resolveUser(data.owner).id;
|
766
|
+
if (typeof data.splash !== 'undefined') _data.splash = data.splash;
|
767
|
+
if (typeof data.explicitContentFilter !== 'undefined') {
|
768
|
+
_data.explicit_content_filter = Number(data.explicitContentFilter);
|
769
|
+
}
|
770
|
+
if (typeof data.defaultMessageNotifications !== 'undefined') {
|
771
|
+
_data.default_message_notifications = typeof data.defaultMessageNotifications === 'string' ?
|
772
|
+
Constants.DefaultMessageNotifications.indexOf(data.defaultMessageNotifications) :
|
773
|
+
Number(data.defaultMessageNotifications);
|
774
|
+
}
|
775
|
+
return this.client.rest.methods.updateGuild(this, _data, reason);
|
776
|
+
}
|
777
|
+
|
778
|
+
/**
|
779
|
+
* Edit the level of the explicit content filter.
|
780
|
+
* @param {number} explicitContentFilter The new level of the explicit content filter
|
781
|
+
* @param {string} [reason] Reason for changing the level of the guild's explicit content filter
|
782
|
+
* @returns {Promise<Guild>}
|
783
|
+
*/
|
784
|
+
setExplicitContentFilter(explicitContentFilter, reason) {
|
785
|
+
return this.edit({ explicitContentFilter }, reason);
|
786
|
+
}
|
787
|
+
|
788
|
+
/**
|
789
|
+
* Edits the setting of the default message notifications of the guild.
|
790
|
+
* @param {DefaultMessageNotifications|number} defaultMessageNotifications
|
791
|
+
* The new setting for the default message notifications
|
792
|
+
* @param {string} [reason] Reason for changing the setting of the default message notifications
|
793
|
+
* @returns {Promise<Guild>}
|
794
|
+
*/
|
795
|
+
setDefaultMessageNotifications(defaultMessageNotifications, reason) {
|
796
|
+
return this.edit({ defaultMessageNotifications }, reason);
|
797
|
+
}
|
798
|
+
|
799
|
+
/**
|
800
|
+
* Edit the name of the guild.
|
801
|
+
* @param {string} name The new name of the guild
|
802
|
+
* @param {string} [reason] Reason for changing the guild's name
|
803
|
+
* @returns {Promise<Guild>}
|
804
|
+
* @example
|
805
|
+
* // Edit the guild name
|
806
|
+
* guild.setName('Discord Guild')
|
807
|
+
* .then(g => console.log(`Updated guild name to ${g}`))
|
808
|
+
* .catch(console.error);
|
809
|
+
*/
|
810
|
+
setName(name, reason) {
|
811
|
+
return this.edit({ name }, reason);
|
812
|
+
}
|
813
|
+
|
814
|
+
/**
|
815
|
+
* Edit the region of the guild.
|
816
|
+
* @param {string} region The new region of the guild
|
817
|
+
* @param {string} [reason] Reason for changing the guild's region
|
818
|
+
* @returns {Promise<Guild>}
|
819
|
+
* @example
|
820
|
+
* // Edit the guild region
|
821
|
+
* guild.setRegion('london')
|
822
|
+
* .then(g => console.log(`Updated guild region to ${g.region}`))
|
823
|
+
* .catch(console.error);
|
824
|
+
*/
|
825
|
+
setRegion(region, reason) {
|
826
|
+
return this.edit({ region }, reason);
|
827
|
+
}
|
828
|
+
|
829
|
+
/**
|
830
|
+
* Edit the verification level of the guild.
|
831
|
+
* @param {number} verificationLevel The new verification level of the guild
|
832
|
+
* @param {string} [reason] Reason for changing the guild's verification level
|
833
|
+
* @returns {Promise<Guild>}
|
834
|
+
* @example
|
835
|
+
* // Edit the guild verification level
|
836
|
+
* guild.setVerificationLevel(1)
|
837
|
+
* .then(g => console.log(`Updated guild verification level to ${g.verificationLevel}`))
|
838
|
+
* .catch(console.error);
|
839
|
+
*/
|
840
|
+
setVerificationLevel(verificationLevel, reason) {
|
841
|
+
return this.edit({ verificationLevel }, reason);
|
842
|
+
}
|
843
|
+
|
844
|
+
/**
|
845
|
+
* Edit the AFK channel of the guild.
|
846
|
+
* @param {ChannelResolvable} afkChannel The new AFK channel
|
847
|
+
* @param {string} [reason] Reason for changing the guild's AFK channel
|
848
|
+
* @returns {Promise<Guild>}
|
849
|
+
* @example
|
850
|
+
* // Edit the guild AFK channel
|
851
|
+
* guild.setAFKChannel(channel)
|
852
|
+
* .then(g => console.log(`Updated guild AFK channel to ${g.afkChannel.name}`))
|
853
|
+
* .catch(console.error);
|
854
|
+
*/
|
855
|
+
setAFKChannel(afkChannel, reason) {
|
856
|
+
return this.edit({ afkChannel }, reason);
|
857
|
+
}
|
858
|
+
|
859
|
+
/**
|
860
|
+
* Edit the system channel of the guild.
|
861
|
+
* @param {ChannelResolvable} systemChannel The new system channel
|
862
|
+
* @param {string} [reason] Reason for changing the guild's system channel
|
863
|
+
* @returns {Promise<Guild>}
|
864
|
+
*/
|
865
|
+
setSystemChannel(systemChannel, reason) {
|
866
|
+
return this.edit({ systemChannel }, reason);
|
867
|
+
}
|
868
|
+
|
869
|
+
/**
|
870
|
+
* Edit the AFK timeout of the guild.
|
871
|
+
* @param {number} afkTimeout The time in seconds that a user must be idle to be considered AFK
|
872
|
+
* @param {string} [reason] Reason for changing the guild's AFK timeout
|
873
|
+
* @returns {Promise<Guild>}
|
874
|
+
* @example
|
875
|
+
* // Edit the guild AFK channel
|
876
|
+
* guild.setAFKTimeout(60)
|
877
|
+
* .then(g => console.log(`Updated guild AFK timeout to ${g.afkTimeout}`))
|
878
|
+
* .catch(console.error);
|
879
|
+
*/
|
880
|
+
setAFKTimeout(afkTimeout, reason) {
|
881
|
+
return this.edit({ afkTimeout }, reason);
|
882
|
+
}
|
883
|
+
|
884
|
+
/**
|
885
|
+
* Set a new guild icon.
|
886
|
+
* @param {Base64Resolvable|BufferResolvable} icon The new icon of the guild
|
887
|
+
* @param {string} [reason] Reason for changing the guild's icon
|
888
|
+
* @returns {Promise<Guild>}
|
889
|
+
* @example
|
890
|
+
* // Edit the guild icon
|
891
|
+
* guild.setIcon('./icon.png')
|
892
|
+
* .then(console.log)
|
893
|
+
* .catch(console.error);
|
894
|
+
*/
|
895
|
+
setIcon(icon, reason) {
|
896
|
+
return this.client.resolver.resolveImage(icon).then(data => this.edit({ icon: data, reason }));
|
897
|
+
}
|
898
|
+
|
899
|
+
/**
|
900
|
+
* Sets a new owner of the guild.
|
901
|
+
* @param {GuildMemberResolvable} owner The new owner of the guild
|
902
|
+
* @param {string} [reason] Reason for setting the new owner
|
903
|
+
* @returns {Promise<Guild>}
|
904
|
+
* @example
|
905
|
+
* // Edit the guild owner
|
906
|
+
* guild.setOwner(guild.members.first())
|
907
|
+
* .then(g => console.log(`Updated the guild owner to ${g.owner.displayName}`))
|
908
|
+
* .catch(console.error);
|
909
|
+
*/
|
910
|
+
setOwner(owner, reason) {
|
911
|
+
return this.edit({ owner }, reason);
|
912
|
+
}
|
913
|
+
|
914
|
+
/**
|
915
|
+
* Set a new guild splash screen.
|
916
|
+
* @param {BufferResolvable|Base64Resolvable} splash The new splash screen of the guild
|
917
|
+
* @param {string} [reason] Reason for changing the guild's splash screen
|
918
|
+
* @returns {Promise<Guild>}
|
919
|
+
* @example
|
920
|
+
* // Edit the guild splash
|
921
|
+
* guild.setSplash('./splash.png')
|
922
|
+
* .then(console.log)
|
923
|
+
* .catch(console.error);
|
924
|
+
*/
|
925
|
+
setSplash(splash) {
|
926
|
+
return this.client.resolver.resolveImage(splash).then(data => this.edit({ splash: data }));
|
927
|
+
}
|
928
|
+
|
929
|
+
/**
|
930
|
+
* Sets the position of the guild in the guild listing.
|
931
|
+
* <warn>This is only available when using a user account.</warn>
|
932
|
+
* @param {number} position Absolute or relative position
|
933
|
+
* @param {boolean} [relative=false] Whether to position relatively or absolutely
|
934
|
+
* @returns {Promise<Guild>}
|
935
|
+
* @deprecated
|
936
|
+
*/
|
937
|
+
setPosition(position, relative) {
|
938
|
+
if (this.client.user.bot) {
|
939
|
+
return Promise.reject(new Error('Setting guild position is only available for user accounts'));
|
940
|
+
}
|
941
|
+
return this.client.user.settings.setGuildPosition(this, position, relative);
|
942
|
+
}
|
943
|
+
|
944
|
+
/**
|
945
|
+
* Marks all messages in this guild as read.
|
946
|
+
* <warn>This is only available when using a user account.</warn>
|
947
|
+
* @returns {Promise<Guild>}
|
948
|
+
* @deprecated
|
949
|
+
*/
|
950
|
+
acknowledge() {
|
951
|
+
return this.client.rest.methods.ackGuild(this);
|
952
|
+
}
|
953
|
+
|
954
|
+
/**
|
955
|
+
* Allow direct messages from guild members.
|
956
|
+
* <warn>This is only available when using a user account.</warn>
|
957
|
+
* @param {boolean} allow Whether to allow direct messages
|
958
|
+
* @returns {Promise<Guild>}
|
959
|
+
* @deprecated
|
960
|
+
*/
|
961
|
+
allowDMs(allow) {
|
962
|
+
const settings = this.client.user.settings;
|
963
|
+
if (allow) return settings.removeRestrictedGuild(this);
|
964
|
+
else return settings.addRestrictedGuild(this);
|
965
|
+
}
|
966
|
+
|
967
|
+
/**
|
968
|
+
* Bans a user from the guild.
|
969
|
+
* @param {UserResolvable} user The user to ban
|
970
|
+
* @param {Object|number|string} [options] Ban options. If a number, the number of days to delete messages for, if a
|
971
|
+
* string, the ban reason. Supplying an object allows you to do both.
|
972
|
+
* @param {number} [options.days=0] Number of days of messages to delete
|
973
|
+
* @param {string} [options.reason] Reason for banning
|
974
|
+
* @returns {Promise<GuildMember|User|string>} Result object will be resolved as specifically as possible.
|
975
|
+
* If the GuildMember cannot be resolved, the User will instead be attempted to be resolved. If that also cannot
|
976
|
+
* be resolved, the user ID will be the result.
|
977
|
+
* @example
|
978
|
+
* // Ban a user by ID
|
979
|
+
* guild.ban('some user ID')
|
980
|
+
* .then(user => console.log(`Banned ${user.username || user.id || user} from ${guild}`))
|
981
|
+
* .catch(console.error);
|
982
|
+
* @example
|
983
|
+
* // Ban a user by object with reason and days
|
984
|
+
* guild.ban(user, { days: 7, reason: 'He needed to go' })
|
985
|
+
* .then(console.log)
|
986
|
+
* .catch(console.error);
|
987
|
+
*/
|
988
|
+
ban(user, options = {}) {
|
989
|
+
if (typeof options === 'number') {
|
990
|
+
options = { reason: null, 'delete-message-days': options };
|
991
|
+
} else if (typeof options === 'string') {
|
992
|
+
options = { reason: options, 'delete-message-days': 0 };
|
993
|
+
}
|
994
|
+
if (options.days) options['delete-message-days'] = options.days;
|
995
|
+
return this.client.rest.methods.banGuildMember(this, user, options);
|
996
|
+
}
|
997
|
+
|
998
|
+
/**
|
999
|
+
* Unbans a user from the guild.
|
1000
|
+
* @param {UserResolvable} user The user to unban
|
1001
|
+
* @param {string} [reason] Reason for unbanning the user
|
1002
|
+
* @returns {Promise<User>}
|
1003
|
+
* @example
|
1004
|
+
* // Unban a user by ID (or with a user/guild member object)
|
1005
|
+
* guild.unban('some user ID')
|
1006
|
+
* .then(user => console.log(`Unbanned ${user.username} from ${guild}`))
|
1007
|
+
* .catch(console.error);
|
1008
|
+
*/
|
1009
|
+
unban(user, reason) {
|
1010
|
+
return this.client.rest.methods.unbanGuildMember(this, user, reason);
|
1011
|
+
}
|
1012
|
+
|
1013
|
+
/**
|
1014
|
+
* Prunes members from the guild based on how long they have been inactive.
|
1015
|
+
* @param {number} days Number of days of inactivity required to kick
|
1016
|
+
* @param {boolean} [dry=false] If true, will return number of users that will be kicked, without actually doing it
|
1017
|
+
* @param {string} [reason] Reason for this prune
|
1018
|
+
* @returns {Promise<number>} The number of members that were/will be kicked
|
1019
|
+
* @example
|
1020
|
+
* // See how many members will be pruned
|
1021
|
+
* guild.pruneMembers(12, true)
|
1022
|
+
* .then(pruned => console.log(`This will prune ${pruned} people!`))
|
1023
|
+
* .catch(console.error);
|
1024
|
+
* @example
|
1025
|
+
* // Actually prune the members
|
1026
|
+
* guild.pruneMembers(12)
|
1027
|
+
* .then(pruned => console.log(`I just pruned ${pruned} people!`))
|
1028
|
+
* .catch(console.error);
|
1029
|
+
*/
|
1030
|
+
pruneMembers(days, dry = false, reason) {
|
1031
|
+
if (typeof days !== 'number') throw new TypeError('Days must be a number.');
|
1032
|
+
return this.client.rest.methods.pruneGuildMembers(this, days, dry, reason);
|
1033
|
+
}
|
1034
|
+
|
1035
|
+
/**
|
1036
|
+
* Syncs this guild (already done automatically every 30 seconds).
|
1037
|
+
* <warn>This is only available when using a user account.</warn>
|
1038
|
+
* @deprecated
|
1039
|
+
*/
|
1040
|
+
sync() {
|
1041
|
+
if (!this.client.user.bot) this.client.syncGuilds([this]);
|
1042
|
+
}
|
1043
|
+
|
1044
|
+
/**
|
1045
|
+
* Overwrites to use when creating a channel or replacing overwrites
|
1046
|
+
* @typedef {Object} ChannelCreationOverwrites
|
1047
|
+
* @property {PermissionResolvable} [allow] The permissions to allow
|
1048
|
+
* @property {PermissionResolvable} [allowed] The permissions to allow
|
1049
|
+
* **(deprecated)**
|
1050
|
+
* @property {PermissionResolvable} [deny] The permissions to deny
|
1051
|
+
* @property {PermissionResolvable} [denied] The permissions to deny
|
1052
|
+
* **(deprecated)**
|
1053
|
+
* @property {GuildMemberResolvable|RoleResolvable} id Member or role this overwrite is for
|
1054
|
+
*/
|
1055
|
+
|
1056
|
+
/**
|
1057
|
+
* Creates a new channel in the guild.
|
1058
|
+
* @param {string} name The name of the new channel
|
1059
|
+
* @param {string|ChannelData} [typeOrOptions='text']
|
1060
|
+
* The type of the new channel, one of `text`, `voice`, `category`, `news`, or `store`. **(deprecated, use options)**
|
1061
|
+
* Alternatively options for the new channel, overriding the following parameters.
|
1062
|
+
* @param {ChannelCreationOverwrites[]|Collection<Snowflake, PermissionOverwrites>} [permissionOverwrites]
|
1063
|
+
* Permission overwrites **(deprecated, use options)**
|
1064
|
+
* @param {string} [reason] Reason for creating this channel **(deprecated, use options)**
|
1065
|
+
* @returns {Promise<CategoryChannel|TextChannel|VoiceChannel>}
|
1066
|
+
* @example
|
1067
|
+
* // Create a new text channel
|
1068
|
+
* guild.createChannel('new-general', { type: 'text' })
|
1069
|
+
* .then(console.log)
|
1070
|
+
* .catch(console.error);
|
1071
|
+
* @example
|
1072
|
+
* // Create a new category channel with permission overwrites
|
1073
|
+
* guild.createChannel('new-category', {
|
1074
|
+
* type: 'category',
|
1075
|
+
* permissionOverwrites: [{
|
1076
|
+
* id: guild.id,
|
1077
|
+
* deny: ['MANAGE_MESSAGES'],
|
1078
|
+
* allow: ['SEND_MESSAGES']
|
1079
|
+
* }]
|
1080
|
+
* })
|
1081
|
+
* .then(console.log)
|
1082
|
+
* .catch(console.error);
|
1083
|
+
*/
|
1084
|
+
createChannel(name, typeOrOptions, permissionOverwrites, reason) {
|
1085
|
+
if (!typeOrOptions || (typeof typeOrOptions === 'string')) {
|
1086
|
+
if (typeOrOptions) {
|
1087
|
+
process.emitWarning(
|
1088
|
+
'Guild#createChannel: Create channels with an options object instead of separate parameters',
|
1089
|
+
'DeprecationWarning'
|
1090
|
+
);
|
1091
|
+
}
|
1092
|
+
typeOrOptions = {
|
1093
|
+
type: typeOrOptions,
|
1094
|
+
permissionOverwrites,
|
1095
|
+
reason,
|
1096
|
+
};
|
1097
|
+
}
|
1098
|
+
return this.client.rest.methods.createChannel(this, name, typeOrOptions);
|
1099
|
+
}
|
1100
|
+
|
1101
|
+
/**
|
1102
|
+
* The data needed for updating a channel's position.
|
1103
|
+
* @typedef {Object} ChannelPosition
|
1104
|
+
* @property {ChannelResolvable} channel Channel to update
|
1105
|
+
* @property {number} position New position for the channel
|
1106
|
+
*/
|
1107
|
+
|
1108
|
+
/**
|
1109
|
+
* Batch-updates the guild's channels' positions.
|
1110
|
+
* @param {ChannelPosition[]} channelPositions Channel positions to update
|
1111
|
+
* @returns {Promise<Guild>}
|
1112
|
+
* @example
|
1113
|
+
* guild.updateChannels([{ channel: channelID, position: newChannelIndex }])
|
1114
|
+
* .then(g => console.log(`Updated channel positions for ${g}`))
|
1115
|
+
* .catch(console.error);
|
1116
|
+
*/
|
1117
|
+
setChannelPositions(channelPositions) {
|
1118
|
+
return this.client.rest.methods.updateChannelPositions(this.id, channelPositions);
|
1119
|
+
}
|
1120
|
+
|
1121
|
+
/**
|
1122
|
+
* Edits the guild's embed.
|
1123
|
+
* @param {GuildEmbedData} embed The embed for the guild
|
1124
|
+
* @param {string} [reason] Reason for changing the guild's embed
|
1125
|
+
* @returns {Promise<Guild>}
|
1126
|
+
*/
|
1127
|
+
setEmbed(embed, reason) {
|
1128
|
+
return this.client.rest.methods.updateEmbed(this.id, embed, reason)
|
1129
|
+
.then(() => this);
|
1130
|
+
}
|
1131
|
+
|
1132
|
+
/**
|
1133
|
+
* Creates a new role in the guild with given information.
|
1134
|
+
* @param {RoleData} [data] The data to update the role with
|
1135
|
+
* @param {string} [reason] Reason for creating this role
|
1136
|
+
* @returns {Promise<Role>}
|
1137
|
+
* @example
|
1138
|
+
* // Create a new role
|
1139
|
+
* guild.createRole()
|
1140
|
+
* .then(role => console.log(`Created new role with name ${role.name}`))
|
1141
|
+
* .catch(console.error);
|
1142
|
+
* @example
|
1143
|
+
* // Create a new role with data
|
1144
|
+
* guild.createRole({
|
1145
|
+
* name: 'Super Cool People',
|
1146
|
+
* color: 'BLUE',
|
1147
|
+
* })
|
1148
|
+
* .then(role => console.log(`Created new role with name ${role.name} and color ${role.color}`))
|
1149
|
+
* .catch(console.error)
|
1150
|
+
*/
|
1151
|
+
createRole(data = {}, reason) {
|
1152
|
+
return this.client.rest.methods.createGuildRole(this, data, reason);
|
1153
|
+
}
|
1154
|
+
|
1155
|
+
/**
|
1156
|
+
* Creates a new custom emoji in the guild.
|
1157
|
+
* @param {BufferResolvable|Base64Resolvable} attachment The image for the emoji
|
1158
|
+
* @param {string} name The name for the emoji
|
1159
|
+
* @param {Collection<Snowflake, Role>|Role[]} [roles] Roles to limit the emoji to
|
1160
|
+
* @param {string} [reason] Reason for creating the emoji
|
1161
|
+
* @returns {Promise<Emoji>} The created emoji
|
1162
|
+
* @example
|
1163
|
+
* // Create a new emoji from a url
|
1164
|
+
* guild.createEmoji('https://i.imgur.com/w3duR07.png', 'rip')
|
1165
|
+
* .then(emoji => console.log(`Created new emoji with name ${emoji.name}`))
|
1166
|
+
* .catch(console.error);
|
1167
|
+
* @example
|
1168
|
+
* // Create a new emoji from a file on your computer
|
1169
|
+
* guild.createEmoji('./memes/banana.png', 'banana')
|
1170
|
+
* .then(emoji => console.log(`Created new emoji with name ${emoji.name}`))
|
1171
|
+
* .catch(console.error);
|
1172
|
+
*/
|
1173
|
+
createEmoji(attachment, name, roles, reason) {
|
1174
|
+
if (typeof attachment === 'string' && attachment.startsWith('data:')) {
|
1175
|
+
return this.client.rest.methods.createEmoji(this, attachment, name, roles, reason);
|
1176
|
+
} else {
|
1177
|
+
return this.client.resolver.resolveImage(attachment).then(data =>
|
1178
|
+
this.client.rest.methods.createEmoji(this, data, name, roles, reason)
|
1179
|
+
);
|
1180
|
+
}
|
1181
|
+
}
|
1182
|
+
|
1183
|
+
/**
|
1184
|
+
* Delete an emoji.
|
1185
|
+
* @param {Emoji|string} emoji The emoji to delete
|
1186
|
+
* @param {string} [reason] Reason for deleting the emoji
|
1187
|
+
* @returns {Promise}
|
1188
|
+
*/
|
1189
|
+
deleteEmoji(emoji, reason) {
|
1190
|
+
if (typeof emoji === 'string') emoji = this.emojis.get(emoji);
|
1191
|
+
if (!(emoji instanceof Emoji)) throw new TypeError('Emoji must be either an instance of Emoji or an ID');
|
1192
|
+
return this.client.rest.methods.deleteEmoji(emoji, reason);
|
1193
|
+
}
|
1194
|
+
|
1195
|
+
/**
|
1196
|
+
* Causes the client to leave the guild.
|
1197
|
+
* @returns {Promise<Guild>}
|
1198
|
+
* @example
|
1199
|
+
* // Leave a guild
|
1200
|
+
* guild.leave()
|
1201
|
+
* .then(g => console.log(`Left the guild ${g}`))
|
1202
|
+
* .catch(console.error);
|
1203
|
+
*/
|
1204
|
+
leave() {
|
1205
|
+
return this.client.rest.methods.leaveGuild(this);
|
1206
|
+
}
|
1207
|
+
|
1208
|
+
/**
|
1209
|
+
* Causes the client to delete the guild.
|
1210
|
+
* @returns {Promise<Guild>}
|
1211
|
+
* @example
|
1212
|
+
* // Delete a guild
|
1213
|
+
* guild.delete()
|
1214
|
+
* .then(g => console.log(`Deleted the guild ${g}`))
|
1215
|
+
* .catch(console.error);
|
1216
|
+
*/
|
1217
|
+
delete() {
|
1218
|
+
return this.client.rest.methods.deleteGuild(this);
|
1219
|
+
}
|
1220
|
+
|
1221
|
+
/**
|
1222
|
+
* Whether this guild equals another guild. It compares all properties, so for most operations
|
1223
|
+
* it is advisable to just compare `guild.id === guild2.id` as it is much faster and is often
|
1224
|
+
* what most users need.
|
1225
|
+
* @param {Guild} guild The guild to compare with
|
1226
|
+
* @returns {boolean}
|
1227
|
+
*/
|
1228
|
+
equals(guild) {
|
1229
|
+
let equal =
|
1230
|
+
guild &&
|
1231
|
+
this.id === guild.id &&
|
1232
|
+
this.available === !guild.unavailable &&
|
1233
|
+
this.splash === guild.splash &&
|
1234
|
+
this.region === guild.region &&
|
1235
|
+
this.name === guild.name &&
|
1236
|
+
this.memberCount === guild.member_count &&
|
1237
|
+
this.large === guild.large &&
|
1238
|
+
this.icon === guild.icon &&
|
1239
|
+
Util.arraysEqual(this.features, guild.features) &&
|
1240
|
+
this.ownerID === guild.owner_id &&
|
1241
|
+
this.verificationLevel === guild.verification_level &&
|
1242
|
+
this.embedEnabled === guild.embed_enabled;
|
1243
|
+
|
1244
|
+
if (equal) {
|
1245
|
+
if (this.embedChannel) {
|
1246
|
+
if (this.embedChannel.id !== guild.embed_channel_id) equal = false;
|
1247
|
+
} else if (guild.embed_channel_id) {
|
1248
|
+
equal = false;
|
1249
|
+
}
|
1250
|
+
}
|
1251
|
+
|
1252
|
+
return equal;
|
1253
|
+
}
|
1254
|
+
|
1255
|
+
/**
|
1256
|
+
* When concatenated with a string, this automatically concatenates the guild's name instead of the guild object.
|
1257
|
+
* @returns {string}
|
1258
|
+
* @example
|
1259
|
+
* // Logs: Hello from My Guild!
|
1260
|
+
* console.log(`Hello from ${guild}!`);
|
1261
|
+
* @example
|
1262
|
+
* // Logs: Hello from My Guild!
|
1263
|
+
* console.log('Hello from ' + guild + '!');
|
1264
|
+
*/
|
1265
|
+
toString() {
|
1266
|
+
return this.name;
|
1267
|
+
}
|
1268
|
+
|
1269
|
+
_addMember(guildUser, emitEvent = true) {
|
1270
|
+
const existing = this.members.has(guildUser.user.id);
|
1271
|
+
if (!(guildUser.user instanceof User)) guildUser.user = this.client.dataManager.newUser(guildUser.user);
|
1272
|
+
|
1273
|
+
guildUser.joined_at = guildUser.joined_at || 0;
|
1274
|
+
const member = new GuildMember(this, guildUser);
|
1275
|
+
this.members.set(member.id, member);
|
1276
|
+
|
1277
|
+
if (this._rawVoiceStates && this._rawVoiceStates.has(member.user.id)) {
|
1278
|
+
const voiceState = this._rawVoiceStates.get(member.user.id);
|
1279
|
+
member.serverMute = voiceState.mute;
|
1280
|
+
member.serverDeaf = voiceState.deaf;
|
1281
|
+
member.selfMute = voiceState.self_mute;
|
1282
|
+
member.selfDeaf = voiceState.self_deaf;
|
1283
|
+
member.voiceSessionID = voiceState.session_id;
|
1284
|
+
member.voiceChannelID = voiceState.channel_id;
|
1285
|
+
if (this.client.channels.has(voiceState.channel_id)) {
|
1286
|
+
this.client.channels.get(voiceState.channel_id).members.set(member.user.id, member);
|
1287
|
+
} else {
|
1288
|
+
this.client.emit('warn', `Member ${member.id} added in guild ${this.id} with an uncached voice channel`);
|
1289
|
+
}
|
1290
|
+
}
|
1291
|
+
|
1292
|
+
/**
|
1293
|
+
* Emitted whenever a user joins a guild.
|
1294
|
+
* @event Client#guildMemberAdd
|
1295
|
+
* @param {GuildMember} member The member that has joined a guild
|
1296
|
+
*/
|
1297
|
+
if (this.client.ws.connection.status === Constants.Status.READY && emitEvent && !existing) {
|
1298
|
+
this.client.emit(Constants.Events.GUILD_MEMBER_ADD, member);
|
1299
|
+
}
|
1300
|
+
|
1301
|
+
return member;
|
1302
|
+
}
|
1303
|
+
|
1304
|
+
_updateMember(member, data) {
|
1305
|
+
const oldMember = Util.cloneObject(member);
|
1306
|
+
|
1307
|
+
if (data.roles) member._roles = data.roles;
|
1308
|
+
if (typeof data.nick !== 'undefined') member.nickname = data.nick;
|
1309
|
+
|
1310
|
+
const notSame = member.nickname !== oldMember.nickname || !Util.arraysEqual(member._roles, oldMember._roles);
|
1311
|
+
|
1312
|
+
if (this.client.ws.connection.status === Constants.Status.READY && notSame) {
|
1313
|
+
/**
|
1314
|
+
* Emitted whenever a guild member changes - i.e. new role, removed role, nickname.
|
1315
|
+
* @event Client#guildMemberUpdate
|
1316
|
+
* @param {GuildMember} oldMember The member before the update
|
1317
|
+
* @param {GuildMember} newMember The member after the update
|
1318
|
+
*/
|
1319
|
+
this.client.emit(Constants.Events.GUILD_MEMBER_UPDATE, oldMember, member);
|
1320
|
+
}
|
1321
|
+
|
1322
|
+
return {
|
1323
|
+
old: oldMember,
|
1324
|
+
mem: member,
|
1325
|
+
};
|
1326
|
+
}
|
1327
|
+
|
1328
|
+
_removeMember(guildMember) {
|
1329
|
+
if (guildMember.voiceChannel) guildMember.voiceChannel.members.delete(guildMember.id);
|
1330
|
+
this.members.delete(guildMember.id);
|
1331
|
+
}
|
1332
|
+
|
1333
|
+
_memberSpeakUpdate(user, speaking) {
|
1334
|
+
const member = this.members.get(user);
|
1335
|
+
if (member && member.speaking !== speaking) {
|
1336
|
+
member.speaking = speaking;
|
1337
|
+
/**
|
1338
|
+
* Emitted once a guild member starts/stops speaking.
|
1339
|
+
* @event Client#guildMemberSpeaking
|
1340
|
+
* @param {GuildMember} member The member that started/stopped speaking
|
1341
|
+
* @param {boolean} speaking Whether or not the member is speaking
|
1342
|
+
*/
|
1343
|
+
this.client.emit(Constants.Events.GUILD_MEMBER_SPEAKING, member, speaking);
|
1344
|
+
}
|
1345
|
+
}
|
1346
|
+
|
1347
|
+
_setPresence(id, presence) {
|
1348
|
+
if (this.presences.get(id)) {
|
1349
|
+
this.presences.get(id).update(presence);
|
1350
|
+
return;
|
1351
|
+
}
|
1352
|
+
this.presences.set(id, new Presence(presence, this.client));
|
1353
|
+
}
|
1354
|
+
|
1355
|
+
/**
|
1356
|
+
* Set the position of a role in this guild.
|
1357
|
+
* @param {string|Role} role The role to edit, can be a role object or a role ID
|
1358
|
+
* @param {number} position The new position of the role
|
1359
|
+
* @param {boolean} [relative=false] Position Moves the role relative to its current position
|
1360
|
+
* @returns {Promise<Guild>}
|
1361
|
+
*/
|
1362
|
+
setRolePosition(role, position, relative = false) {
|
1363
|
+
if (typeof role === 'string') {
|
1364
|
+
role = this.roles.get(role);
|
1365
|
+
if (!role) return Promise.reject(new Error('Supplied role is not a role or snowflake.'));
|
1366
|
+
}
|
1367
|
+
|
1368
|
+
position = Number(position);
|
1369
|
+
if (isNaN(position)) return Promise.reject(new Error('Supplied position is not a number.'));
|
1370
|
+
|
1371
|
+
let updatedRoles = this._sortedRoles.array();
|
1372
|
+
|
1373
|
+
Util.moveElementInArray(updatedRoles, role, position, relative);
|
1374
|
+
|
1375
|
+
updatedRoles = updatedRoles.map((r, i) => ({ id: r.id, position: i }));
|
1376
|
+
return this.client.rest.methods.setRolePositions(this.id, updatedRoles);
|
1377
|
+
}
|
1378
|
+
|
1379
|
+
/**
|
1380
|
+
* Set the position of a channel in this guild.
|
1381
|
+
* @param {string|GuildChannel} channel The channel to edit, can be a channel object or a channel ID
|
1382
|
+
* @param {number} position The new position of the channel
|
1383
|
+
* @param {boolean} [relative=false] Position Moves the channel relative to its current position
|
1384
|
+
* @returns {Promise<Guild>}
|
1385
|
+
*/
|
1386
|
+
setChannelPosition(channel, position, relative = false) {
|
1387
|
+
if (typeof channel === 'string') {
|
1388
|
+
channel = this.channels.get(channel);
|
1389
|
+
if (!channel) return Promise.reject(new Error('Supplied channel is not a channel or snowflake.'));
|
1390
|
+
}
|
1391
|
+
|
1392
|
+
position = Number(position);
|
1393
|
+
if (isNaN(position)) return Promise.reject(new Error('Supplied position is not a number.'));
|
1394
|
+
|
1395
|
+
let updatedChannels = this._sortedChannels(channel.type).array();
|
1396
|
+
|
1397
|
+
Util.moveElementInArray(updatedChannels, channel, position, relative);
|
1398
|
+
|
1399
|
+
updatedChannels = updatedChannels.map((r, i) => ({ id: r.id, position: i }));
|
1400
|
+
return this.client.rest.methods.setChannelPositions(this.id, updatedChannels);
|
1401
|
+
}
|
1402
|
+
|
1403
|
+
/**
|
1404
|
+
* Fetches a collection of channels in the current guild sorted by position.
|
1405
|
+
* @param {string} type The channel type
|
1406
|
+
* @returns {Collection<Snowflake, GuildChannel>}
|
1407
|
+
* @private
|
1408
|
+
*/
|
1409
|
+
_sortedChannels(type) {
|
1410
|
+
return this._sortPositionWithID(this.channels.filter(c => {
|
1411
|
+
if (type === 'voice' && c.type === 'voice') return true;
|
1412
|
+
else if (type !== 'voice' && c.type !== 'voice') return true;
|
1413
|
+
else return type === c.type;
|
1414
|
+
}));
|
1415
|
+
}
|
1416
|
+
|
1417
|
+
/**
|
1418
|
+
* Sorts a collection by object position or ID if the positions are equivalent.
|
1419
|
+
* Intended to be identical to Discord's sorting method.
|
1420
|
+
* @param {Collection} collection The collection to sort
|
1421
|
+
* @returns {Collection}
|
1422
|
+
* @private
|
1423
|
+
*/
|
1424
|
+
_sortPositionWithID(collection) {
|
1425
|
+
return collection.sort((a, b) =>
|
1426
|
+
a.position !== b.position ?
|
1427
|
+
a.position - b.position :
|
1428
|
+
Long.fromString(b.id).sub(Long.fromString(a.id)).toNumber()
|
1429
|
+
);
|
1430
|
+
}
|
1431
|
+
}
|
1432
|
+
|
1433
|
+
/**
|
1434
|
+
* The `#general` TextChannel of the guild
|
1435
|
+
* @name Guild#defaultChannel
|
1436
|
+
* @type {TextChannel}
|
1437
|
+
* @readonly
|
1438
|
+
* @deprecated
|
1439
|
+
*/
|
1440
|
+
Object.defineProperty(Guild.prototype, 'defaultChannel', {
|
1441
|
+
get: util.deprecate(function defaultChannel() {
|
1442
|
+
return this.channels.get(this.id);
|
1443
|
+
}, 'Guild#defaultChannel: This property is obsolete, will be removed in v12.0.0, and may not function as expected.'),
|
1444
|
+
});
|
1445
|
+
|
1446
|
+
Guild.prototype.allowDMs =
|
1447
|
+
util.deprecate(Guild.prototype.allowDMs, 'Guild#allowDMs: userbot methods will be removed');
|
1448
|
+
|
1449
|
+
Guild.prototype.acknowledge =
|
1450
|
+
util.deprecate(Guild.prototype.acknowledge, 'Guild#acknowledge: userbot methods will be removed');
|
1451
|
+
|
1452
|
+
Guild.prototype.setPosition =
|
1453
|
+
util.deprecate(Guild.prototype.setPosition, 'Guild#setPosition: userbot methods will be removed');
|
1454
|
+
|
1455
|
+
Guild.prototype.search =
|
1456
|
+
util.deprecate(Guild.prototype.search, 'Guild#search: userbot methods will be removed');
|
1457
|
+
|
1458
|
+
Guild.prototype.sync =
|
1459
|
+
util.deprecate(Guild.prototype.sync, 'Guild#sync:, userbot methods will be removed');
|
1460
|
+
|
1461
|
+
module.exports = Guild;
|