How to handle multiple tokens.

I have a single file of code. I'd like to run a service where you send a bot token and it runs the code on that bot too. How could i handle that? discord.js@latest node.js@latest
23 Replies
d.js toolkit
d.js toolkit5mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
treble/luna
treble/luna5mo ago
depends on how you are getting that token you cannot ask users to give you their bot token
kama
kamaOP5mo ago
no. it's basically my friends whenever they create a server they need a protection bot. so they give me token and i host script on that token
treble/luna
treble/luna5mo ago
just use the same bot then?
MartialAssault
MartialAssault5mo ago
You need a different bot for different servers? If you have access to these “different tokens” you can simply maintain different env files, and whenever you start the bot you can use Node’s —env-file flag to specify the env file to use while running the application
kama
kamaOP5mo ago
okay yeah but the point is to use multiple tokens at once yea if for example you want go have your custom branding discord is very limited with per-server bot identity
MartialAssault
MartialAssault5mo ago
I’ve been doing this the entire time to deploy any of the bots (of course they authorised me to) Is there a way around to this?! I actually have the same “white labelling” question as @kama Makes sense O_O
kama
kamaOP5mo ago
i'm not asking them. they willingly give it to me. that's why services like crowbots or myself can work around that rule i see. well my problem still resides in how to run everything on multiple tokens without duplicating my code
Amgelo
Amgelo5mo ago
I mean I'd say that having a system for that is still against the ToS, it's not like "I have it but I don't recommend using it" is a strong argument maybe if you make it very, very clear that they're violating the ToS it'll be better
kama
kamaOP5mo ago
yes. but i want to run them all simultaneously without having to run the code 3x
Rusty
Rusty5mo ago
I guess just put all of them in for loop or something and that’s it. Run a file once to start all of them.
kama
kamaOP5mo ago
if i ever change something, and have more bots than three thisll take forever to start everything up
Amgelo
Amgelo5mo ago
but then you won't be able to start or stop a single bot and if one bot causes the process to crash, all of them will crash
Rayan
Rayan5mo ago
no
treble/luna
treble/luna5mo ago
uh yes If they all run in the same process it will crash the entire process
Rayan
Rayan5mo ago
const tokens = ['token1', 'token2', 'token3']; // All tokens here

tokens.forEach(t => {
try {
// index.js code here

// Client.login(t)
} catch (e) {
console.error(e.message);
}
});
const tokens = ['token1', 'token2', 'token3']; // All tokens here

tokens.forEach(t => {
try {
// index.js code here

// Client.login(t)
} catch (e) {
console.error(e.message);
}
});
treble/luna
treble/luna5mo ago
thats 1 single process indeed
Rayan
Rayan5mo ago
if an instance crashes there will simply be error
treble/luna
treble/luna5mo ago
and not too sure what you're here for, we're trying to tell them not to run it in a single process
Rayan
Rayan5mo ago
why ?
treble/luna
treble/luna5mo ago
because as of whats mentioned before, and in general its bad practice to run multiple bots in a single process
Rayan
Rayan5mo ago
crowbot uses this method its true that its not optimized, but for a small bot I dont think it's too much trouble
Amgelo
Amgelo5mo ago
that's not how errors work, events still need to handle their own errors, otherwise you'll get an unhandled error event exception they literally said it'll "take forever to start everything up"

Did you find this page helpful?