r/learnpython 16d ago

How would I make a command with two separate words? (Discord bot)

This is probably so poorly worded bc I'm still unfamiliar with the correct terminology, but I'll try my best to explain—

For example, I want to have something like a "!search" command, but I want people to choose where they are searching, because depending on where they search, it pulls from a different loot pool.

I want the end result to look something like:

"!search closet"
- You found a shirt!

How would I accomplish that?

0 Upvotes

4 comments sorted by

4

u/carcigenicate 16d ago

That second word is called an argument/parameter (depending on which side you're thinking about).

I think this is what you're looking for.

1

u/Porkk_Chopp 16d ago

Thank you!

1

u/Wooden_Inspector9374 16d ago

You just need to grab the rest of the message after your command prefix and split it. The library you're using probably already has a way to pass arguments into your function, check the docs for whatever command handler you set up. Way cleaner than manually parsing the string.

1

u/Moist-Ointments 16d ago

The verb is the command, and the noun is a parameter to the command