Skip to content

Instantly share code, notes, and snippets.

@NitramO-YT
Last active May 28, 2024 19:59
Show Gist options
  • Save NitramO-YT/ac16776b530436431e99284b988aedc6 to your computer and use it in GitHub Desktop.
Save NitramO-YT/ac16776b530436431e99284b988aedc6 to your computer and use it in GitHub Desktop.
Small script that automates counting in channels to count on Discord.

DiscordSelfbotCount

Small script that automates counting in channels to count on Discord.

SlefBot for Discord by NitramO 02/03/2020

CountMessages V0.9 Based on an @rigwild script: https://gist.github.com/rigwild/28f5d9479e3e122070e27db84e104719

Just download the DiscordSelfbotCount.js file (or copy his content) and open it, next paste his content to the Discord Console (Ctrl + Shift + I) and press Enter key!

for start counting, type "setup('token', 'channelId', 'amount', 'timeout')" in the console and replace all parameters by what they should be,

[NOT OPTIONAL]

  • If you don't know your token you can open the Discord Console, go on the two smalls arrows in the top toolbar and click on "Application", after that, go to "Local Storage", then click on "https://discordapp.com" and inside the array find "token" key, if you don't have it, click at empty place on Discord window and do Ctrl + R, now you should can see your token in the array!

[NOT OPTIONAL]

  • For find a channel id, rightclick on the channel where you want to count, and click on "Copy ID" if you don't have it, it's because your discord isn't in developer mode, for activate the developer mode you need to go inside your Discord parameters and in Appearance, go at the bottom and toggle "Developer mode", now you could rightclick on a channel and copy his id!

[NOT OPTIONAL]

  • The "amount" parameter is the limit of how much you want to count.

[OPTIONAL]

  • The last parameter is the delay in milliseconds between the messages that was sent. (1000 = 1000 MS = 1 second) (advice: do not put a number below 600 otherwise the bot will not succeed to send certain messages because of anti spam and you will lose more time than anything else!)

For force stop counting, type "stopCounting()" in the console!

