Fix Message cannot Send
- Known Issue: Unable to send Embed
This commit is contained in:
parent
8e987355f0
commit
721d1216e0
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "discord.js-selfbot-v13",
|
"name": "discord.js-selfbot-v13",
|
||||||
"version": "0.0.3",
|
"version": "0.1.0",
|
||||||
"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",
|
||||||
@ -44,8 +44,11 @@
|
|||||||
"@sapphire/async-queue": "^1.3.0",
|
"@sapphire/async-queue": "^1.3.0",
|
||||||
"@sapphire/snowflake": "^3.2.0",
|
"@sapphire/snowflake": "^3.2.0",
|
||||||
"@types/ws": "^8.5.2",
|
"@types/ws": "^8.5.2",
|
||||||
|
"axios": "^0.26.1",
|
||||||
"discord-api-types": "^0.27.3",
|
"discord-api-types": "^0.27.3",
|
||||||
|
"discord.js": "^13.6.0",
|
||||||
"form-data": "^4.0.0",
|
"form-data": "^4.0.0",
|
||||||
|
"json-bigint": "^1.0.0",
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
"lodash.snakecase": "^4.1.1",
|
"lodash.snakecase": "^4.1.1",
|
||||||
"node-fetch": "^3.2.2",
|
"node-fetch": "^3.2.2",
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const { Buffer } = require('node:buffer');
|
const { Buffer } = require('node:buffer');
|
||||||
const { isJSONEncodable } = require('@discordjs/builders');
|
const { BaseMessageComponent, MessageEmbed } = require('discord.js');
|
||||||
const { MessageFlags } = require('discord-api-types/v9');
|
const { MessageFlags } = require('discord-api-types/v9');
|
||||||
const { RangeError } = require('../errors');
|
const { RangeError } = require('../errors');
|
||||||
const DataResolver = require('../util/DataResolver');
|
const DataResolver = require('../util/DataResolver');
|
||||||
@ -109,7 +109,6 @@ class MessagePayload {
|
|||||||
|
|
||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolves the body.
|
* Resolves the body.
|
||||||
* @returns {MessagePayload}
|
* @returns {MessagePayload}
|
||||||
@ -131,8 +130,8 @@ class MessagePayload {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const components = this.options.components?.map(c =>
|
const components = this.options.components?.map((c) =>
|
||||||
isJSONEncodable(c) ? c.toJSON() : this.target.client.options.jsonTransformer(c),
|
BaseMessageComponent.create(c).toJSON(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let username;
|
let username;
|
||||||
@ -196,18 +195,23 @@ class MessagePayload {
|
|||||||
content,
|
content,
|
||||||
tts,
|
tts,
|
||||||
nonce,
|
nonce,
|
||||||
embeds: this.options.embeds?.map(embed =>
|
embeds: this.options.embeds?.map((embed) =>
|
||||||
isJSONEncodable(embed) ? embed.toJSON() : this.target.client.options.jsonTransformer(embed),
|
new MessageEmbed(embed).toJSON(),
|
||||||
),
|
),
|
||||||
components,
|
components,
|
||||||
username,
|
username,
|
||||||
avatar_url: avatarURL,
|
avatar_url: avatarURL,
|
||||||
allowed_mentions:
|
allowed_mentions:
|
||||||
typeof content === 'undefined' && typeof message_reference === 'undefined' ? undefined : allowedMentions,
|
typeof content === 'undefined' &&
|
||||||
|
typeof message_reference === 'undefined'
|
||||||
|
? undefined
|
||||||
|
: allowedMentions,
|
||||||
flags,
|
flags,
|
||||||
message_reference,
|
message_reference,
|
||||||
attachments: this.options.attachments,
|
attachments: this.options.attachments,
|
||||||
sticker_ids: this.options.stickers?.map(sticker => sticker.id ?? sticker),
|
sticker_ids: this.options.stickers?.map(
|
||||||
|
(sticker) => sticker.id ?? sticker,
|
||||||
|
),
|
||||||
};
|
};
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,49 @@ const { TypeError, Error } = require('../../errors');
|
|||||||
const InteractionCollector = require('../InteractionCollector');
|
const InteractionCollector = require('../InteractionCollector');
|
||||||
const MessageCollector = require('../MessageCollector');
|
const MessageCollector = require('../MessageCollector');
|
||||||
const MessagePayload = require('../MessagePayload');
|
const MessagePayload = require('../MessagePayload');
|
||||||
|
const DiscordAPIError = require('../../rest/DiscordAPIError');
|
||||||
|
|
||||||
|
const _send = (client, channelID, data, files) => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
require('axios')({
|
||||||
|
method: 'post',
|
||||||
|
url: `${client.options.http.api}/v${client.options.http.version}/channels/${channelID}/messages`,
|
||||||
|
headers: {
|
||||||
|
authorization: client.token,
|
||||||
|
Accept: '*/*',
|
||||||
|
'Accept-Language': 'en-US,en;q=0.9',
|
||||||
|
'Cache-Control': 'no-cache',
|
||||||
|
Pragma: 'no-cache',
|
||||||
|
Referer: 'https://discord.com/channels/@me',
|
||||||
|
'Sec-Ch-Ua': '" Not A;Brand";v="99" "',
|
||||||
|
'Sec-Ch-Ua-Mobile': '?0',
|
||||||
|
'Sec-Ch-Ua-Platform': '"iOS"',
|
||||||
|
'Sec-Fetch-Dest': 'empty',
|
||||||
|
'Sec-Fetch-Mode': 'cors',
|
||||||
|
'Sec-Fetch-Site': 'same-origin',
|
||||||
|
'X-Debug-Options': 'bugReporterEnabled',
|
||||||
|
'X-Discord-Locale': 'en-US',
|
||||||
|
Origin: 'https://discord.com',
|
||||||
|
},
|
||||||
|
data,
|
||||||
|
files,
|
||||||
|
})
|
||||||
|
.then((res) => resolve(res.data))
|
||||||
|
.catch((err) => {
|
||||||
|
err.request.options = {
|
||||||
|
data,
|
||||||
|
files,
|
||||||
|
};
|
||||||
|
return reject(
|
||||||
|
new DiscordAPIError(
|
||||||
|
err.response.data,
|
||||||
|
err.response.status,
|
||||||
|
err.request,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Interface for classes that have text-channel-like features.
|
* Interface for classes that have text-channel-like features.
|
||||||
* @interface
|
* @interface
|
||||||
@ -173,12 +215,15 @@ class TextBasedChannel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const { body, files } = await messagePayload.resolveFiles();
|
const { body, files } = await messagePayload.resolveFiles();
|
||||||
const d = await this.client.api.channels[this.id].messages.post({ body, files });
|
console.log(body);
|
||||||
|
// const d = await this.client.api.channels[this.id].messages.post({ body, files });
|
||||||
|
const d = await _send(this.client, this.id, body, files);
|
||||||
|
console.log(d);
|
||||||
await this.client.api.channels(this.id).typing.delete();
|
await this.client.api.channels(this.id).typing.delete();
|
||||||
return this.messages.cache.get(d.id) ?? this.messages._add(d);
|
return this.messages.cache.get(d.id) ?? this.messages._add(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Patch send message [fck :(]
|
||||||
/**
|
/**
|
||||||
* Sends a typing indicator in the channel.
|
* Sends a typing indicator in the channel.
|
||||||
* @returns {Promise<void>} Resolves upon the typing status being sent
|
* @returns {Promise<void>} Resolves upon the typing status being sent
|
||||||
@ -294,22 +339,35 @@ class TextBasedChannel {
|
|||||||
*/
|
*/
|
||||||
async bulkDelete(messages, filterOld = false) {
|
async bulkDelete(messages, filterOld = false) {
|
||||||
if (Array.isArray(messages) || messages instanceof Collection) {
|
if (Array.isArray(messages) || messages instanceof Collection) {
|
||||||
let messageIds = messages instanceof Collection ? [...messages.keys()] : messages.map(m => m.id ?? m);
|
let messageIds =
|
||||||
|
messages instanceof Collection
|
||||||
|
? [...messages.keys()]
|
||||||
|
: messages.map((m) => m.id ?? m);
|
||||||
if (filterOld) {
|
if (filterOld) {
|
||||||
messageIds = messageIds.filter(id => Date.now() - DiscordSnowflake.timestampFrom(id) < 1_209_600_000);
|
messageIds = messageIds.filter(
|
||||||
|
(id) =>
|
||||||
|
Date.now() - DiscordSnowflake.timestampFrom(id) < 1_209_600_000,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
if (messageIds.length === 0) return new Collection();
|
if (messageIds.length === 0) return new Collection();
|
||||||
if (messageIds.length === 1) {
|
if (messageIds.length === 1) {
|
||||||
await this.client.api.channels(this.id).messages(messageIds[0]).delete();
|
await this.client.api
|
||||||
|
.channels(this.id)
|
||||||
|
.messages(messageIds[0])
|
||||||
|
.delete();
|
||||||
const message = this.client.actions.MessageDelete.getMessage(
|
const message = this.client.actions.MessageDelete.getMessage(
|
||||||
{
|
{
|
||||||
message_id: messageIds[0],
|
message_id: messageIds[0],
|
||||||
},
|
},
|
||||||
this,
|
this,
|
||||||
);
|
);
|
||||||
return message ? new Collection([[message.id, message]]) : new Collection();
|
return message
|
||||||
|
? new Collection([[message.id, message]])
|
||||||
|
: new Collection();
|
||||||
}
|
}
|
||||||
await this.client.api.channels(this.id).messages['bulk-delete'].post({ body: { messages: messageIds } });
|
await this.client.api
|
||||||
|
.channels(this.id)
|
||||||
|
.messages['bulk-delete'].post({ body: { messages: messageIds } });
|
||||||
return messageIds.reduce(
|
return messageIds.reduce(
|
||||||
(col, id) =>
|
(col, id) =>
|
||||||
col.set(
|
col.set(
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
const process = require('node:process');
|
const process = require('node:process');
|
||||||
const Transformers = require('./Transformers');
|
const Transformers = require('./Transformers');
|
||||||
|
const JSONBig = require('json-bigint');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {Function} CacheFactory
|
* @typedef {Function} CacheFactory
|
||||||
@ -101,21 +102,22 @@ class Options extends null {
|
|||||||
},
|
},
|
||||||
http: {
|
http: {
|
||||||
headers: {
|
headers: {
|
||||||
"Accept": "*/*",
|
Accept: '*/*',
|
||||||
"Accept-Encoding": "gzip, deflate, br",
|
// 'Accept-Encoding': 'gzip, deflate, br',
|
||||||
"Accept-Language": 'en-US,en;q=0.9',
|
'Accept-Language': 'en-US,en;q=0.9',
|
||||||
"Cache-Control": "no-cache",
|
'Cache-Control': 'no-cache',
|
||||||
"Pragma": "no-cache",
|
'Content-Type': 'application/json',
|
||||||
"Referer": "https://discord.com/channels/@me",
|
Pragma: 'no-cache',
|
||||||
"Sec-Ch-Ua": '" Not A;Brand";v="99" "',
|
Referer: 'https://discord.com/channels/@me',
|
||||||
"Sec-Ch-Ua-Mobile": '?0',
|
'Sec-Ch-Ua': '" Not A;Brand";v="99" "',
|
||||||
"Sec-Ch-Ua-Platform": '"iOS"',
|
'Sec-Ch-Ua-Mobile': '?0',
|
||||||
"Sec-Fetch-Dest": "empty",
|
'Sec-Ch-Ua-Platform': '"iOS"',
|
||||||
"Sec-Fetch-Mode": "cors",
|
'Sec-Fetch-Dest': 'empty',
|
||||||
"Sec-Fetch-Site": "same-origin",
|
'Sec-Fetch-Mode': 'cors',
|
||||||
"X-Debug-Options": "bugReporterEnabled",
|
'Sec-Fetch-Site': 'same-origin',
|
||||||
"X-Discord-Locale": 'en-US',
|
'X-Debug-Options': 'bugReporterEnabled',
|
||||||
"Origin": "https://discord.com"
|
'X-Discord-Locale': 'en-US',
|
||||||
|
Origin: 'https://discord.com',
|
||||||
},
|
},
|
||||||
agent: {},
|
agent: {},
|
||||||
version: 9,
|
version: 9,
|
||||||
@ -125,6 +127,7 @@ class Options extends null {
|
|||||||
template: 'https://discord.new',
|
template: 'https://discord.new',
|
||||||
scheduledEvent: 'https://discord.com/events',
|
scheduledEvent: 'https://discord.com/events',
|
||||||
},
|
},
|
||||||
|
jsonTransformer: (object) => JSONBig.stringify(object),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user