Skip to content

Instantly share code, notes, and snippets.

@rigwild
Last active April 9, 2022 20:37
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save rigwild/28f5d9479e3e122070e27db84e104719 to your computer and use it in GitHub Desktop.
Save rigwild/28f5d9479e3e122070e27db84e104719 to your computer and use it in GitHub Desktop.
This has moved to https://github.com/rigwild/discord-self-bot-console --- A simple Discord Self-bot using console
// Due to some interest, I created a proper repo.
// Check it out! :)
// https://github.com/rigwild/discord-self-bot-console
@rigwild
Copy link
Author

rigwild commented Jul 24, 2020

@KuroRXX good job :)
It may help to also provide an unminified version though

@KaliyaAlkaline
Copy link

@KuroRXX good job :)
It may help to also provide an unminified version though

I actually added in those features after messing with your already made function "apiCall", by the time I was editing it I already put the original in a code compressor. Most of this was just me going through the discord API endpoint list and spending hours making functions for them. Mostly copy paste and a little editing.

@micc281
Copy link

micc281 commented Aug 12, 2020

Hey! I was wondering if it was okay if I used this to make a library but adding more and stuff? Or adding more things to the api.

@rigwild
Copy link
Author

rigwild commented Aug 12, 2020

@micc281 no problem :) don't forget to add rigwild <me@rigwild.dev> in your license 😁

@micc281
Copy link

micc281 commented Aug 13, 2020

@rigwild
Will do! Although this may take a while. I am a slow programmer and I have come into my first issue using fetch :/ But none the less I will put you in!!

Edit: I just realized this is not what I thought it was. But thank you anyway for introducing me into the discord api, I will give you credit still.

@dis-chord-dev
Copy link

dis-chord-dev commented Aug 28, 2020

Ok Hey. So I am micc281 I have a new account for making my discord lib and I had to rewrite your entire fetch code. Well not entirely but most so yeah that my progress.
Cool! my code doesn't work with Other methods but get

@DeadLyBro
Copy link

To fix Api/V6 error replace this api prefix code; ( Now working. )
apiPrefix = 'https://discord.com/api/v8'

@BryanBarrera
Copy link

BryanBarrera commented Dec 28, 2020

How can we modify this script to send a message every minute? @rigwild

@SkellyM386
Copy link

this still works?

@rigwild
Copy link
Author

rigwild commented Jan 19, 2021

Sorry for the late reply!

@BryanBarrera

How can we modify this script to send a message every minute?

loop = true
count = 0
setup = async () => {
  while (loop) {
  	const test2 = await api.sendMessage('channel_id', 'your_message')
  	console.log(`Sent ${++count} messages`)
  	await timeout(61000) // 61 seconds
  }
}

setup()

When you want to stop it you can simply use

loop = false

this still works?

I just updated the API uri to the new domain (discord.com), it's working.


Please tell me if you think I should open a proper GitHub repository for this as it's getting a lot of attention. Did you get here by googling discord self bot ?

@SkellyM386
Copy link

Yes you should start a repository and i have this project id like to discuss with you that i dont know much about cause theres no public info but you seem to understand the discord user api better than me. If youve got the time

@BryanBarrera
Copy link

BryanBarrera commented Jan 20, 2021

I agree. Please create a repository. @rigwild

@rigwild, how could we have two messages with 2 different timers? One message works perfect with the snippet you provided.

@SkellyM386
Copy link

SkellyM386 commented Jan 20, 2021

@BryanBarrera im goint to format his example a little differently bare in mind but

loop = Infinity
count = 0;
const messages = [
  { channelID: 'the channel id', content: 'hello', afterDelay: 6000/*in ms*/ },
  { channelID: 'the channel id', content: 'world', afterDelay: 3000/*in ms*/},
];
setup = async () => {
  for (let i = 0; i < loop; i ++) {
     for(let x = 0; x < messages.length; x++){
       let { channelID, content, afterDelay } = messages[x];
  	const test2 = await api.sendMessage(channelID, content);
  	console.log(`Sent ${++count} messages`)
  	await timeout(afterDelay);
  	}
  }
}

setup()

only reason you'd want to use for loops instead is when you start working with event handlers the while loop fucks up any event listeners.

@BryanBarrera
Copy link

BryanBarrera commented Jan 20, 2021

@SkellyM386 thanks so much, your update worked as expected. I appreciate this!

@DeadLyBro
Copy link

How can we send a message like Ping Pong?
User1: ping
We: pong

@rigwild
Copy link
Author

rigwild commented Jan 20, 2021