/*
SelfBot for Discord by NitramO
02/03/2020
CountMessages V0.9
Based on an rigwild script: https://gist.github.com/rigwild/28f5d9479e3e122070e27db84e104719
*/
'use strict'
/**
* Discord Console Self bot
*
* Open chrome console on Discord using Ctrl+shift+i
* Go to the network tab, send a message and copy the 'Authorize' header sent by the app.
* Paste it in authHeader below.
*
* Paste the entire script in the console.
* Now use the provided functions to do some stuff using api.func().
*/
var selftBotScriptOptions = {
scriptName: 'SelbotCount',
version: '0.9',
author: 'NitramO',
authorColored: '%cNi%ctra%cmO',
scriptBase: {
name: 'Simple Discord Selbot',
link: 'https://gist.github.com/rigwild/28f5d9479e3e122070e27db84e104719',
author: 'rigwild'
}
};
var counting = false;//debug
var stoppedCount = false;//debug
// If vars not declared, declare them. We are in console, var could already be defined.
if (typeof authHeader === 'undefined') {
var authHeader = ''
var apiPrefix = ''
var api = ''
var timeout = ''
var apiCall = ''
var setup = ''
var stopCount = ''
}
// You 'Authorize' token here
authHeader = ''
apiPrefix = 'https://discord.com/api/v8'
timeout = ms => new Promise(res => setTimeout(res, ms))
apiCall = (apiPath, body, method = 'GET') =>
fetch(apiPrefix + apiPath, {
body: body ? JSON.stringify(body): undefined,
headers: {
Accept: '*/*',
'Accept-Language': 'en-US',
Authority: 'discordapp.com',
Authorization: authHeader,
'Content-Type': 'application/json',
'User-Agent':
'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) discord/0.0.301 Chrome/56.0.2924.87 Discord/1.6.15 Safari/537.36'
},
method
})
.then(res => (res.status === 200 ? res.json(): Promise.resolve()))
.catch(console.error)
// Self bot API
api = {
// Get messages from channel
getMessages(channelId) {
return apiCall(`/channels/${channelId}/messages?limit=100`)
},
// Send a message in a channel
sendMessage(channelId, message, tts) {
return apiCall(`/channels/${channelId}/messages`, { content: message, tts: !!tts }, 'POST')
},
// Edit a message in a channel
editMessage(channelId, messageId, newMessage) {
return apiCall(`/channels/${channelId}/messages/${messageId}`, { content: newMessage }, 'PATCH')
},
// Delete a message from a channel
deleteMessage(channelId, messageId) {
return apiCall(`/channels/${channelId}/messages/${messageId}`, null, 'DELETE')
}
}
function startMessage() {
console.log(
'%cSuccessfully loaded %c' + selftBotScriptOptions.scriptName + ' %cV%c' + selftBotScriptOptions.version + ' %cBy ' + selftBotScriptOptions.authorColored + '%c!',
'color:green;font-family:system-ui;font-size:1.2rem',
'color:cyan;font-family:system-ui;font-size:1.2rem;font-weight:bold',
'color:grey;font-family:system-ui;font-size:1.2rem',
'color:orange;font-family:system-ui;font-size:1.2rem;font-weight:bold',
'color:grey;font-family:system-ui;font-size:1.2rem',
'color:blue;font-family:system-ui;font-size:1.2rem;font-weight:bold;text-shadow: 0px 0px 7px black',
'color:white;font-family:system-ui;font-size:1.2rem;font-weight:bold;text-shadow: 0px 0px 7px black',
'color:red;font-family:system-ui;font-size:1.2rem;font-weight:bold;text-shadow: 0px 0px 7px black',
'color:grey;font-family:system-ui;font-size:1.2rem',
);
return new Date();
}
function stopCounting() {
if (counting == true) {
if (stoppedCount == false) {
stoppedCount = true;
console.log(
'%cCount stoping...',
'color:grey;font-family:system-ui;font-size:1.5rem'
);
return 'Waiting...';
} else {
console.error('Failed to stop counting!', {'Info': 'Count stoping already in progress...'});
return 'DEBUG: An error occurred, see details above...';
}
} else {
console.error('Failed to stop counting!', {'Info': 'Count stoping already in progress...'});
return 'DEBUG: An error occurred, see details above...';
}
}
setup = async (token, channelId, valueBuffer, timeOut) => {
if (token) {
authHeader = token;
if (channelId) {
if (valueBuffer) {
const lastMessages = await api.getMessages(channelId);
if (lastMessages) {
var foundMessage = ''; //debug
await lastMessages.forEach(function(element, index, array) {
if (!foundMessage || foundMessage == '' || foundMessage == undefined) {
if (element.content.match(/^[0-9]+$/g) !== null) {
foundMessage = element;
}
}
});
if (foundMessage) {
var lastMessage = foundMessage;
var lastMessageValue = parseInt(lastMessage.content, 10);
await timeout(150);
if (valueBuffer > lastMessageValue) {
counting = true;
console.log(
'%cCount starting! %c(Start from ' + (lastMessageValue+1) + ' to ' + valueBuffer + '. ' + (valueBuffer-lastMessageValue) + ' Messages to send.)',
'color:lime;font-family:system-ui;font-size:2rem;font-weight:bold',
'color:gray;font-family:system-ui;font-size:1.3rem;font-weight:bold'
);
for(var i=(lastMessageValue+1); i < (valueBuffer+1); i++) {
if (stoppedCount && stoppedCount == true) {
console.log(
'%cCount successfully stopped! %c' + ((i-lastMessageValue)-1) + '/' + (valueBuffer-lastMessageValue) + ' Messages sent. (' + (i-1) + '/' + valueBuffer + ')',
'color:lime;font-family:system-ui;font-size:2rem;font-weight:bold',
'color:gray;font-family:system-ui;font-size:1.3rem;font-weight:bold'
);
i = (valueBuffer+1);
} else {
const sendMessage = await api.sendMessage(channelId, i);
if (sendMessage) {
console.log(
'%cSuccessfully sent message: %c' + sendMessage.content + '/' + valueBuffer + ' (' + (i-lastMessageValue) + '/' + (valueBuffer-lastMessageValue) + ' Messages sent.)',
'color:green;font-family:system-ui;font-size:1.5rem',
'color:gray;font-family:system-ui;font-size:1.2rem'
);
} else {
console.log(
'%cFailed to send message: %c' + i + '/' + valueBuffer + ' (' + ((i-lastMessageValue)-1) + '/' + (valueBuffer-lastMessageValue) + ' Messages sent.)',
'color:red;font-family:system-ui;font-size:1.5rem',
'color:gray;font-family:system-ui;font-size:1.2rem'
);
i--
}
if (timeOut) {
await timeout(timeOut);
}
}
};
counting = false;
if (stoppedCount && stoppedCount == true) {
stoppedCount = false;
} else {
console.log(
'%cCount successfully finished! %c' + ((i-lastMessageValue)-1) + '/' + (valueBuffer-lastMessageValue) + ' Messages sent. (' + (i-1) + '/' + valueBuffer + ')',
'color:lime;font-family:system-ui;font-size:2rem;font-weight:bold',
'color:gray;font-family:system-ui;font-size:1.3rem;font-weight:bold'
);
}
} else {
//error message: Number buffer to count is less greater than the last message value.
console.error('ERROR: Number need to be more greater than the last message value', {'Info': 'Can\'t count from \"' + lastMessageValue + '\" to \"' + valueBuffer + '\".', 'Channel ID': channelId});
}
} else {
//error message: Failed to find message with number.
console.error('Failed to found number message!', {'Info': 'Missing message that contains number.', 'Channel ID': channelId});
}
}
} else {
//error message: Missing valueBuffer.
console.error('Syntax error: Missing amount', {'Info': 'Missing amount argument', 'Syntax': 'setup(\'token\', \'channelId\', \'amount\', \'timeout\')'});
}
} else {
//error message: Missing channelId.
console.error('Syntax error: Missing channelId', {'Info': 'Missing channelId argument', 'Syntax': 'setup(\'token\', \'channelId\', \'amount\', \'timeout\')'});
}
} else {
//error message: Missing token.
console.error('Syntax error: Missing token', {'Info': 'Missing token argument', 'Syntax': 'setup(\'token\', \'channelId\', \'amount\', \'timeout\')'});
}
}
startMessage(); //debug
//Example: setup('token', 'channelId', 'amount', 'timeout')
//Force stop counting: stopCounting()
@Mixarar
Copy link

