discordjs/discord.js · error · RangeError
timestamps.end must fit into a unix timestamp
Error message
timestamps.end must fit into a unix timestamp
What it means
Same validation as timestamps.start but for activity.timestamps.end in setActivity(): the value must be a valid unix timestamp or a RangeError is thrown.
Source
Thrown at packages/rpc/src/client.ts:554
* @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,
);
}
/**
* Clears the currently set presence, if any. This will hide the "Playing X" message
* displayed below the user's name.
*
* @param pid - The application's process ID. Defaults to the executing process' PID.View on GitHub (pinned to a81ed8a306)
Solutions
- Convert to epoch seconds: Math.floor((Date.now() + durationMs) / 1000)
- Validate the number is finite and within unix range before passing
- Omit timestamps.end if unknown
Example fix
// before
client.setActivity({ timestamps: { end: Date.now() + 60_000 } });
// after
client.setActivity({ timestamps: { end: Math.floor((Date.now() + 60_000) / 1000) } }); Defensive patterns
Strategy: validation
Validate before calling
const endSec = Math.floor((Date.now() + durationMs) / 1000);
if (!Number.isFinite(endSec)) throw new Error('end 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.end')) {
// drop or fix timestamps.end and retry
}
} Prevention
- Compute end times in seconds: Math.floor(ms / 1000)
- Validate timestamps before each setActivity call
- Omit timestamps.end when the end time is unknown
When it happens
Trigger: Calling client.setActivity({ timestamps: { end: someValue } }) where someValue is in milliseconds, NaN, or otherwise outside valid epoch-seconds range.
Common situations: Setting an end time with Date.now() + durationInMs without converting to seconds, or leaving end as undefined-checked string input from config.
Related errors
- timestamps.start 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/a4f09e21f45c019e.
Report an issue: GitHub.