Skip to content

Instantly share code, notes, and snippets.

@seabeya
Created August 9, 2024 14:26
Show Gist options
  • Save seabeya/95f2bbbf72e1e73a1133fa462599568a to your computer and use it in GitHub Desktop.
Save seabeya/95f2bbbf72e1e73a1133fa462599568a to your computer and use it in GitHub Desktop.
A console script to repeatedly send Discord bot commands.

A console script to repeatedly send Discord bot commands.

Paste everything below into your browser's F12 console.

  1. The main script:

    class Dishcord {
      #TOKEN = null;
      #PAYLOAD = null;
    
      #TURNS = 0;
      #DELAYS = [3.2, 3.3, 3.4, 3.5, 3.6, 3.7];
    
      constructor(token, payload) {
        this.#TOKEN = token;
        this.#PAYLOAD = payload;
      }
    
      async start(turns) {
        if (turns < 1 || turns === undefined) {
          console.log("Turns can't be less than 1!");
          return;
        }
    
        console.log("Started!");
        this.#TURNS = turns;
    
        while (this.#TURNS > 0) {
          const delay = this.#getRandomDelayInMs();
          this.#send();
          console.log(`delay: ${delay}ms | ${this.#TURNS - 1} turns left`);
          await this.#sleep(delay);
          this.#TURNS--;
        }
      }
    
      stop() {
        this.#TURNS = 0;
        console.log("Stopped!");
      }
    
      #send() {
        const formData = new FormData();
        formData.append(
          "payload_json",
          this.#getPayloadWithUpdatedNonce(PAYLOAD)
        );
    
        fetch(`https://discord.com/api/v9/interactions`, {
          method: "POST",
          headers: {
            Authorization: TOKEN,
          },
          body: formData,
        });
      }
    
      #getPayloadWithUpdatedNonce(payload) {
        const newNonce = this.#generateRandom18DigitNumber();
    
        const jsonPayload = JSON.parse(payload);
        jsonPayload.nonce = newNonce;
    
        return JSON.stringify(jsonPayload);
      }
    
      #generateRandom18DigitNumber() {
        let randomNumber = "";
        for (let i = 0; i < 19; i++) {
          randomNumber += Math.floor(Math.random() * 10);
        }
        return randomNumber;
      }
    
      #getRandomDelayInMs() {
        const randomIndex = Math.floor(Math.random() * this.#DELAYS.length);
        return this.#DELAYS[randomIndex] * 1000;
      }
    
      #sleep(ms) {
        return new Promise((resolve) => setTimeout(resolve, ms));
      }
    }
  2. Credentials:

    • Token:

      You can find your token value in Discord's Local Storage.

      const TOKEN = YOUR_TOKEN_VALUE;
    • Payload:

      To get the payload text: Open the F12 Network tab, go to the Discord channel where you want to automate the command, run the command manually once, find the interactions request in the Network tab, switch to the Payload sub-tab, and copy the text value from { to } (including the brackets).

      const PAYLOAD = `THE_PAYLOAD_TEXT`;
  3. Getting ready:

    const dc = new Dishcord(TOKEN, PAYLOAD);
  4. Getting started:

    • To start:
      dc.start(10);

      This will send the command 10 times. You can change the number to any number you want.

    • To stop:
      dc.stop();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment