Skip to content

Commit

Permalink
1.3.4
Browse files Browse the repository at this point in the history
Get interaction commands using gateway
  • Loading branch information
aiko-chan-ai committed Apr 12, 2022
1 parent f73525f commit d78a10e
Show file tree
Hide file tree
Showing 15 changed files with 1,791 additions and 1,536 deletions.
1 change: 1 addition & 0 deletions DOCUMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
68 changes: 68 additions & 0 deletions Document/API.md
Original file line number Diff line number Diff line change
@@ -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: {},
});
```
25 changes: 25 additions & 0 deletions Document/Message.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 ?
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/client/actions/InteractionCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
10 changes: 10 additions & 0 deletions src/client/websocket/handlers/GUILD_APPLICATION_COMMANDS_UPDATE.js
Original file line number Diff line number Diff line change
@@ -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);
};
};
1 change: 1 addition & 0 deletions src/client/websocket/handlers/GUILD_MEMBER_LIST_UPDATE.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 3 additions & 1 deletion src/client/websocket/handlers/INTERACTION_CREATE.js
Original file line number Diff line number Diff line change
@@ -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);
};
6 changes: 6 additions & 0 deletions src/client/websocket/handlers/INTERACTION_FAILED.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
'use strict';
const { Events } = require('../../../util/Constants');

module.exports = (client, { d: data }) => {
client.emit(Events.INTERACTION_FAILED, data);
};
6 changes: 6 additions & 0 deletions src/client/websocket/handlers/INTERACTION_SUCCESS.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
'use strict';
const { Events } = require('../../../util/Constants');

module.exports = (client, { d: data }) => {
client.emit(Events.INTERACTION_SUCCESS, data);
};
6 changes: 6 additions & 0 deletions src/client/websocket/handlers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')],
Expand Down Expand Up @@ -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')],
Expand Down
5 changes: 3 additions & 2 deletions src/managers/ApplicationCommandManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,19 @@ 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) {
if (!force) {
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());
}
Expand Down
Loading

0 comments on commit d78a10e

Please sign in to comment.