Skip to content

Instantly share code, notes, and snippets.

@rigwild
Last active April 9, 2022 20:37
Show Gist options
  • 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
@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...

@Omar-Aljohani
Copy link

Omar-Aljohani 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.

@Omar-Aljohani
Copy link

Omar-Aljohani 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