Skip to content

Instantly share code, notes, and snippets.

@CodeF53
Last active July 31, 2023 22:57
Show Gist options
  • Save CodeF53/46ccfb2c0f00c99b935f0272cceedd86 to your computer and use it in GitHub Desktop.
Save CodeF53/46ccfb2c0f00c99b935f0272cceedd86 to your computer and use it in GitHub Desktop.
Horse Reactor
(() => {
// Edit this stuff to configure where and who you are horse reacting
const serverId = '398590278404931584' // Max0r's server
const channelId = '717498714259980378' // memes channel
// const userId = '629352120231133190' // Snaxy
const userId = '355016563109396482' // Kyuri
// use discord's internal request api, so we don't need to worry about session cookies
const wreq = webpackChunkdiscord_app.push([[Symbol()],{},r=>r])
webpackChunkdiscord_app.pop()
const RestAPI = Object.values(wreq.c).find(m => m.exports?.ZP?.getAPIBaseURL).exports.ZP
// `await sleep(500)` -> waits 500 milliseconds
const sleep = time => new Promise(res => setTimeout(res, time));
// reacts to target `messageId` with 🐴
async function horseReact(messageId) {
try {
return await RestAPI.put({url: `/channels/${channelId}/messages/${messageId}/reactions/🐴/@me`})
} catch (error) {
// if request failed, wait 30 seconds to reset rate limit timer, then try again
await sleep(30000)
return await horseReact(messageId)
}
}
// gets the 25 oldest messages from `userId` in `channelId` in `serverId`
// offset offsets the search to newer messages
async function search(offset) {
try {
return await RestAPI.get({url: `/guilds/${serverId}/messages/search?channel_id=${channelId}&author_id=${userId}&include_nsfw=true&sort_by=timestamp&sort_order=asc&offset=${offset}`})
} catch (error) {
// if request failed, wait 30 seconds to reset rate limit timer, then try again
await sleep(30000)
return await search(offset)
}
}
// gets all the messages from `userId` in `channelId` in serverId
// most of the logic is to bypass the 25 message limit that search imposes
async function getMessageIds() {
let messageIds = []
let totalResults = 25 // dummy number to let first cycle get number of results
while (totalResults - messageIds.length > 0) {
const resp = await search(messageIds.length)
// save total results so we know when to end, limited to 5000 because discords search is dumb
totalResults = Math.min(resp.body.total_results, 5000)
// get the ids
messageIds.push(...resp.body.messages.map(message => message[0].id))
console.log(`${messageIds.length} / ${totalResults} messages collected`)
// prevent getting rate limited
await sleep(500)
}
return messageIds
}
async function reactAllHorse() {
const messageIds = await getMessageIds()
for (let i = 0; i < messageIds.length; i++) {
const messageId = messageIds[i];
await horseReact(messageId)
console.log(`${i} / ${messageIds.length} messages 🐴 reacted`)
// wait a bit before next reaction to prevent getting rate limited
await sleep(500)
}
}
reactAllHorse()
})()

Horse Reactor

There is an excellent meme in Max0r's discord where for some reason we just react to certain peoples messages with horses

See this lore video: https://cdn.discordapp.com/attachments/717498714259980378/1135618996050342019/snaxy.mov

Anyways, I decided it would be a good idea to make a script to automate horse reacting to every message ever by a certian user within a channel

How to use:

Open discord, and use ctrlshifti to open the developer console

Click the "console" tab, paste the contents of horseReact.js into the console, and press enter

I reccomend running this before you go to bed, as getting and reacting to all the messages takes a very very long time due to discord's ratelimits.

Configuring the script:

The script is pre-configured to horse react to Kyuri's messages within the Memes channel of Max0r's discord.

This can be modified by editing the serverId, channelId, and userId variables to fit a specific Server, Channel, and User.

Safety of the script:

Technically this is a selfbot, so is against discord's TOS.

The script takes large delays between each action, so I doubt it will actually lead to anyone getting banned.

When discord does rate limit you for using the script, it waits 30 seconds before retrying.

Etc:

Discord won't let you use a search offset > 5000, so this script will only ever react to the first 5000 messages sent by a user in the channel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment