From 83ce0a0f439e80c3fa381481ab00a64831864524 Mon Sep 17 00:00:00 2001 From: March 7th <71698422+aiko-chan-ai@users.noreply.github.com> Date: Wed, 8 Jun 2022 12:35:19 +0700 Subject: [PATCH] Update - Warn msg - Add `nonce` param (interaction) --- Document/GuildMember.md | 1 - src/managers/GuildMemberManager.js | 18 +++++++++++++----- src/structures/ApplicationCommand.js | 2 ++ src/structures/Guild.js | 2 +- src/structures/MessageButton.js | 2 ++ src/structures/MessageSelectMenu.js | 2 ++ 6 files changed, 20 insertions(+), 7 deletions(-) diff --git a/Document/GuildMember.md b/Document/GuildMember.md index 8b13789..e69de29 100644 --- a/Document/GuildMember.md +++ b/Document/GuildMember.md @@ -1 +0,0 @@ - diff --git a/src/managers/GuildMemberManager.js b/src/managers/GuildMemberManager.js index 9b92b3e..74d4ba6 100644 --- a/src/managers/GuildMemberManager.js +++ b/src/managers/GuildMemberManager.js @@ -427,9 +427,9 @@ class GuildMemberManager extends CachedManager { this.guild.me.permissions.has('BAN_MEMBERS') || this.guild.me.permissions.has('MANAGE_ROLES') ) { - type = 8; // This is opcode + type = Opcodes.REQUEST_GUILD_MEMBERS; // This is opcode this.guild.shard.send({ - op: Opcodes.REQUEST_GUILD_MEMBERS, + op: type, d: { guild_id: this.guild.id, presences, @@ -440,7 +440,7 @@ class GuildMemberManager extends CachedManager { }, }); } else { - type = 14; // This is opcode + type = Opcodes.LAZY_REQUEST; // This is opcode let channel; let channels = this.guild.channels.cache.filter(c => c.isText()); channels = channels.filter(c => c.permissionsFor(this.guild.me).has('VIEW_CHANNEL')); @@ -468,6 +468,14 @@ class GuildMemberManager extends CachedManager { [200, 299], ]); } else { + if (allMember > 1_000) { + console.warn( + `[WARN] Guild ${this.guild.id} has ${allMember} > 1000 members. Can't get offline members (Opcode 14)\n> https://discordpy-self.readthedocs.io/en/latest/migrating_from_dpy.html#guild-members`, + ); + if (allMember > 75_000) { + console.warn(`[WARN] Can't get enough members because the guild is large (Opcode 14)`); + } + } let x = 100; for (let i = 0; i < allMember; i++) { if (x > allMember) { @@ -485,7 +493,7 @@ class GuildMemberManager extends CachedManager { Promise.all( list.map(l => { this.guild.shard.send({ - op: Opcodes.LAZY_REQUEST, + op: type, d: { guild_id: this.guild.id, typing: true, @@ -516,7 +524,7 @@ class GuildMemberManager extends CachedManager { this.client.decrementMaxListeners(); let fetched = fetchedMembers.size < this.guild.members.cache.size ? this.guild.members.cache : fetchedMembers; if (user_ids && !Array.isArray(user_ids) && fetched.size) fetched = fetched.first(); - if (type == 14) { + if (type == Opcodes.LAZY_REQUEST) { this.guild.client.sleep(sleepTime).then(() => resolve(fetched)); } else { resolve(fetched); diff --git a/src/structures/ApplicationCommand.js b/src/structures/ApplicationCommand.js index 6b55cf7..50afc28 100644 --- a/src/structures/ApplicationCommand.js +++ b/src/structures/ApplicationCommand.js @@ -630,6 +630,7 @@ class ApplicationCommand extends Base { type: ApplicationCommandTypes[this.type], options: option_, }, + nonce: SnowflakeUtil.generate(), }, }); return true; @@ -666,6 +667,7 @@ class ApplicationCommand extends Base { type: ApplicationCommandTypes[this.type], target_id: ApplicationCommandTypes[this.type] == 1 ? message.author.id : message.id, }, + nonce: SnowflakeUtil.generate(), }, }); return true; diff --git a/src/structures/Guild.js b/src/structures/Guild.js index 54b931f..811d79c 100644 --- a/src/structures/Guild.js +++ b/src/structures/Guild.js @@ -638,7 +638,7 @@ class Guild extends AnonymousGuild { // MODAL_SUMMIT :)) } if (type < 1 || type > 3) { - throw new RangeError('Type must be 1, 2, 3'); + throw new RangeError('Type must be 1 (CHAT_INPUT), 2 (USER), 3 (MESSAGE)'); } if (typeof type !== 'number') { throw new TypeError('Type must be a number | string'); diff --git a/src/structures/MessageButton.js b/src/structures/MessageButton.js index 7c7a5bc..6b46cc3 100644 --- a/src/structures/MessageButton.js +++ b/src/structures/MessageButton.js @@ -4,6 +4,7 @@ const BaseMessageComponent = require('./BaseMessageComponent'); const { Message } = require('./Message'); const { RangeError } = require('../errors'); const { MessageButtonStyles, MessageComponentTypes } = require('../util/Constants'); +const SnowflakeUtil = require('../util/SnowflakeUtil'); const Util = require('../util/Util'); /** @@ -183,6 +184,7 @@ class MessageButton extends BaseMessageComponent { component_type: 2, // Button custom_id: this.customId, }, + nonce: SnowflakeUtil.generate(), }, }); return true; diff --git a/src/structures/MessageSelectMenu.js b/src/structures/MessageSelectMenu.js index 29a0d8b..fc61344 100644 --- a/src/structures/MessageSelectMenu.js +++ b/src/structures/MessageSelectMenu.js @@ -3,6 +3,7 @@ const BaseMessageComponent = require('./BaseMessageComponent'); const { Message } = require('./Message'); const { MessageComponentTypes } = require('../util/Constants'); +const SnowflakeUtil = require('../util/SnowflakeUtil'); const Util = require('../util/Util'); /** @@ -254,6 +255,7 @@ class MessageSelectMenu extends BaseMessageComponent { type: 3, // Select Menu values, }, + nonce: SnowflakeUtil.generate(), }, }); return true;