Home > other >  discord.js | Will client.login('TOKEN') twice lead to problems?
discord.js | Will client.login('TOKEN') twice lead to problems?

Time:10-30

I was getting an error by fetching a channel from my client that said my client was not logged in at that point, so I used client.login() right before requesting the channel and also in my main.js so the client will login at a normal start as well.

I am asking myself now if logging in the client twice could lead to any problems. Is it just catched if the client is already logged in, or is something like a duplicate of the client started?

Just want to know if I could run into problems and I did not find any answer to this question : )

CodePudding user response:

After testing, it seems that logging in with the same token twice will make the other client log out, or doesn't even log in again. This means that it doesn't make a "duplicate" client. This is the code I used:

const client = new Client({
    intents: [
        Intents.FLAGS.GUILDS,
        Intents.FLAGS.GUILD_MESSAGES
    ]
})
const client2 = new Client({
    intents: [
        Intents.FLAGS.GUILDS,
        Intents.FLAGS.GUILD_MESSAGES
    ]
})
client.login('...')
client2.login('...') //the tokens are the same

We get the same results using the same client variable. The messageCreate event only ran once, not twice (which I can tell because my bot only sent a single message on the event)

Putting it inside of the messageCreate event seems to also make no difference.

As I said at the top, it's also possible that this login is simply ignored, as I don't seem to be getting any ready events.

Because of these points, I wouldn't say there would be any problems by logging in twice

  • Related