serenity
serenity copied to clipboard
Confusion about no prefix functionality
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:

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?
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_prefixto 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::prefixeswith""-- unlikeConfiguration::prefix, this will not reset the list of prefixes, at least on thev0.10.9release. Oncurrent(andnext), it has been fixed. If you are depending on Serenity from git, then the only solution will be to push""intoConfiguration::prefixes, a hidden, but accessible field.
Can this issue be closed?
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::prefixesshouldn'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.
Ah, it seems examples/e01_basic_ping_bot/src/main.rs is more fundamental and better suited for the purpose.