Get interaction commands using gateway
This commit is contained in:
March 7th 2022-04-12 20:46:25 +07:00
parent f73525f278
commit d78a10ed76
15 changed files with 1791 additions and 1536 deletions

View File

@ -9,6 +9,7 @@
- [<strong>Guild</strong>](https://github.com/aiko-chan-ai/discord.js-selfbot-v13/blob/main/Document/Guild.md) - [<strong>Guild</strong>](https://github.com/aiko-chan-ai/discord.js-selfbot-v13/blob/main/Document/Guild.md)
- [<strong>Message</strong>](https://github.com/aiko-chan-ai/discord.js-selfbot-v13/blob/main/Document/Message.md) - [<strong>Message</strong>](https://github.com/aiko-chan-ai/discord.js-selfbot-v13/blob/main/Document/Message.md)
- [<strong>User</strong>](https://github.com/aiko-chan-ai/discord.js-selfbot-v13/blob/main/Document/User.md) - [<strong>User</strong>](https://github.com/aiko-chan-ai/discord.js-selfbot-v13/blob/main/Document/User.md)
- [<strong>API</strong>](https://github.com/aiko-chan-ai/discord.js-selfbot-v13/blob/main/Document/API.md)
## More features ## More features

68
Document/API.md Normal file
View File

@ -0,0 +1,68 @@
# Extending Discord.js-selfbot-v13
> `credit: Discum`
How to add extra API wraps to Discord.js-selfbot-v13?
# Table of Contents
- [HTTP APIs](#HTTP-APIs)
- [Gateway APIs](#Gateway-APIs)
### HTTP APIs:
```js
URL example:
'https://discord.com/api/v9/users/@me'
const url = client.api.users['@me'];
/* Method: GET | POST | PUT | PATCH | DELETE */
```
###### GET:
```js
await client.api.users['@me'].get({ versioned: true });
/* Request: https://discord.com/api/v9/users/@me */
await client.api.users['@me'].get({ versioned: false });
/* Request: https://discord.com/api/users/@me */
```
###### POST:
```js
await client.api.channels[channel.id].messages.post({ versioned: true, data: {}, files: [] });
/* Request: https://discord.com/api/v9/channels/{channel.id}/messages */
```
###### PUT:
```js
await client.api
.guilds(guild.id)
.bans(user.id)
.put({
versioned: true,
data: {},
});
/* Request: https://discord.com/api/guilds/{guild.id}/bans/{user.id} */
```
###### PATCH:
```js
await client.api.users['@me'].patch({ versioned: true, data: {} });
/* Request: https://discord.com/api/v9/users/@me */
```
###### DELETE:
```js
await client.api.hypesquad.online.delete({ versioned: true });
/* Request: https://discord.com/api/v9/hypesquad/online */
```
### Gateway APIs
You need to send data to the port and listen for an event. This is quite complicated but if you want to use an existing event, here are the instructions
###### SEND:
```js
const { Constants } = require('discord.js-selfbot-v13');
// Global gateway (example update presence)
client.ws.broadcast({
op: Constants.Opcodes.STATUS_UPDATE,
d: {},
});
// Guild gateway (example get all members)
guild.shard.send({
op: Constants.Opcodes.REQUEST_GUILD_MEMBERS,
d: {},
});
```

View File

@ -4,6 +4,30 @@
## Interaction ## Interaction
<details> <details>
<summary>Fetch Commands data</summary>
```js
/* Save to cache */
// In guild (Opcode 24)
await guild.searchInteraction(
{
limit: 100, // default: 1
query: 'ping', // optional
type: 'CHAT_INPUT', // default: 'CHAT_INPUT'
offset: 0, // default: 0
botID: ['botid1', 'botid2'], // optional
}
);
// Fetch all commands (1 bot) Shouldn't be used
await bot.applications.fetch(
{
guildId: 'guild id to search', // optional
force: false, // Using cache or createDMs to bot
}
);
```
</details>
<details>
<summary>Button Click</summary> <summary>Button Click</summary>
```js ```js
@ -57,6 +81,7 @@ await message.contextMenu(botID, commandName);
> In this way, all Slash commands can be obtained > In this way, all Slash commands can be obtained
- I will try to find another way to not need to create DMs with Bot anymore - I will try to find another way to not need to create DMs with Bot anymore
- Credit: [Here](https://www.reddit.com/r/Discord_selfbots/comments/tczprx/discum_help_creating_a_selfbot_that_can_do_ping/) - Credit: [Here](https://www.reddit.com/r/Discord_selfbots/comments/tczprx/discum_help_creating_a_selfbot_that_can_do_ping/)
- <strong>Update: Now to get more secure interaction commands you need to use guild.searchInteraction() (using gateway)</strong>
</details> </details>
## MessageEmbed ? ## MessageEmbed ?

View File

@ -1,6 +1,6 @@
{ {
"name": "discord.js-selfbot-v13", "name": "discord.js-selfbot-v13",
"version": "1.3.3", "version": "1.3.4",
"description": "A unofficial discord.js fork for creating selfbots [Based on discord.js v13]", "description": "A unofficial discord.js fork for creating selfbots [Based on discord.js v13]",
"main": "./src/index.js", "main": "./src/index.js",
"types": "./typings/index.d.ts", "types": "./typings/index.d.ts",

View File

@ -60,7 +60,7 @@ class InteractionCreateAction extends Action {
InteractionType = AutocompleteInteraction; InteractionType = AutocompleteInteraction;
break; break;
default: default:
client.emit(Events.DEBUG, `[INTERACTION] Received interaction with unknown type: ${data.type}`); client.emit(Events.DEBUG, `[INTERACTION] Received [BOT] / Send (Selfbot) interactionID ${data.id} with unknown type: ${data.type}`);
return; return;
} }

View File

@ -0,0 +1,10 @@
'use strict';
module.exports = (client, { d: data }) => {
if (!data.application_commands[0]) return;
for (const command of data.application_commands) {
const user = client.users.cache.get(command.application_id);
if (!user) continue;
user.applications._add(command, true);
};
};

View File

@ -9,6 +9,7 @@ module.exports = (client, { d: data }) => {
const guild = client.guilds.cache.get(data.guild_id); const guild = client.guilds.cache.get(data.guild_id);
if (!guild) return; if (!guild) return;
const members = new Collection(); const members = new Collection();
// Get Member from side Discord Channel (online counting if large server)
for (const object of data.ops) { for (const object of data.ops) {
if (object.op == 'SYNC') { if (object.op == 'SYNC') {
for (const member_ of object.items) { for (const member_ of object.items) {

View File

@ -1,5 +1,7 @@
'use strict'; 'use strict';
const { Events } = require('../../../util/Constants');
module.exports = (client, packet) => { module.exports = (client, packet) => {
client.actions.InteractionCreate.handle(packet.d); if (client.user.bot) client.actions.InteractionCreate.handle(packet.d);
else client.emit(Events.INTERACTION_CREATE, packet.d);
}; };

View File

@ -0,0 +1,6 @@
'use strict';
const { Events } = require('../../../util/Constants');
module.exports = (client, { d: data }) => {
client.emit(Events.INTERACTION_FAILED, data);
};

View File

@ -0,0 +1,6 @@
'use strict';
const { Events } = require('../../../util/Constants');
module.exports = (client, { d: data }) => {
client.emit(Events.INTERACTION_SUCCESS, data);
};

View File

@ -18,6 +18,10 @@ const handlers = Object.fromEntries([
['GUILD_MEMBER_UPDATE', require('./GUILD_MEMBER_UPDATE')], ['GUILD_MEMBER_UPDATE', require('./GUILD_MEMBER_UPDATE')],
['GUILD_MEMBERS_CHUNK', require('./GUILD_MEMBERS_CHUNK')], ['GUILD_MEMBERS_CHUNK', require('./GUILD_MEMBERS_CHUNK')],
['GUILD_MEMBER_LIST_UPDATE', require('./GUILD_MEMBER_LIST_UPDATE.js')], ['GUILD_MEMBER_LIST_UPDATE', require('./GUILD_MEMBER_LIST_UPDATE.js')],
[
'GUILD_APPLICATION_COMMANDS_UPDATE',
require('./GUILD_APPLICATION_COMMANDS_UPDATE.js'),
],
['GUILD_INTEGRATIONS_UPDATE', require('./GUILD_INTEGRATIONS_UPDATE')], ['GUILD_INTEGRATIONS_UPDATE', require('./GUILD_INTEGRATIONS_UPDATE')],
['GUILD_ROLE_CREATE', require('./GUILD_ROLE_CREATE')], ['GUILD_ROLE_CREATE', require('./GUILD_ROLE_CREATE')],
['GUILD_ROLE_DELETE', require('./GUILD_ROLE_DELETE')], ['GUILD_ROLE_DELETE', require('./GUILD_ROLE_DELETE')],
@ -50,6 +54,8 @@ const handlers = Object.fromEntries([
['VOICE_SERVER_UPDATE', require('./VOICE_SERVER_UPDATE')], ['VOICE_SERVER_UPDATE', require('./VOICE_SERVER_UPDATE')],
['WEBHOOKS_UPDATE', require('./WEBHOOKS_UPDATE')], ['WEBHOOKS_UPDATE', require('./WEBHOOKS_UPDATE')],
['INTERACTION_CREATE', require('./INTERACTION_CREATE')], ['INTERACTION_CREATE', require('./INTERACTION_CREATE')],
['INTERACTION_SUCCESS', require('./INTERACTION_SUCCESS')],
['INTERACTION_FAILED', require('./INTERACTION_FAILED')],
['STAGE_INSTANCE_CREATE', require('./STAGE_INSTANCE_CREATE')], ['STAGE_INSTANCE_CREATE', require('./STAGE_INSTANCE_CREATE')],
['STAGE_INSTANCE_UPDATE', require('./STAGE_INSTANCE_UPDATE')], ['STAGE_INSTANCE_UPDATE', require('./STAGE_INSTANCE_UPDATE')],
['STAGE_INSTANCE_DELETE', require('./STAGE_INSTANCE_DELETE')], ['STAGE_INSTANCE_DELETE', require('./STAGE_INSTANCE_DELETE')],

View File

@ -84,7 +84,7 @@ class ApplicationCommandManager extends CachedManager {
* .catch(console.error); * .catch(console.error);
*/ */
async fetch(id, { guildId, cache = true, force = false } = {}) { async fetch(id, { guildId, cache = true, force = false } = {}) {
await this.user.createDM().catch(() => {}); // change from user.createDM to opcode (risky action)
if (typeof id === 'object') { if (typeof id === 'object') {
({ guildId, cache = true } = id); ({ guildId, cache = true } = id);
} else if (id) { } else if (id) {
@ -92,10 +92,11 @@ class ApplicationCommandManager extends CachedManager {
const existing = this.cache.get(id); const existing = this.cache.get(id);
if (existing) return existing; if (existing) return existing;
} }
await this.user.createDM().catch(() => {});
const command = await this.commandPath({ id, guildId }).get(); const command = await this.commandPath({ id, guildId }).get();
return this._add(command, cache); return this._add(command, cache);
} }
await this.user.createDM().catch(() => {});
const data = await this.commandPath({ guildId }).get(); const data = await this.commandPath({ guildId }).get();
return data.reduce((coll, command) => coll.set(command.id, this._add(command, cache, guildId)), new Collection()); return data.reduce((coll, command) => coll.set(command.id, this._add(command, cache, guildId)), new Collection());
} }

View File

@ -31,6 +31,7 @@ const {
Status, Status,
MFALevels, MFALevels,
PremiumTiers, PremiumTiers,
Opcodes,
} = require('../util/Constants'); } = require('../util/Constants');
const DataResolver = require('../util/DataResolver'); const DataResolver = require('../util/DataResolver');
const SystemChannelFlags = require('../util/SystemChannelFlags'); const SystemChannelFlags = require('../util/SystemChannelFlags');
@ -311,7 +312,8 @@ class Guild extends AnonymousGuild {
* The explicit content filter level of the guild * The explicit content filter level of the guild
* @type {ExplicitContentFilterLevel} * @type {ExplicitContentFilterLevel}
*/ */
this.explicitContentFilter = ExplicitContentFilterLevels[data.explicit_content_filter]; this.explicitContentFilter =
ExplicitContentFilterLevels[data.explicit_content_filter];
} }
if ('mfa_level' in data) { if ('mfa_level' in data) {
@ -335,7 +337,8 @@ class Guild extends AnonymousGuild {
* The default message notification level of the guild * The default message notification level of the guild
* @type {DefaultMessageNotificationLevel} * @type {DefaultMessageNotificationLevel}
*/ */
this.defaultMessageNotifications = DefaultMessageNotificationLevels[data.default_message_notifications]; this.defaultMessageNotifications =
DefaultMessageNotificationLevels[data.default_message_notifications];
} }
if ('system_channel_flags' in data) { if ('system_channel_flags' in data) {
@ -343,7 +346,9 @@ class Guild extends AnonymousGuild {
* The value set for the guild's system channel flags * The value set for the guild's system channel flags
* @type {Readonly<SystemChannelFlags>} * @type {Readonly<SystemChannelFlags>}
*/ */
this.systemChannelFlags = new SystemChannelFlags(data.system_channel_flags).freeze(); this.systemChannelFlags = new SystemChannelFlags(
data.system_channel_flags,
).freeze();
} }
if ('max_members' in data) { if ('max_members' in data) {
@ -499,7 +504,8 @@ class Guild extends AnonymousGuild {
* @type {GuildStickerManager} * @type {GuildStickerManager}
*/ */
this.stickers = new GuildStickerManager(this); this.stickers = new GuildStickerManager(this);
if (data.stickers) for (const sticker of data.stickers) this.stickers._add(sticker); if (data.stickers)
for (const sticker of data.stickers) this.stickers._add(sticker);
} else if (data.stickers) { } else if (data.stickers) {
this.client.actions.GuildStickersUpdate.handle({ this.client.actions.GuildStickersUpdate.handle({
guild_id: this.id, guild_id: this.id,
@ -523,7 +529,15 @@ class Guild extends AnonymousGuild {
* @returns {?string} * @returns {?string}
*/ */
discoverySplashURL({ format, size } = {}) { discoverySplashURL({ format, size } = {}) {
return this.discoverySplash && this.client.rest.cdn.DiscoverySplash(this.id, this.discoverySplash, format, size); return (
this.discoverySplash &&
this.client.rest.cdn.DiscoverySplash(
this.id,
this.discoverySplash,
format,
size,
)
);
} }
/** /**
@ -617,6 +631,51 @@ class Guild extends AnonymousGuild {
} }
} }
/**
* Search slash command / message context
* @param {guildSearchInteraction} options
* {
*
* type: 1 | 2 | 3, [CHAT_INPUT | USER | MESSAGE]
*
* query: string | undefined,
*
* limit: number | 1,
*
* offset: number | 0,
*
* botID: [Snowflake] | undefined,
*
* }
*/
async searchInteraction(options = {}) {
let { query, type, limit, offset, botID } = Object.assign(
{ query: undefined, type: 1, limit: 1, offset: 0, botID: [] },
options,
);
if (typeof type == 'string') {
if (type == 'CHAT_INPUT') type = 1;
else if (type == 'USER') type = 2;
else if (type == 'MESSAGE') type = 3;
}
if (type < 1 || type > 3)
throw new RangeError('Type must be 1, 2, 3');
if (typeof type !== 'number')
throw new TypeError('Type must be a number | string');
this.shard.send({
op: Opcodes.REQUEST_APPLICATION_COMMANDS,
d: {
guild_id: this.id,
applications: false,
limit,
offset,
type,
query: query,
command_ids: Array.isArray(botID) ? botID : undefined,
},
});
}
/** /**
* Fetches a collection of integrations to this guild. * Fetches a collection of integrations to this guild.
* Resolves with a collection mapping integrations by their ids. * Resolves with a collection mapping integrations by their ids.
@ -630,7 +689,11 @@ class Guild extends AnonymousGuild {
async fetchIntegrations() { async fetchIntegrations() {
const data = await this.client.api.guilds(this.id).integrations.get(); const data = await this.client.api.guilds(this.id).integrations.get();
return data.reduce( return data.reduce(
(collection, integration) => collection.set(integration.id, new Integration(this.client, integration, this)), (collection, integration) =>
collection.set(
integration.id,
new Integration(this.client, integration, this),
),
new Collection(), new Collection(),
); );
} }
@ -642,7 +705,10 @@ class Guild extends AnonymousGuild {
*/ */
async fetchTemplates() { async fetchTemplates() {
const templates = await this.client.api.guilds(this.id).templates.get(); const templates = await this.client.api.guilds(this.id).templates.get();
return templates.reduce((col, data) => col.set(data.code, new GuildTemplate(this.client, data)), new Collection()); return templates.reduce(
(col, data) => col.set(data.code, new GuildTemplate(this.client, data)),
new Collection(),
);
} }
/** /**
@ -661,7 +727,9 @@ class Guild extends AnonymousGuild {
* @returns {Promise<GuildTemplate>} * @returns {Promise<GuildTemplate>}
*/ */
async createTemplate(name, description) { async createTemplate(name, description) {
const data = await this.client.api.guilds(this.id).templates.post({ data: { name, description } }); const data = await this.client.api
.guilds(this.id)
.templates.post({ data: { name, description } });
return new GuildTemplate(this.client, data); return new GuildTemplate(this.client, data);
} }
@ -716,7 +784,8 @@ class Guild extends AnonymousGuild {
async fetchWebhooks() { async fetchWebhooks() {
const apiHooks = await this.client.api.guilds(this.id).webhooks.get(); const apiHooks = await this.client.api.guilds(this.id).webhooks.get();
const hooks = new Collection(); const hooks = new Collection();
for (const hook of apiHooks) hooks.set(hook.id, new Webhook(this.client, hook)); for (const hook of apiHooks)
hooks.set(hook.id, new Webhook(this.client, hook));
return hooks; return hooks;
} }
@ -762,7 +831,9 @@ class Guild extends AnonymousGuild {
this.widgetChannelId = data.channel_id; this.widgetChannelId = data.channel_id;
return { return {
enabled: data.enabled, enabled: data.enabled,
channel: data.channel_id ? this.channels.cache.get(data.channel_id) : null, channel: data.channel_id
? this.channels.cache.get(data.channel_id)
: null,
}; };
} }
@ -786,8 +857,10 @@ class Guild extends AnonymousGuild {
* .catch(console.error); * .catch(console.error);
*/ */
async fetchAuditLogs(options = {}) { async fetchAuditLogs(options = {}) {
if (options.before && options.before instanceof GuildAuditLogs.Entry) options.before = options.before.id; if (options.before && options.before instanceof GuildAuditLogs.Entry)
if (typeof options.type === 'string') options.type = GuildAuditLogs.Actions[options.type]; options.before = options.before.id;
if (typeof options.type === 'string')
options.type = GuildAuditLogs.Actions[options.type];
const data = await this.client.api.guilds(this.id)['audit-logs'].get({ const data = await this.client.api.guilds(this.id)['audit-logs'].get({
query: { query: {
@ -865,16 +938,23 @@ class Guild extends AnonymousGuild {
_data.afk_channel_id = this.client.channels.resolveId(data.afkChannel); _data.afk_channel_id = this.client.channels.resolveId(data.afkChannel);
} }
if (typeof data.systemChannel !== 'undefined') { if (typeof data.systemChannel !== 'undefined') {
_data.system_channel_id = this.client.channels.resolveId(data.systemChannel); _data.system_channel_id = this.client.channels.resolveId(
data.systemChannel,
);
} }
if (data.afkTimeout) _data.afk_timeout = Number(data.afkTimeout); if (data.afkTimeout) _data.afk_timeout = Number(data.afkTimeout);
if (typeof data.icon !== 'undefined') _data.icon = await DataResolver.resolveImage(data.icon); if (typeof data.icon !== 'undefined')
_data.icon = await DataResolver.resolveImage(data.icon);
if (data.owner) _data.owner_id = this.client.users.resolveId(data.owner); if (data.owner) _data.owner_id = this.client.users.resolveId(data.owner);
if (typeof data.splash !== 'undefined') _data.splash = await DataResolver.resolveImage(data.splash); if (typeof data.splash !== 'undefined')
_data.splash = await DataResolver.resolveImage(data.splash);
if (typeof data.discoverySplash !== 'undefined') { if (typeof data.discoverySplash !== 'undefined') {
_data.discovery_splash = await DataResolver.resolveImage(data.discoverySplash); _data.discovery_splash = await DataResolver.resolveImage(
data.discoverySplash,
);
} }
if (typeof data.banner !== 'undefined') _data.banner = await DataResolver.resolveImage(data.banner); if (typeof data.banner !== 'undefined')
_data.banner = await DataResolver.resolveImage(data.banner);
if (typeof data.explicitContentFilter !== 'undefined') { if (typeof data.explicitContentFilter !== 'undefined') {
_data.explicit_content_filter = _data.explicit_content_filter =
typeof data.explicitContentFilter === 'number' typeof data.explicitContentFilter === 'number'
@ -888,13 +968,19 @@ class Guild extends AnonymousGuild {
: DefaultMessageNotificationLevels[data.defaultMessageNotifications]; : DefaultMessageNotificationLevels[data.defaultMessageNotifications];
} }
if (typeof data.systemChannelFlags !== 'undefined') { if (typeof data.systemChannelFlags !== 'undefined') {
_data.system_channel_flags = SystemChannelFlags.resolve(data.systemChannelFlags); _data.system_channel_flags = SystemChannelFlags.resolve(
data.systemChannelFlags,
);
} }
if (typeof data.rulesChannel !== 'undefined') { if (typeof data.rulesChannel !== 'undefined') {
_data.rules_channel_id = this.client.channels.resolveId(data.rulesChannel); _data.rules_channel_id = this.client.channels.resolveId(
data.rulesChannel,
);
} }
if (typeof data.publicUpdatesChannel !== 'undefined') { if (typeof data.publicUpdatesChannel !== 'undefined') {
_data.public_updates_channel_id = this.client.channels.resolveId(data.publicUpdatesChannel); _data.public_updates_channel_id = this.client.channels.resolveId(
data.publicUpdatesChannel,
);
} }
if (typeof data.features !== 'undefined') { if (typeof data.features !== 'undefined') {
_data.features = data.features; _data.features = data.features;
@ -903,8 +989,11 @@ class Guild extends AnonymousGuild {
_data.description = data.description; _data.description = data.description;
} }
if (data.preferredLocale) _data.preferred_locale = data.preferredLocale; if (data.preferredLocale) _data.preferred_locale = data.preferredLocale;
if ('premiumProgressBarEnabled' in data) _data.premium_progress_bar_enabled = data.premiumProgressBarEnabled; if ('premiumProgressBarEnabled' in data)
const newData = await this.client.api.guilds(this.id).patch({ data: _data, reason }); _data.premium_progress_bar_enabled = data.premiumProgressBarEnabled;
const newData = await this.client.api
.guilds(this.id)
.patch({ data: _data, reason });
return this.client.actions.GuildUpdate.handle(newData).updated; return this.client.actions.GuildUpdate.handle(newData).updated;
} }
@ -958,7 +1047,7 @@ class Guild extends AnonymousGuild {
*/ */
async editWelcomeScreen(data) { async editWelcomeScreen(data) {
const { enabled, description, welcomeChannels } = data; const { enabled, description, welcomeChannels } = data;
const welcome_channels = welcomeChannels?.map(welcomeChannelData => { const welcome_channels = welcomeChannels?.map((welcomeChannelData) => {
const emoji = this.emojis.resolve(welcomeChannelData.emoji); const emoji = this.emojis.resolve(welcomeChannelData.emoji);
return { return {
emoji_id: emoji?.id, emoji_id: emoji?.id,
@ -968,7 +1057,9 @@ class Guild extends AnonymousGuild {
}; };
}); });
const patchData = await this.client.api.guilds(this.id, 'welcome-screen').patch({ const patchData = await this.client.api
.guilds(this.id, 'welcome-screen')
.patch({
data: { data: {
welcome_channels, welcome_channels,
description, description,
@ -1192,11 +1283,7 @@ class Guild extends AnonymousGuild {
if (type == 1 || `${type}`.toUpperCase() === 'FOLDER') { if (type == 1 || `${type}`.toUpperCase() === 'FOLDER') {
folderID = folderID || this.folder.folderId; folderID = folderID || this.folder.folderId;
if (!['number', 'string'].includes(typeof folderID)) if (!['number', 'string'].includes(typeof folderID))
throw new TypeError( throw new TypeError('INVALID_TYPE', 'folderID', 'String | Number');
'INVALID_TYPE',
'folderID',
'String | Number',
);
// Get Data from Folder ID // Get Data from Folder ID
const folder = await this.client.setting.rawSetting.guild_folders.find( const folder = await this.client.setting.rawSetting.guild_folders.find(
(obj) => obj.id == folderID, (obj) => obj.id == folderID,
@ -1419,7 +1506,12 @@ class Guild extends AnonymousGuild {
* @param {TextChannelResolvable} rulesChannel * @param {TextChannelResolvable} rulesChannel
* @param {String} reason * @param {String} reason
*/ */
async setCommunity(stats = true, publicUpdatesChannel = '1', rulesChannel = '1', reason) { async setCommunity(
stats = true,
publicUpdatesChannel = '1',
rulesChannel = '1',
reason,
) {
if (stats) { if (stats) {
// Check everyone role // Check everyone role
const everyoneRole = this.roles.everyone; const everyoneRole = this.roles.everyone;
@ -1442,13 +1534,16 @@ class Guild extends AnonymousGuild {
reason, reason,
); );
} else { } else {
this.edit({ this.edit(
{
publicUpdatesChannel: null, publicUpdatesChannel: null,
rulesChannel: null, rulesChannel: null,
features: this.features.filter(f => f !== 'COMMUNITY'), features: this.features.filter((f) => f !== 'COMMUNITY'),
preferredLocale: this.preferredLocale, preferredLocale: this.preferredLocale,
description: this.description, description: this.description,
}, reason); },
reason,
);
} }
} }
@ -1474,10 +1569,10 @@ class Guild extends AnonymousGuild {
* @readonly * @readonly
*/ */
get voiceAdapterCreator() { get voiceAdapterCreator() {
return methods => { return (methods) => {
this.client.voice.adapters.set(this.id, methods); this.client.voice.adapters.set(this.id, methods);
return { return {
sendPayload: data => { sendPayload: (data) => {
if (this.shard.status !== Status.READY) return false; if (this.shard.status !== Status.READY) return false;
this.shard.send(data); this.shard.send(data);
return true; return true;
@ -1508,7 +1603,7 @@ class Guild extends AnonymousGuild {
const category = channel.type === ChannelTypes.GUILD_CATEGORY; const category = channel.type === ChannelTypes.GUILD_CATEGORY;
return Util.discordSort( return Util.discordSort(
this.channels.cache.filter( this.channels.cache.filter(
c => (c) =>
(['GUILD_TEXT', 'GUILD_NEWS', 'GUILD_STORE'].includes(channel.type) (['GUILD_TEXT', 'GUILD_NEWS', 'GUILD_STORE'].includes(channel.type)
? ['GUILD_TEXT', 'GUILD_NEWS', 'GUILD_STORE'].includes(c.type) ? ['GUILD_TEXT', 'GUILD_NEWS', 'GUILD_STORE'].includes(c.type)
: c.type === channel.type) && : c.type === channel.type) &&

View File

@ -347,6 +347,8 @@ exports.Events = {
TYPING_START: 'typingStart', TYPING_START: 'typingStart',
WEBHOOKS_UPDATE: 'webhookUpdate', WEBHOOKS_UPDATE: 'webhookUpdate',
INTERACTION_CREATE: 'interactionCreate', INTERACTION_CREATE: 'interactionCreate',
INTERACTION_SUCCESS: 'interactionSuccess',
INTERACTION_FAILED: 'interactionFailed',
ERROR: 'error', ERROR: 'error',
WARN: 'warn', WARN: 'warn',
DEBUG: 'debug', DEBUG: 'debug',

170
typings/index.d.ts vendored
View File

@ -146,6 +146,7 @@ import {
RawWidgetData, RawWidgetData,
RawWidgetMemberData, RawWidgetMemberData,
} from './rawDataTypes'; } from './rawDataTypes';
import { RelationshipType } from '../src/util/Constants';
//#region Classes //#region Classes
@ -975,6 +976,7 @@ export class Guild extends AnonymousGuild {
public fetchAuditLogs<T extends GuildAuditLogsResolvable = 'ALL'>( public fetchAuditLogs<T extends GuildAuditLogsResolvable = 'ALL'>(
options?: GuildAuditLogsFetchOptions<T>, options?: GuildAuditLogsFetchOptions<T>,
): Promise<GuildAuditLogs<T>>; ): Promise<GuildAuditLogs<T>>;
public searchInteraction(options?: guildSearchInteraction): Promise<void>;
public fetchIntegrations(): Promise<Collection<Snowflake | string, Integration>>; public fetchIntegrations(): Promise<Collection<Snowflake | string, Integration>>;
public fetchOwner(options?: BaseFetchOptions): Promise<GuildMember>; public fetchOwner(options?: BaseFetchOptions): Promise<GuildMember>;
public fetchPreview(): Promise<GuildPreview>; public fetchPreview(): Promise<GuildPreview>;
@ -3886,6 +3888,14 @@ export interface BaseFetchOptions {
force?: boolean; force?: boolean;
} }
export interface guildSearchInteraction {
type?: ApplicationCommandTypes,
query?: String | void,
limit?: Number,
offset?: Number,
botID?: Array<User.id>,
}
export interface BaseMessageComponentOptions { export interface BaseMessageComponentOptions {
type?: MessageComponentType | MessageComponentTypes; type?: MessageComponentType | MessageComponentTypes;
} }
@ -4052,6 +4062,11 @@ export interface ClientEvents extends BaseClientEvents {
data: { count: number; index: number; nonce: string | undefined }, data: { count: number; index: number; nonce: string | undefined },
]; ];
guildMemberUpdate: [oldMember: GuildMember | PartialGuildMember, newMember: GuildMember]; guildMemberUpdate: [oldMember: GuildMember | PartialGuildMember, newMember: GuildMember];
guildMemberListUpdate: [
members: Collection<Snowflake, GuildMember>,
guild: Guild,
data: {}, // see: https://luna.gitlab.io/discord-unofficial-docs/lazy_guilds.html
]
guildUpdate: [oldGuild: Guild, newGuild: Guild]; guildUpdate: [oldGuild: Guild, newGuild: Guild];
inviteCreate: [invite: Invite]; inviteCreate: [invite: Invite];
inviteDelete: [invite: Invite]; inviteDelete: [invite: Invite];
@ -4089,7 +4104,9 @@ export interface ClientEvents extends BaseClientEvents {
webhookUpdate: [channel: TextChannel | NewsChannel]; webhookUpdate: [channel: TextChannel | NewsChannel];
/** @deprecated Use interactionCreate instead */ /** @deprecated Use interactionCreate instead */
interaction: [interaction: Interaction]; interaction: [interaction: Interaction];
interactionCreate: [interaction: Interaction]; interactionCreate: [interaction: Interaction | { nonce: Snowflake, id: Snowflake }];
interactionSuccess: [interaction: { nonce: Snowflake, id: Snowflake }];
interactionFailed: [interaction: { nonce: Snowflake, id: Snowflake }];
shardDisconnect: [closeEvent: CloseEvent, shardId: number]; shardDisconnect: [closeEvent: CloseEvent, shardId: number];
shardError: [error: Error, shardId: number]; shardError: [error: Error, shardId: number];
shardReady: [shardId: number, unavailableGuilds: Set<Snowflake> | undefined]; shardReady: [shardId: number, unavailableGuilds: Set<Snowflake> | undefined];
@ -4106,6 +4123,16 @@ export interface ClientEvents extends BaseClientEvents {
guildScheduledEventDelete: [guildScheduledEvent: GuildScheduledEvent]; guildScheduledEventDelete: [guildScheduledEvent: GuildScheduledEvent];
guildScheduledEventUserAdd: [guildScheduledEvent: GuildScheduledEvent, user: User]; guildScheduledEventUserAdd: [guildScheduledEvent: GuildScheduledEvent, user: User];
guildScheduledEventUserRemove: [guildScheduledEvent: GuildScheduledEvent, user: User]; guildScheduledEventUserRemove: [guildScheduledEvent: GuildScheduledEvent, user: User];
relationshipAdd: [
id: Snowflake,
type: RelationshipType,
user: User,
]
relationshipRemove: [
id: Snowflake,
type: RelationshipType,
user: User,
]
} }
export interface ClientFetchInviteOptions { export interface ClientFetchInviteOptions {
@ -4285,74 +4312,79 @@ export interface ConstantsEvents {
/** @deprecated See [this issue](https://github.com/discord/discord-api-docs/issues/3690) for more information. */ /** @deprecated See [this issue](https://github.com/discord/discord-api-docs/issues/3690) for more information. */
APPLICATION_COMMAND_DELETE: 'applicationCommandDelete'; APPLICATION_COMMAND_DELETE: 'applicationCommandDelete';
/** @deprecated See [this issue](https://github.com/discord/discord-api-docs/issues/3690) for more information. */ /** @deprecated See [this issue](https://github.com/discord/discord-api-docs/issues/3690) for more information. */
APPLICATION_COMMAND_UPDATE: 'applicationCommandUpdate'; APPLICATION_COMMAND_UPDATE: 'applicationCommandUpdate',
GUILD_CREATE: 'guildCreate'; GUILD_CREATE: 'guildCreate',
GUILD_DELETE: 'guildDelete'; GUILD_DELETE: 'guildDelete',
GUILD_UPDATE: 'guildUpdate'; GUILD_UPDATE: 'guildUpdate',
INVITE_CREATE: 'inviteCreate'; GUILD_UNAVAILABLE: 'guildUnavailable',
INVITE_DELETE: 'inviteDelete'; GUILD_MEMBER_ADD: 'guildMemberAdd',
GUILD_UNAVAILABLE: 'guildUnavailable'; GUILD_MEMBER_REMOVE: 'guildMemberRemove',
GUILD_MEMBER_ADD: 'guildMemberAdd'; GUILD_MEMBER_UPDATE: 'guildMemberUpdate',
GUILD_MEMBER_REMOVE: 'guildMemberRemove'; GUILD_MEMBER_AVAILABLE: 'guildMemberAvailable',
GUILD_MEMBER_UPDATE: 'guildMemberUpdate'; GUILD_MEMBERS_CHUNK: 'guildMembersChunk',
GUILD_MEMBER_AVAILABLE: 'guildMemberAvailable'; GUILD_MEMBER_LIST_UPDATE: 'guildMemberListUpdate',
GUILD_MEMBERS_CHUNK: 'guildMembersChunk'; GUILD_INTEGRATIONS_UPDATE: 'guildIntegrationsUpdate',
GUILD_INTEGRATIONS_UPDATE: 'guildIntegrationsUpdate'; GUILD_ROLE_CREATE: 'roleCreate',
GUILD_ROLE_CREATE: 'roleCreate'; GUILD_ROLE_DELETE: 'roleDelete',
GUILD_ROLE_DELETE: 'roleDelete'; INVITE_CREATE: 'inviteCreate',
GUILD_ROLE_UPDATE: 'roleUpdate'; INVITE_DELETE: 'inviteDelete',
GUILD_EMOJI_CREATE: 'emojiCreate'; GUILD_ROLE_UPDATE: 'roleUpdate',
GUILD_EMOJI_DELETE: 'emojiDelete'; GUILD_EMOJI_CREATE: 'emojiCreate',
GUILD_EMOJI_UPDATE: 'emojiUpdate'; GUILD_EMOJI_DELETE: 'emojiDelete',
GUILD_BAN_ADD: 'guildBanAdd'; GUILD_EMOJI_UPDATE: 'emojiUpdate',
GUILD_BAN_REMOVE: 'guildBanRemove'; GUILD_BAN_ADD: 'guildBanAdd',
CHANNEL_CREATE: 'channelCreate'; GUILD_BAN_REMOVE: 'guildBanRemove',
CHANNEL_DELETE: 'channelDelete'; CHANNEL_CREATE: 'channelCreate',
CHANNEL_UPDATE: 'channelUpdate'; CHANNEL_DELETE: 'channelDelete',
CHANNEL_PINS_UPDATE: 'channelPinsUpdate'; CHANNEL_UPDATE: 'channelUpdate',
MESSAGE_CREATE: 'messageCreate'; CHANNEL_PINS_UPDATE: 'channelPinsUpdate',
MESSAGE_DELETE: 'messageDelete'; MESSAGE_CREATE: 'messageCreate',
MESSAGE_UPDATE: 'messageUpdate'; MESSAGE_DELETE: 'messageDelete',
MESSAGE_BULK_DELETE: 'messageDeleteBulk'; MESSAGE_UPDATE: 'messageUpdate',
MESSAGE_REACTION_ADD: 'messageReactionAdd'; MESSAGE_BULK_DELETE: 'messageDeleteBulk',
MESSAGE_REACTION_REMOVE: 'messageReactionRemove'; MESSAGE_REACTION_ADD: 'messageReactionAdd',
MESSAGE_REACTION_REMOVE_ALL: 'messageReactionRemoveAll'; MESSAGE_REACTION_REMOVE: 'messageReactionRemove',
MESSAGE_REACTION_REMOVE_EMOJI: 'messageReactionRemoveEmoji'; MESSAGE_REACTION_REMOVE_ALL: 'messageReactionRemoveAll',
THREAD_CREATE: 'threadCreate'; MESSAGE_REACTION_REMOVE_EMOJI: 'messageReactionRemoveEmoji',
THREAD_DELETE: 'threadDelete'; THREAD_CREATE: 'threadCreate',
THREAD_UPDATE: 'threadUpdate'; THREAD_DELETE: 'threadDelete',
THREAD_LIST_SYNC: 'threadListSync'; THREAD_UPDATE: 'threadUpdate',
THREAD_MEMBER_UPDATE: 'threadMemberUpdate'; THREAD_LIST_SYNC: 'threadListSync',
THREAD_MEMBERS_UPDATE: 'threadMembersUpdate'; THREAD_MEMBER_UPDATE: 'threadMemberUpdate',
USER_UPDATE: 'userUpdate'; THREAD_MEMBERS_UPDATE: 'threadMembersUpdate',
PRESENCE_UPDATE: 'presenceUpdate'; USER_UPDATE: 'userUpdate',
VOICE_SERVER_UPDATE: 'voiceServerUpdate'; PRESENCE_UPDATE: 'presenceUpdate',
VOICE_STATE_UPDATE: 'voiceStateUpdate'; VOICE_SERVER_UPDATE: 'voiceServerUpdate',
TYPING_START: 'typingStart'; VOICE_STATE_UPDATE: 'voiceStateUpdate',
WEBHOOKS_UPDATE: 'webhookUpdate'; TYPING_START: 'typingStart',
INTERACTION_CREATE: 'interactionCreate'; WEBHOOKS_UPDATE: 'webhookUpdate',
ERROR: 'error'; INTERACTION_CREATE: 'interactionCreate',
WARN: 'warn'; INTERACTION_SUCCESS: 'interactionSuccess',
DEBUG: 'debug'; INTERACTION_FAILED: 'interactionFailed',
CACHE_SWEEP: 'cacheSweep'; ERROR: 'error',
SHARD_DISCONNECT: 'shardDisconnect'; WARN: 'warn',
SHARD_ERROR: 'shardError'; DEBUG: 'debug',
SHARD_RECONNECTING: 'shardReconnecting'; CACHE_SWEEP: 'cacheSweep',
SHARD_READY: 'shardReady'; SHARD_DISCONNECT: 'shardDisconnect',
SHARD_RESUME: 'shardResume'; SHARD_ERROR: 'shardError',
INVALIDATED: 'invalidated'; SHARD_RECONNECTING: 'shardReconnecting',
RAW: 'raw'; SHARD_READY: 'shardReady',
STAGE_INSTANCE_CREATE: 'stageInstanceCreate'; SHARD_RESUME: 'shardResume',
STAGE_INSTANCE_UPDATE: 'stageInstanceUpdate'; INVALIDATED: 'invalidated',
STAGE_INSTANCE_DELETE: 'stageInstanceDelete'; RAW: 'raw',
GUILD_STICKER_CREATE: 'stickerCreate'; STAGE_INSTANCE_CREATE: 'stageInstanceCreate',
GUILD_STICKER_DELETE: 'stickerDelete'; STAGE_INSTANCE_UPDATE: 'stageInstanceUpdate',
GUILD_STICKER_UPDATE: 'stickerUpdate'; STAGE_INSTANCE_DELETE: 'stageInstanceDelete',
GUILD_SCHEDULED_EVENT_CREATE: 'guildScheduledEventCreate'; GUILD_STICKER_CREATE: 'stickerCreate',
GUILD_SCHEDULED_EVENT_UPDATE: 'guildScheduledEventUpdate'; GUILD_STICKER_DELETE: 'stickerDelete',
GUILD_SCHEDULED_EVENT_DELETE: 'guildScheduledEventDelete'; GUILD_STICKER_UPDATE: 'stickerUpdate',
GUILD_SCHEDULED_EVENT_USER_ADD: 'guildScheduledEventUserAdd'; GUILD_SCHEDULED_EVENT_CREATE: 'guildScheduledEventCreate',
GUILD_SCHEDULED_EVENT_USER_REMOVE: 'guildScheduledEventUserRemove'; GUILD_SCHEDULED_EVENT_UPDATE: 'guildScheduledEventUpdate',
GUILD_SCHEDULED_EVENT_DELETE: 'guildScheduledEventDelete',
GUILD_SCHEDULED_EVENT_USER_ADD: 'guildScheduledEventUserAdd',
GUILD_SCHEDULED_EVENT_USER_REMOVE: 'guildScheduledEventUserRemove',
RELATIONSHIP_ADD: 'relationshipAdd',
RELATIONSHIP_REMOVE: 'relationshipRemove',
} }
export interface ConstantsOpcodes { export interface ConstantsOpcodes {