discordjs/discord.js · error · RangeError
timestamps.start must fit into a unix timestamp
Error message
timestamps.start must fit into a unix timestamp
What it means
setActivity() validates rich-presence timestamps and throws this RangeError when activity.timestamps.start is not a valid unix timestamp (per isValidTimestamp — outside the safe numeric range, e.g. milliseconds or NaN).
Source
Thrown at packages/rpc/src/client.ts:550
/**
* Sets the presence for the logged in user.
*
* @param activity - The rich presence to pass.
* @param pid - The application's process ID. Defaults to the executing process' PID.
* @remarks
* Clients may only update their activity 5 times per 20 seconds.
*/
public async setActivity(
activity: RPCSetActivityArgs['activity'] = {},
pid: number | null = getPid(),
options?: RequestOptions,
): Promise<unknown> {
activity.instance = Boolean(activity.instance);
if (activity.timestamps) {
if ('start' in activity.timestamps && isValidTimestamp(activity.timestamps.start)) {
throw new RangeError('timestamps.start must fit into a unix timestamp');
}
if ('end' in activity.timestamps && isValidTimestamp(activity.timestamps.end)) {
throw new RangeError('timestamps.end must fit into a unix timestamp');
}
}
return this.request(
RPCCommands.SetActivity,
{
pid: pid ?? 0,
activity,
},
options,
);
}
/**View on GitHub (pinned to a81ed8a306)
Solutions
- Convert to seconds: Math.floor(Date.now() / 1000)
- Ensure the value is a finite number, not a string or Date object
- Only set timestamps.start when you actually have a valid epoch-seconds value
Example fix
// before
client.setActivity({ timestamps: { start: Date.now() } });
// after
client.setActivity({ timestamps: { start: Math.floor(Date.now() / 1000) } }); Defensive patterns
Strategy: validation
Validate before calling
const startSec = Math.floor(Date.now() / 1000);
if (!Number.isFinite(startSec) || startSec > 2 ** 53 - 1) throw new Error('start out of unix range'); Type guard
function isValidEpochSeconds(v: unknown): v is number {
return typeof v === 'number' && Number.isFinite(v) && v > 0 && v < 2 ** 53 - 1;
} Try / catch
try {
await client.setActivity(activity);
} catch (err) {
if (err instanceof RangeError && err.message.includes('timestamps.start')) {
// fix timestamp units and retry
}
} Prevention
- Always convert Date.now() (ms) to seconds before use
- Never pass Date objects or ISO strings into timestamps
- Centralize a toEpochSeconds() helper for all rich-presence timestamps
When it happens
Trigger: Calling client.setActivity({ timestamps: { start: Date.now() } }) — passing milliseconds instead of seconds — or a string/NaN that fails the timestamp check.
Common situations: Using JavaScript's Date.now() (ms) directly, passing an ISO date string, or computing timestamps with Math.round missing.
Related errors
- timestamps.end must fit into a unix timestamp
- ShardingShardMiscalculation
- CommandInteractionOptionInvalidChannelType
- InvalidType
- Invalid extension provided: ${extension} Must be one of: ${a
AI-assisted analysis of discordjs/discord.js@a81ed8a306 (2026-08-30).
Data as JSON: /api/errors/4946dc41cde8afda.
Report an issue: GitHub.