Upgrading from djs v12 (commando) to djs v14 (and sapphire framework) - Unsure on how to Parse Types
Hello!
I have recently started upgrading an outdated open source project, and got stuck for a couple days on a specific aspect (almost done with everything else though).
Context: In the configuration command, it takes two arguments, first being the key (or what setting to change), and second being the new value.
Problem: The old project had a parseType function (under Utils.ts), which uses Commando's ArgumentCollector and ArgumentInfo - these do not exist in vanilla dj.s v14 or Sapphire Framework. This parseType function is extremely crucial, as it checks if the VALUE input is valid for the config (ex. councilorRole would take a role mention or role ID, and the parseType would return the Role object IF VALID somehow?). This function also takes a custom serializer that tells it the Object type and how to serialize/what function to run (ex. councilorRole key has type "role" for value, and runs the getId function).
I am unsure on how to move forward with this, I have a working serializer (at least I believe) that hasn't been changed, but I am unsure on how to return the object. Depending on the key, the value could be anything from a boolean, role, channel, or JSON.
Will post my ConfigCommand.ts file below! - Utils.ts and CouncilData.ts (which has the serializer) are the exact same, but I need a new parseType() function that doesn't depend on Commando (so Utils.ts needs to be altered).
A Discord bot for managing small party voting systems - evaera/Votum
Solution
My solution:
const valueType = (serializer.type as any) try { args.restore() value = await args.rest(valueType) } catch (e) { value = null }
const valueType = (serializer.type as any) try { args.restore() value = await args.rest(valueType) } catch (e) { value = null }
And I did end up having to create three custom arguments (I was referencing the guidelines prior to opening this, and couldn't figure out how to create one or at least export it, but I then realized it was some caching issue which was resolved with me deleting all my compiled files and recompiling).