serenity icon indicating copy to clipboard operation
serenity copied to clipboard

Confusion about no prefix functionality

Open Stef16Robbe opened this issue 4 years ago • 1 comments
trafficstars

The prefix docs say the following about having no prefix command character:

Note: Passing empty string "" will set no prefix.

To my understanding this means that commands will be executed without using a prefix, e.g:

let framework = StandardFramework::new()
        .configure(|c| c.prefix("")) // set the bot's command prefix
        .group(&GENERAL_GROUP);

would achieve:

image

Should it work like this? Currently it does not, nothing happens using the ping pong example of this repo. If it shouldn't work like this, how would I achieve this result?

Stef16Robbe avatar Nov 12 '21 15:11 Stef16Robbe

To my understanding this means that commands will be executed without using a prefix

No, what the note is saying that by passing "" into Framework::prefix will reset the list of prefixes the framework will use to distinguish commands from normal messages.

If you wish to be able to invoke commands without a prefix, there are two solutions:

  • Set Configuration::no_dm_prefix to true -- if you would like to invoke commands in DMs without a prefix, but keep them everywhere else (i.e. guilds), then this option will allow that.
  • Set Configuration::prefixes with "" -- unlike Configuration::prefix, this will not reset the list of prefixes, at least on the v0.10.9 release. On current (and next), it has been fixed. If you are depending on Serenity from git, then the only solution will be to push "" into Configuration::prefixes, a hidden, but accessible field.

arqunis avatar Nov 12 '21 17:11 arqunis

Can this issue be closed?

kangalio avatar Sep 12 '22 08:09 kangalio

Today I just encountered the exactly same question as the OP.

  • I think the documentation is poorly worded.

  • Do I still have to stick to this workaround after 2 years?

    If you are depending on Serenity from git, then the only solution will be to push "" into Configuration::prefixes, a hidden, but accessible field.

    let framework = StandardFramework::new()
        .configure(|c| {
            c.prefixes.push("".to_owned());
            c
        })
        .group(&GENERAL_GROUP);
    

    If so,

    • The workaround should be documented anywhere. (I'm sorry if it is documented already.)
    • Configuration::prefixes shouldn't be hidden.

    (But..., is setting no prefix so rare to justify not exposing an official way (rather than a workaround)? I've created many Discord bot in many languages and I've never wanted to set prefixes (maybe because my bots are deployed to a server with the small number of members).)


How did I find this issue?

As a beginner for this crate, I first read the example shown in README.md:

    let framework = StandardFramework::new()
        .configure(|c| c.prefix("~")) // set the bot's prefix to "~"
        .group(&GENERAL_GROUP);

The comment suggests c.prefix() sets the bot's prefix, so I removed the call of .configure(), but my bot didn't work.

So I visited the official documentation of Configuration::prefix and it says

Passing empty string "" will set no prefix.

Then I tried c.prefix("") to no avail.

your-diary avatar Aug 31 '23 12:08 your-diary

Ah, it seems examples/e01_basic_ping_bot/src/main.rs is more fundamental and better suited for the purpose.

your-diary avatar Sep 01 '23 08:09 your-diary