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>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>API</strong>](https://github.com/aiko-chan-ai/discord.js-selfbot-v13/blob/main/Document/API.md)
## 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
<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>
```js
@ -57,6 +81,7 @@ await message.contextMenu(botID, commandName);
> 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
- 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>
## MessageEmbed ?

View File

@ -1,6 +1,6 @@
{
"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]",
"main": "./src/index.js",
"types": "./typings/index.d.ts",

View File

@ -60,7 +60,7 @@ class InteractionCreateAction extends Action {
InteractionType = AutocompleteInteraction;
break;
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;
}

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);
if (!guild) return;
const members = new Collection();
// Get Member from side Discord Channel (online counting if large server)
for (const object of data.ops) {
if (object.op == 'SYNC') {
for (const member_ of object.items) {

View File

@ -1,5 +1,7 @@
'use strict';
const { Events } = require('../../../util/Constants');
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_MEMBERS_CHUNK', require('./GUILD_MEMBERS_CHUNK')],
['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_ROLE_CREATE', require('./GUILD_ROLE_CREATE')],
['GUILD_ROLE_DELETE', require('./GUILD_ROLE_DELETE')],
@ -50,6 +54,8 @@ const handlers = Object.fromEntries([
['VOICE_SERVER_UPDATE', require('./VOICE_SERVER_UPDATE')],
['WEBHOOKS_UPDATE', require('./WEBHOOKS_UPDATE')],
['INTERACTION_CREATE', require('./INTERACTION_CREATE')],
['INTERACTION_SUCCESS', require('./INTERACTION_SUCCESS')],
['INTERACTION_FAILED', require('./INTERACTION_FAILED')],
['STAGE_INSTANCE_CREATE', require('./STAGE_INSTANCE_CREATE')],
['STAGE_INSTANCE_UPDATE', require('./STAGE_INSTANCE_UPDATE')],
['STAGE_INSTANCE_DELETE', require('./STAGE_INSTANCE_DELETE')],

View File

@ -84,7 +84,7 @@ class ApplicationCommandManager extends CachedManager {
* .catch(console.error);
*/
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') {
({ guildId, cache = true } = id);
} else if (id) {
@ -92,10 +92,11 @@ class ApplicationCommandManager extends CachedManager {
const existing = this.cache.get(id);
if (existing) return existing;
}
await this.user.createDM().catch(() => {});
const command = await this.commandPath({ id, guildId }).get();
return this._add(command, cache);
}
await this.user.createDM().catch(() => {});
const data = await this.commandPath({ guildId }).get();
return data.reduce((coll, command) => coll.set(command.id, this._add(command, cache, guildId)), new Collection());
}

File diff suppressed because it is too large Load Diff

View File

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

170
typings/index.d.ts vendored
View File

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