actually if we can i'd like to message you guys since your interested in client botting cause right now im working on a more nodejs version of a user/client bot thats similar to discord.js except that its a user bot and its got the ability to read all the json data that goes in and out requests and responses it can even using this example automatically get your user token and be able to accomplish more its just im just one person and i dont know the user api like rigwild does. the plan is to make this and then publish it as a package. and im not afraid of discord since their bot detection isn't that good.

I am not interested in doing full client botting right now, sorry. This is only intended to run small script manually from the console.

How can we send a message like Ping Pong?
User1: ping
We: pong

This is using HTTP queries, so there is no WebSocket event listener like in Discord.js. You can use api.getMessages and search for a message if you want.


Cleaned the thread a bit.

@DeadLyBro
Copy link

DeadLyBro commented Jan 20, 2021

This is using HTTP queries, so there is no WebSocket event listener like in Discord.js. You can use api.getMessages and search for a message if you want.

Yeah i want like this api.getMessages and post message but I don't know how to do it, can you tell me?

@rigwild
Copy link
Author

rigwild commented Jan 20, 2021

ok so @BryanBarrera so apparently im a dummy and the api for users is almost exactly the same as the discord api if not actually the same

It is indeed the same API. In fact, you can use the discord.js package with your user token (v11.3.2 and below though, they deprecated user token support starting v11.4.0).

@eschanze
Copy link

Hello,
First of all, thanks for this resource.
I wanted to know how to loop through the messages once you call getMessages; any help would be appreciated.
Thanks in advance.

@DeadLyBro
Copy link

DeadLyBro commented Feb 23, 2021

Hello,
First of all, thanks for this resource.
I wanted to know how to loop through the messages once you call getMessages; any help would be appreciated.
Thanks in advance.

I wan't know too. Please help us guys.

@DeadLyBro
Copy link

I don't understand: send a message. Can you help me

setup = async () => {
  // Send a message
  const test2 = await api.sendMessage('your-channel-id-here', 'your-message-here')
  console.log(test2)
  await delay(3000)
}
setup()

edit your-channel-id-here and your-message-here and send with console.

@beppe9000
Copy link

beppe9000 commented Feb 23, 2021

is there a way to obtain the authtoken programmatically in javascript ? anyone knows how it's stored ?
also, can this be used on discord's website too ?

@Minigugus
Copy link

is there a way to obtain the authtoken programmatically in javascript ? anyone knows how it's stored ?
also, can this be used on discord's website too ?

Discord don't really want users to automate theirs accounts... More than a year ago the authentication token was just stored in the localStorage, which means it was pretty easy to get. But due to its success, their found a way to remove the token while the app is open, and even remove the global localStorage object to make sure it cannot be accessed via the console. Too many users got their tokens stolen with this technique.

Another solution, a bit hacky, maybe be to hook the fetch (or XMLHTTPRequest) function to intercept the Authorization header, but it still require the app to send a request, and it wont work if they keep a local copy of the fetch function.

I wanted to know how to loop through the messages once you call getMessages; any help would be appreciated.

Functions like sendMessages and so on here just call the API as defined on the Discord website, e.g. https://discord.com/developers/docs/resources/channel#get-channel-messages. They use a filter mechanism based on a reference id to handle pagination, so you have to get for instance the 50 latest messages, that start again by passing the lowest (oldest) message id as the before parameter, and so on. But I'm not sure it works indefinitely, and I assume their abuse system is aware about that...

@5rbsh518
Copy link

5rbsh518 commented Apr 26, 2021

Can I make this script fetch a message like if someone sent ping I replay pong?
a script start when the event new message in a channel occurs gets the message and makes the message.content == "ping"
and if that happened I start the function api.sendMessage('channel_id', 'pong')

@rigwild
Copy link
Author

rigwild commented Apr 26, 2021

@5rbsh518 this does not support the WebSocket events API.
You can try to check the recent messages using api.getMessages every x seconds and check if a message start with pong.

@5rbsh518
Copy link

5rbsh518 commented Apr 26, 2021

Wouldn't that get me banned if I requested messages every 1 second or 2 seconds?

I will request a maximum of 5 messages if I'll spam it

@rigwild
Copy link
Author

rigwild commented Apr 26, 2021

I don't know, maybe. I have used this script multiple times in the past to delete 100k+ messages of mine accross private messages and servers and never got banned.
But I can't garantee anything.

@AceN1nja
Copy link

Hi, I have no experience with JS and so I am unable to debug it. I tried using the script on console and I am getting an error saying 'delay is not defined'.

@beppe9000
Copy link

I am looking at ways to extract the auth token by a web extension...

@rigwild
Copy link
Author

rigwild commented Jun 13, 2021

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