App 8: Build a Discord Bot / Build a Discord bot
Lesson 6 of 10
Commands with options
Commands can take inputs. Type hints tell Discord what kind of value to ask for.
Key points
- Parameters become command options
- int, str, discord.Member and more
- Add descriptions with @app_commands.describe
@tree.command(name="roll", description="Roll a dice")
@app_commands.describe(sides="How many sides")
async def roll(interaction: discord.Interaction, sides: int = 6):
import random
await interaction.response.send_message(f"🎲 You rolled {random.randint(1, sides)}")Your turn
Add /roll with an optional number of sides.
Quiz · +10 XP
How does Discord know /roll takes a number?
Log in to save progress and earn XP.