Mixarar commented Nov 8, 2020

Doesn't work it says Access to fetch at 'https://discordapp.com/api/v7/channels/773673510090047498/messages?limit=100' from origin 'https://discord.com' has been blocked by CORS policy: Request header field authority is not allowed by Access-Control-Allow-Headers in preflight response.

@SPACECOWPIE
Copy link

Doesn't work it says Access to fetch at 'https://discordapp.com/api/v7/channels/773673510090047498/messages?limit=100' from origin 'https://discord.com' has been blocked by CORS policy: Request header field authority is not allowed by Access-Control-Allow-Headers in preflight response.

I have the exact same problem.

@DeadLyBro
Copy link

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

@NitramO-YT
Copy link
Author

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

Thx for the informations, i'll edit the file in few minutes!

@NitramO-YT
Copy link
Author

Doesn't work it says Access to fetch at 'https://discordapp.com/api/v7/channels/773673510090047498/messages?limit=100' from origin 'https://discord.com' has been blocked by CORS policy: Request header field authority is not allowed by Access-Control-Allow-Headers in preflight response.

Doesn't work it says Access to fetch at 'https://discordapp.com/api/v7/channels/773673510090047498/messages?limit=100' from origin 'https://discord.com' has been blocked by CORS policy: Request header field authority is not allowed by Access-Control-Allow-Headers in preflight response.

I have the exact same problem.

It should work now!

@DeadLyBro
Copy link

Doesn't work it says Access to fetch at 'https://discordapp.com/api/v7/channels/773673510090047498/messages?limit=100' from origin 'https://discord.com' has been blocked by CORS policy: Request header field authority is not allowed by Access-Control-Allow-Headers in preflight response.

Doesn't work it says Access to fetch at 'https://discordapp.com/api/v7/channels/773673510090047498/messages?limit=100' from origin 'https://discord.com' has been blocked by CORS policy: Request header field authority is not allowed by Access-Control-Allow-Headers in preflight response.

I have the exact same problem.

It should work now!

Good if it works, but I did it with discord.com, not discordapp.com. No problem if it works with discordapp.com as well.

@NitramO-YT
Copy link
Author

Doesn't work it says Access to fetch at 'https://discordapp.com/api/v7/channels/773673510090047498/messages?limit=100' from origin 'https://discord.com' has been blocked by CORS policy: Request header field authority is not allowed by Access-Control-Allow-Headers in preflight response.

Doesn't work it says Access to fetch at 'https://discordapp.com/api/v7/channels/773673510090047498/messages?limit=100' from origin 'https://discord.com' has been blocked by CORS policy: Request header field authority is not allowed by Access-Control-Allow-Headers in preflight response.

I have the exact same problem.

It should work now!

Good if it works, but I did it with discord.com, not discordapp.com. No problem if it works with discordapp.com as well.

Yes thank you again, you're right, it should still work for a while, but in an indefinite period of time they will suspend discordapp.com and replace it by discord.com!

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