serenity-rs / poise

Discord bot command framework for serenity, with advanced features like edit tracking and flexible argument parsing
MIT License
666 stars 117 forks source link

Error when having space or symbol characters inside `#[rename]` for args. #327

Closed yakiimoninja closed 6 minutes ago

yakiimoninja commented 1 day ago

When renaming a slash command argument to anything containing two space separated characters or containing symbols, an error occurs. (If theres trailing whitespace no error happens.)

Executing this code:

#[poise::command(prefix_command, slash_command)]
pub async fn hi(
    ctx: Context<'_>,
    #[min_length = 2]
    #[rename = "say hi"]
    #[description = "Character name or nickname."] input: String,
) -> Result<(), Error> {

    println!("{}",  input);
}

Yields this error:

thread 'tokio-runtime-worker' panicked at src/main.rs:148:55:
Failed to start bot: Invalid Form Body (6.options.0.name: String value did not match validation regex.).
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Character tested: !, ., `,,,@`.

Would it be possible to get a more descriptive error message?

jamesbt365 commented 1 day ago

This error message is from discord as a response for the bot trying to register commands, returning a better error message would mean enforcing it when the command macro is being built or manually detecting this at runtime.

However, the caveat about that is limitations on discord themselves change, which can be a problem as we would have to personally keep track of that and remove/change any restrictions that change on discord themselves, so instead of checking this stuff we are opting to remove checks like these and leave them up to the bot developers.

I'm not sure we will add a check for this, but I think the least we can do is add some additional documentation to the rename property that links to the discord docs on naming schemes so that hopefully less people run into this.

I doubt we will add an actual compile time/runtime check for the matter though.

yakiimoninja commented 6 minutes ago

I see. Well in that case, having some more info in the docs would probably be the best course of action. Thanks. I'll mark this closed