ExpectedValidationError from EmbedBuilder().setTimestamp(variable)

(using typescript) while creating an embed in an interaction handler and setting the Timestamp on it, the following Error(s) are thrown
CombinedError (3)
Received one or more errors

1 ExpectedValidationError > s.literal(V)
| Expected values to be equals
|
| Expected:
| | null
|
| Received:
| | '1695404406973'

2 ValidationError > s.number
| Expected a number primitive
|
| Received:
| | '1695404406973'

3 ValidationError > s.date
| Expected a Date
|
| Received:
| | '1695404406973'
CombinedError (3)
Received one or more errors

1 ExpectedValidationError > s.literal(V)
| Expected values to be equals
|
| Expected:
| | null
|
| Received:
| | '1695404406973'

2 ValidationError > s.number
| Expected a number primitive
|
| Received:
| | '1695404406973'

3 ValidationError > s.date
| Expected a Date
|
| Received:
| | '1695404406973'
the code throwing is equivalent to the following:
export class someClass {
public createdAt!: number
}

//...

const embed = new EmbedBuilder()
//set a bold title
.setTitle('**EmbedTitle**')
.setDescription('SomeLongText')
.setFooter({ text: 'FooterText' })
.setTimestamp(classInstance.createdAt)
export class someClass {
public createdAt!: number
}

//...

const embed = new EmbedBuilder()
//set a bold title
.setTitle('**EmbedTitle**')
.setDescription('SomeLongText')
.setFooter({ text: 'FooterText' })
.setTimestamp(classInstance.createdAt)
relevant dependeversions:
discord.js 14.13.0
@sapphire/discord.js-utilities 7.0.2
@sapphire/duration 1.1.0
@sapphire/framework 4.6.0
@sapphire/pieces 3.7.0
@sapphire/utilities 3.13.0
discord.js 14.13.0
@sapphire/discord.js-utilities 7.0.2
@sapphire/duration 1.1.0
@sapphire/framework 4.6.0
@sapphire/pieces 3.7.0
@sapphire/utilities 3.13.0
the indirectly depended version of shapeshift throwing the error seems to be @sapphire/[email protected]
Solution:
classInstance.createdAt is a string
Jump to solution
5 Replies
Favna
Favna15mo ago
s.number | Expected a number primitive | | Received: | | '1695404406973'
Solution
Favna
Favna15mo ago
classInstance.createdAt is a string
Favna
Favna15mo ago
I know you didnt type it as such but runtime says otherwise
Max
MaxOP15mo ago
man i hate js sometimes yup, explicitly casting my number to a number makes sure it's a number .setTimestamp(Number(classInstance.createdAt)) i assume the single quotes indicate that it's a string in that exception?
Favna
Favna15mo ago
yeah also the fact that it says it expected a number but it wasn't, there was only one other thing that could've been formatted like that
Want results from more Discord servers?
Add your server