Discord bot not connecting or 429 status code

Hey everyone,

Just to clarify before you read the rest of this post, I myself do not require any help, im just giving some help for the ones who are willing to try it instead of complaining,
Im aware of the meaning of the status codes and im aware of the watch.json and vice versa. Please if you are here just to hate on me, complain or try to help me, do not comment as i do not want to waste my time replying to comments that arent relevant to helping others, that instead try to help me

Lately alot of my discord bots just would not want to connect and it has been bothering me a bit.
But i found a solution to this problem and this may help you guys out too.

If your bot doesnt connect, gives a 429 status code or just returns a something took too look error you should do the following

either remix this extremely basic base project and create a bot in it:
https://glitch.com/edit/#!/fftr

or

after importing the Client from the discord.js module and creating a new client i.e:

const {Client} = require("discord.js");
const bot = new Client();

just add this simple line

bot.options.http.api = "https://discord.com/api"

You should end up with something like the following:

const {Client} = require("discord.js");
const bot = new Client();
bot.options.http.api = "https://discord.com/api"

ofcourse make sure that if you have a different variable name to change it, in my case its bot.

This seemed to fix the issue, many of you might have noticed that discord recently switched their domain from https://discordapp.com to just https://discord.com and that seems to cause the issue. By changing the api url inside the discord.js Client we can get the bot up and running.

If you check the documentation over at discord you can see that the base url is now only discord.com instead of discordapp.com

If it does not work for you, i’m sorry but i do not know what to do.

Peace :v:

3 Likes

You might be on a banned host. Please check out this post: Discord Ban mega-thread the second! (Discord bot / Something took too long to do)

1 Like

I doubt i am because when changing the api base url it works fine again.

1 Like

Could you run curl -I https://discordapp.com/api/v7/gateway in your console please? If it returns a 429 code it’s on a banned host

Already did and im completely aware of the fact it returns a 429,
but could you please try to see what i mean by doing
curl -I https://discord.com/api/v7/gateway
instead of using the https://discordapp.com domain,
using the https://discord.com domain returns OK and it works fine.

yeah discord.com is the website but not the actual Discord app. Please check out the post I linked before :+1:

1 Like

Im not trying to be rude but, i do not think the link u posted above is relevant to my point, if the project is on a banned host, then why using the new discord domain makes it connect without returning me a 429,
if you haven’t tried yet, if you visit the old discord domain api route it redirects it to the new one.

Because discordapp.com is where users and bot can message on. discord.com is just the nice site with “this is Discord” and “make an account” and stuff. You’re not banned on there because you can’t send requests there.

Then would you like to explain why changing the api url inside the discord client makes the bot fully functional again without a single error on any request it makes.

I don’t know… I am no pro and I have no idea what’s the issue. Just put in your project name in the thread above and Glitch staff will move your project to another host.

I do not require my project to be moved as my solution fixes the entierity of this problem as a whole and im not encountering any errors anymore.
And just for your information, the discord api and discord frontend are on the same domain, if you visit discordapp.com it redirects you to discord.com/new. But, if you visit the api route on discordapp.com it also redirects to the discord.com domain with the same api route.

429 means “Too many requests”, this had happened to you because discord has rate limit for bot logging in. Instead of constantly refreshing the bot on changes, add watch.json file and set the throttle value to something like 1500000. When you make changes to bot and you want to see them, type in the terminal this refresh. Your bot can only login 1,000 times per hour. If you got temporarily blocked, because you reached the limit, wait like 3 hours to let it reset.

Im aware that 429 means too many requests but my bot had its login code commented out for a week or so and only today an hour ago i uncommented it and waited but nothing happend, no way that it made too many requests as it was sleeping the entierity of the week. Besides, changing the api url seems to fix the issue. And i want to clarify im here to give a solution for the ones searching for one, i myself do not require help as i fixed the issue on my end.

This is wrong. Even the web app has moved to discord.com now (see discord.com/app). discordapp.com redirects to discord.com - both should work with the API, but maybe there is an issue with the redirect right now or with Glitch

2 Likes

Thank you, finally someone who gets my point and knows what they’re talking about, Your comment is greatly appreciated.

3 Likes