DEV Community

Discussion on: How to implement, test and mock Discord.js v13 slash commands with Typescript

Collapse
 
opyficarlogg profile image
OpyFicarlogg

Hello,
I have mocked commandInteraction, and I use options in my code (getInteger).

But I can't figure out how to mock the options object (type CommandInteractionOptionResolver), can you help me on this?

Thank you

Collapse
 
heymarkkop profile image
Mark Kop

Hey, there.
You shouldn't need to mock CommandInteractionOptionResolver, because we're passing the resolved options directly to the CommandInteraction class.
That's why, according to this guide, you have to pass it as an object like this

{
  "id": "config",
  "name": "config",
  "type": 1,
  "options": [
    {
      "type": 1,
      "name": "set",
      "options": [{
        "value": "en",
        "type": 3,
        "name": "lang"
      }],
    }
  ]
}
Enter fullscreen mode Exit fullscreen mode

or parse a command line like I've showed previously in the guide.