From 29e65bf40418c4aff2b045d2b50b0ae88cfe5598 Mon Sep 17 00:00:00 2001 From: rigwild Date: Sun, 13 Jun 2021 21:49:14 +0200 Subject: [PATCH] Add more functions --- .prettierrc.js | 9 +++++ README.md | 106 +++++++++++++++++++++++++++---------------------- index.js | 91 ++++++++++++++++++++++++++---------------- 3 files changed, 123 insertions(+), 83 deletions(-) create mode 100644 .prettierrc.js diff --git a/.prettierrc.js b/.prettierrc.js new file mode 100644 index 0000000..6f32db5 --- /dev/null +++ b/.prettierrc.js @@ -0,0 +1,9 @@ +module.exports = { + semi: false, + singleQuote: true, + printWidth: 200, + useTabs: false, + vueIndentScriptAndStyle: false, + trailingComma: 'none', + arrowParens: 'avoid' +} diff --git a/README.md b/README.md index c6d40c9..ee806c3 100644 --- a/README.md +++ b/README.md @@ -18,9 +18,7 @@ Automating user accounts is against [Discord's Terms of Service](https://discord You can now use any function one by one as you like directly in the console `await api.someFunction()`. Don't forget `await` or the server's response will not be printed to the console. -```js -await api.sendMessage('channel_id', 'Hello!') -``` +Use the `id()` function to update the variable `gid` guild id and `cid` channel id to what you are currently watching. **Note:** It's a good idea to wrap your code in its own scope `{ code }` or you might get an error when reusing the same variable names later! @@ -28,11 +26,12 @@ await api.sendMessage('channel_id', 'Hello!') ## Basic example -Get the last 100 messages of a channel, send a message to it, edit it then delete it. +Update `cid` to the channel you are watching, get the last 100 messages, send a message, edit then delete. ```js { - let channelId = '826934811846377545' + id() + let channelId = cid // Send a message let sentMessage = await api.sendMessage(channelId, 'Hello!') @@ -57,7 +56,8 @@ You can use `loop = false` at any time to stop it. ```js { - let channelId = '826934811846377545' + id() + let channelId = cid let message = 'Hi, I like spamming 🦜' var loop = true @@ -85,7 +85,8 @@ Discord recently made its rate limiting strictier. I recommend 1100ms as a minim ```js { - let channelId = '826934811846377545' + id() + let channelId = cid let userId = '012345678987654321' let amount = 99999999 let delayMs = 1100 @@ -135,6 +136,41 @@ Discord recently made its rate limiting strictier. I recommend 1100ms as a minim # API +## Full list + +Here is the full list of available functions, check [`index.js`](./index.js). + +- `id()` +- `delay(ms) ` +- `api.apiCall(apiPath, body, method = 'GET')` +- `api.getMessages(channelId, params = {})` +- `api.sendMessage(channelId, message, tts, body = {})` +- `api.editMessage(channelId, messageId, newMessage, body = {})` +- `api.deleteMessage(channelId, messageId)` +- `api.sendEmbed(channelId, title, description, color)` +- `api.auditLog(guildId)` +- `api.getRoles(guildId)` +- `api.createRole(guildId, name)` +- `api.deleteRole(guildId, roleId)` +- `api.getBans(guildId)` +- `api.banUser(guildId, userId, reason)` +- `api.unbanUser(guildId, userId)` +- `api.kickUser(guildId, userId)` +- `api.addRole(guildId, userId, roleId)` +- `api.removeRole(guildId, userId, roleId)` +- `api.getChannels(guildId)` +- `api.createChannel(guildId, name, type)` +- `api.pinnedMessages(channelId)` +- `api.addPin(channelId, messageId)` +- `api.deletePin(channelId, messageId)` +- `api.changeNick(guildId, nick)` +- `api.leaveServer(guildId)` +- `api.getDMs()` +- `api.getUser(userId)` +- `api.addReaction(channelId, messageId, emojiUrl)` +- `api.deleteReaction(channelId, messageId, emojiUrl)` +- `api.typing(channelId)` + ## `delay(ms)` `delay(ms: number) => Promise` @@ -145,6 +181,16 @@ Wait for `ms` milliseconds. await delay(1500) ``` +## `id()` + +`id() => void` + +Update the variable `gid` guild id and `cid` channel id to what you are currently watching in the Discord client. + +```js +id() +``` + ## `api.getMessages(channelId)` `api.getMessages(channelId: string) => Promise` @@ -153,13 +199,9 @@ Get the last 100 messages from a channel (`channelId`). https://discord.com/developers/docs/resources/channel#get-channel-messages -```js -await api.getMessages('826934811846377545') -``` - ```js { - let messages = await api.getMessages('826934811846377545') + let messages = await api.getMessages(cid) messages[0].author.username } ``` @@ -173,15 +215,7 @@ Send a `message` to a channel (`channelId`) with Text To Speach (`tts`, off by d https://discord.com/developers/docs/resources/channel#create-message ```js -await api.sendMessage('826934811846377545', 'Hello!') -await api.sendMessage('826934811846377545', 'Hello!', true) -``` - -```js -{ - let message = await api.sendMessage('826934811846377545', 'Hello!') - message.id -} +await api.sendMessage(cid, 'Hello!') ``` ## `api.editMessage(channelId, messageId, newMessage)` @@ -193,14 +227,7 @@ Edit a message (`messageId`) from a channel (`channelId`) and replace its conten https://discord.com/developers/docs/resources/channel#edit-message ```js -await api.editMessage('826934811846377545', '853663267628122122', 'Hello! You good? 😊') -``` - -```js -{ - let message = await api.editMessage('826934811846377545', '853663267628122122', 'Hello! You good? 😊') - message.content -} +await api.editMessage(cid, 'message_id', 'Hello! You good? 😊') ``` ## `api.deleteMessage(channelId, messageId)` @@ -212,24 +239,7 @@ Delete a message (`messageId`) from a channel (`channelId`). https://discord.com/developers/docs/resources/channel#delete-message ```js -await api.deleteMessage('826934811846377545', '853663267628122122') -``` - -```js -{ - let messages = await api.deleteMessage('826934811846377545', '853663267628122122') - messages[0] -} -``` - -## `api.apiCall(apiPath, body, method)` - -`api.apiCall(apiPath: string, body: any, method = 'GET') => Promise` - -Do a raw API call. - -```js -await api.apiCall(`/channels/${channelId}/messages`, { content: message }, 'POST') +await api.deleteMessage(cid, 'message_id') ``` # FAQ @@ -256,7 +266,7 @@ Post your requests in the [Discussions](https://github.com/rigwild/discord-self- ## I made a nice/useful script, can I share? -Of course! Post the [Discussions](https://github.com/rigwild/discord-self-bot-console/discussions) tab. Please search if a similar script was shared earlier before posting. +Of course! Post it in the [Discussions](https://github.com/rigwild/discord-self-bot-console/discussions) tab. Please search if a similar script was shared earlier before posting. ## Why this repo? diff --git a/index.js b/index.js index 753f73f..ccafefd 100644 --- a/index.js +++ b/index.js @@ -8,8 +8,7 @@ .join('&') const apiCall = (apiPath, body, method = 'GET') => { - if (!authHeader) - throw new Error("The authorization token is missing. Did you forget set it? `authHeader = 'your_token'`") + if (!authHeader) throw new Error("The authorization token is missing. Did you forget set it? `authHeader = 'your_token'`") return fetch(`${apiPrefix}${apiPath}`, { body: body ? JSON.stringify(body) : undefined, method, @@ -18,8 +17,7 @@ 'Accept-Language': 'en-US', Authorization: authHeader, 'Content-Type': 'application/json', - 'User-Agent': - 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) discord/1.0.9002 Chrome/83.0.4103.122 Electron/9.3.5 Safari/537.36' + 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) discord/1.0.9002 Chrome/83.0.4103.122 Electron/9.3.5 Safari/537.36' } }) .then(res => res.json().catch(() => {})) @@ -27,42 +25,65 @@ } var api = { - /** - * Get the last 100 messages from a channel - * @see https://discord.com/developers/docs/resources/channel#get-channel-messages - */ - getMessages(channelId, params = {}) { - return apiCall(`/channels/${channelId}/messages?limit=100&${qs(params)}`) - }, - - /** - * Send a message in a channel - * @see https://discord.com/developers/docs/resources/channel#create-message - */ - sendMessage(channelId, message, tts, body = {}) { - return apiCall(`/channels/${channelId}/messages`, { content: message, tts: !!tts, ...body }, 'POST') - }, - - /** - * Edit a message - * @see https://discord.com/developers/docs/resources/channel#edit-message - */ - editMessage(channelId, messageId, newMessage, body = {}) { - return apiCall(`/channels/${channelId}/messages/${messageId}`, { content: newMessage, ...body }, 'PATCH') - }, - - /** - * Delete a message from a channel - * @see https://discord.com/developers/docs/resources/channel#delete-message - */ - deleteMessage(channelId, messageId) { - return apiCall(`/channels/${channelId}/messages/${messageId}`, null, 'DELETE') - }, + getMessages: (channelId, params = {}) => apiCall(`/channels/${channelId}/messages?limit=100&${qs(params)}`), + sendMessage: (channelId, message, tts, body = {}) => apiCall(`/channels/${channelId}/messages`, { content: message, tts: !!tts, ...body }, 'POST'), + editMessage: (channelId, messageId, newMessage, body = {}) => apiCall(`/channels/${channelId}/messages/${messageId}`, { content: newMessage, ...body }, 'PATCH'), + deleteMessage: (channelId, messageId) => apiCall(`/channels/${channelId}/messages/${messageId}`, null, 'DELETE'), + + sendEmbed: (channelId, title, description, color) => apiCall(`/channels/${channelId}/messages`, { tts: false, embed: { title, description, color } }, 'POST'), + + auditLog: guildId => apiCall(`/guilds/${guildId}/audit-logs`), + + getRoles: guildId => apiCall(`/guilds/${guildId}/roles`), + createRole: (guildId, name) => apiCall(`/guilds/${guildId}/roles`, { name }, 'POST'), + deleteRole: (guildId, roleId) => apiCall(`/guilds/${guildId}/roles/${roleId}`, null, 'DELETE'), + + getBans: guildId => apiCall(`/guilds/${guildId}/bans`), + banUser: (guildId, userId, reason) => apiCall(`/guilds/${guildId}/bans/${userId}`, { delete_message_days: '7', reason }, 'PUT'), + unbanUser: (guildId, userId) => apiCall(`/guilds/${guildId}/bans/${userId}`, null, 'DELETE'), + kickUser: (guildId, userId) => apiCall(`/guilds/${guildId}/members/${userId}`, null, 'DELETE'), + + addRole: (guildId, userId, roleId) => apiCall(`/guilds/${guildId}/members/${userId}/roles/${roleId}`, null, 'PUT'), + removeRole: (guildId, userId, roleId) => apiCall(`/guilds/${guildId}/members/${userId}/roles/${roleId}`, null, 'DELETE'), + + getChannels: guildId => apiCall(`/guilds/${guildId}/channels`), + createChannel: (guildId, name, type) => apiCall(`/guilds/${guildId}/channels`, { name, type }, 'POST'), + + pinnedMessages: channelId => apiCall(`/channels/${channelId}/pins`), + addPin: (channelId, messageId) => apiCall(`/channels/${channelId}/pins/${messageId}`, null, 'PUT'), + deletePin: (channelId, messageId) => apiCall(`/channels/${channelId}/pins/${messageId}`, null, 'DELETE'), + + changeNick: (guildId, nick) => apiCall(`/guilds/${guildId}/members/@me/nick`, { nick }, 'PATCH'), + leaveServer: guildId => apiCall(`/users/@me/guilds/${guildId}`, null, 'DELETE'), + + getDMs: () => apiCall(`/users/@me/channels`), + getUser: userId => apiCall(`/users/${userId}`), + + addReaction: (channelId, messageId, emojiUrl) => apiCall(`/channels/${channelId}/messages/${messageId}/reactions/${emojiUrl}/@me`, null, 'PUT'), + deleteReaction: (channelId, messageId, emojiUrl) => apiCall(`/channels/${channelId}/messages/${messageId}/reactions/${emojiUrl}/@me`, null, 'DELETE'), + + typing: channelId => apiCall(`/channels/${channelId}/typing`, null, 'POST'), delay, apiCall } + console.log('\n\n\n\nSelfbot loaded! Use it like this: `await api.someFunction()`') + console.log('Abusing this could get you banned from Discord, use at your own risk!') + console.log() + console.log('Use the `id()` function to update the variable `gid` guild id and `cid` channel id to what you are currently watching.') + console.log('https://github.com/rigwild/discord-self-bot-console') + + var gid = '' // Current guild id + var cid = '' // Current channel id + + // Call this to update `cid` and `gid` to current channel and guild id + var id = () => { + gid = window.location.href.split('/').slice(4)[0] + cid = window.location.href.split('/').slice(4)[1] + } + id() + // Set your `Authorization` token here var authHeader = '' }