API Rate Limit?
Answered
Catla posted this in #help-forum
CatlaOP
Hi.
This is a script named actions.ts. It is called via form submission on a client component which is under a server page.tsx on edge runtime.
When I am testing on my dev environment (localhost:3000) it will successfully generate all group roles as discord roles.
However, when I move this to production, only 1 role generates and no more will. Even if I spam submit the form!
Is there some sort of rate limit that vercel/next itself implement? Or is this more of a discord question? I think given the circumstances (It working on dev environment), it is the former.
Thanks.
'use server';
import { auth } from '@/auth';
import db from '@/lib/db';
import { getRoles } from '@/lib/roblox';
import { REST } from '@discordjs/rest';
import { RESTGetAPIGuildRolesResult, Routes } from 'discord-api-types/v10';
const rest = new REST({ version: '10' }).setToken(process.env.DISCORD_BOT_TOKEN as string)
export async function GenDiscordRoles(guildId: string) {
const session = await auth();
const guild = await db.guild.findUnique({
where: {
id: guildId
}
});
if (!guild || guild.ownerId !== session?.user.id || !guild.groupId) return;;
const groupRoles = await getRoles(guild.groupId);
if (!groupRoles) return;
let guildRoles: Array<string> = [];
try {
const guildRolesData: RESTGetAPIGuildRolesResult = await rest.get(Routes.guildRoles(guildId)) as RESTGetAPIGuildRolesResult;
guildRoles = guildRolesData.map(guildRole => guildRole.name);
} catch { return };
const filteredGroupRoles = groupRoles.roles.reverse().filter(groupRole => !guildRoles.includes(groupRole.name));
filteredGroupRoles.forEach(async groupRole => {
await rest.post(Routes.guildRoles(guildId), {
body: {
name: groupRole.name,
hoist: true
}
}).catch()
})
};This is a script named actions.ts. It is called via form submission on a client component which is under a server page.tsx on edge runtime.
When I am testing on my dev environment (localhost:3000) it will successfully generate all group roles as discord roles.
However, when I move this to production, only 1 role generates and no more will. Even if I spam submit the form!
Is there some sort of rate limit that vercel/next itself implement? Or is this more of a discord question? I think given the circumstances (It working on dev environment), it is the former.
Thanks.
15 Replies
Toyger
probably you can put some console.log into catch blocks like
to find out are your request returning some errors
catch (error) {
console.log(error);
} to find out are your request returning some errors
@Toyger probably you can put some console.log into catch blocks like
js
catch (error) {
console.log(error);
}
to find out are your request returning some errors
CatlaOP
Where on the vercel deployment page would I read the log if it did print?
@Toyger Click to see attachment
CatlaOP
Right. Well, it's always returning status 200. So apparently it's completing.
Typically that would mean maybe there literally is only 1 role to add and it's adding it. Therefor it's 200 OK. But that can't be the case because on my dev environment it's adding multiple (as it should). It should be no different in production.
Toyger
You can add additional console.logs to log your guildroles,folteredguildroles....
@Toyger You can add additional console.logs to log your guildroles,folteredguildroles....
CatlaOP
Doesn’t relate to what I said?
@Catla Doesn’t relate to what I said?
Toyger
why? if it's executes without errors, then probably initial data that invoke requests themselves is wrong, so you need to log it to check is it ok
CatlaOP
But the initial data can’t be wrong due to the dev environment working
@Catla But the initial data can’t be wrong due to the dev environment working
Toyger
if it not works as expected then everything can be wrong. you need to add additional logging to check that
@Toyger if it not works as expected then everything can be wrong. you need to add additional logging to check that
CatlaOP
Right. Well, I added it, and indeed there are multiple groupRoles and filteredRoles, and yet it is only creating 1 role.
@Catla Right. Well, I added it, and indeed there are multiple groupRoles and filteredRoles, and yet it is only creating 1 role.
Toyger
you need more logs, add logs inside forEach, to understand is it call each item from array
also you can log result, just to be sure
also you can log result, just to be sure
CatlaOP
forEach does not wait for async
Answer