krisppurg / dimscord

A Discord Bot & REST Library for Nim.
https://krisppurg.github.io/dimscord/
MIT License
222 stars 20 forks source link

Typesafe command options #57

Closed ire4ever1190 closed 3 years ago

ire4ever1190 commented 3 years ago

Interaction command options now have separate fields for the different possible values e.g.

# Simple example of behind the scenes
let input = %* {
            "value": "foobar",
            "type": 3,
            "name": "word"
}
let option = input.newApplicationCommandInteractionDataOption()
# Code that the developer would write
assert option.str == "word" # isn't an option anymore
assert option.ival == 9 # Throws an error since option.kind != acotInt

Also wrote some unit tests based on json responses from discord to test that this works in different scenarios