From f5d246984236991b35f293058d9298837c54703e Mon Sep 17 00:00:00 2001 From: March 7th <71698422+aiko-chan-ai@users.noreply.github.com> Date: Mon, 21 Mar 2022 12:16:46 +0700 Subject: [PATCH] Fix MessageEdit Know: Webhook Edit error --- package.json | 2 +- src/managers/MessageManager.js | 48 ++++++++++++++++++- src/structures/interfaces/TextBasedChannel.js | 1 - 3 files changed, 47 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 82845d4..62111eb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "discord.js-selfbot-v13", - "version": "0.1.4", + "version": "0.1.5", "description": "A unofficial discord.js fork for creating selfbots [Based on discord.js v13]", "main": "./src/index.js", "types": "./typings/index.d.ts", diff --git a/src/managers/MessageManager.js b/src/managers/MessageManager.js index 6f67f2d..ca928b0 100644 --- a/src/managers/MessageManager.js +++ b/src/managers/MessageManager.js @@ -7,6 +7,50 @@ const { TypeError } = require('../errors'); const { Message } = require('../structures/Message'); const MessagePayload = require('../structures/MessagePayload'); const Util = require('../util/Util'); +const DiscordAPIError = require('../rest/DiscordAPIError'); + +const _edit = (client, channelID, messageID, data, files) => { + return new Promise((resolve, reject) => { + require('axios')({ + method: 'patch', + url: `${client.options.http.api}/v${client.options.http.version}/channels/${channelID}/messages/${messageID}`, + 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, + ), + ); + }); + }); +}; + /** * Manages API methods for Messages and holds their cache. @@ -130,8 +174,8 @@ class MessageManager extends CachedManager { ) .resolveBody() .resolveFiles(); - const d = await this.client.api.channels(this.channel.id).messages(messageId).patch({ body, files }); - + // const d = await this.client.api.channels(this.channel.id).messages(messageId).patch({ body, files }); + const d = await _edit(this.client, this.channel.id, messageId, body, files); const existing = this.cache.get(messageId); if (existing) { const clone = existing._clone(); diff --git a/src/structures/interfaces/TextBasedChannel.js b/src/structures/interfaces/TextBasedChannel.js index dd760e9..ab4a796 100644 --- a/src/structures/interfaces/TextBasedChannel.js +++ b/src/structures/interfaces/TextBasedChannel.js @@ -215,7 +215,6 @@ class TextBasedChannel { } const { body, files } = await messagePayload.resolveFiles(); - 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); return this.messages.cache.get(d.id) ?? this.messages._add(d);