Category: Discord Bot Tutorials
Discord Bot Tutorial#2Adding Options (Arguments) to Slash Commands!
This post was translated from the Korean original.
Contents4 sections
Hi there! It's Mojangcam 🙌
Last time, we built a basic slash command, /hello, remember?
This time, we'll build a slash command that takes user input and acts on it.
Something like /say message:안녕!
📦 The Code
Once again, we're using Python and discord.py.
Take a look at the code below first👇
import discord
from discord.ext import commands
from discord import app_commands
intents = discord.Intents.default()
bot = commands.Bot(command_prefix="/", intents=intents)
@bot.event
async def on_ready():
await bot.tree.sync()
print(f"✅ {bot.user} is ready!")
@bot.tree.command(name="hello", description="A simple greeting command")
async def hello(interaction: discord.Interaction):
await interaction.response.send_message("Hello!")
@bot.tree.command(name="say", description="Repeats the message you type!")
@app_commands.describe(message="Enter the message to repeat.")
async def say(interaction: discord.Interaction, message: str):
await interaction.response.send_message(f"You said: {message}")
bot.run("YOUR_TOKEN")🧪 What It Looks Like in Action
What happens if you type this into a Discord chat?
/say message:안녕 나는 봇이야👇 The bot replies like this:
You said: 안녕 나는 봇이야 ("Hi, I'm a bot" in Korean)
📌 You Can Use Many Other Option Types, Too!
Type Description Example
| str | String | message:Hello |
|---|---|---|
| int | Number | count:3 |
| bool | true/false choice | is_public:true |
| discord.User | Pick a user | user:@JohnDoe |
| discord.TextChannel | Pick a text channel | channel:#general |
🧠 Wrapping Up
Slash commands that take options make your bot far more versatile! Next time, we'll look at Enum-style options that limit the choices, or grouping subcommands (Command Groups)!
If you have any questions, leave them in the comments or the guestbook 🙌 Thanks for reading!
Series · Part 2 of 32
Discord Bot Tutorial
- #1Discord Bot Tutorial - Mastering Slash Commands!
- #2Adding Options (Arguments) to Slash Commands!You are here
- #3Adding Subcommands to Slash Commands!
- #4Sending Embeds with Slash Commands!
- #5Implementing Button Interactions!
- #6Implementing a Dropdown (Select Menu)!
- #7Getting User Input with a Modal (Python Example)
- #8Styling Embeds with Images and Fields (Python Example)
- #9Connecting AI (Claude & ChatGPT API) to Your Bot! (Python Example)
- #10Adding Multi-Language (i18n) Support! (Python Example)
- #11Building a Web Dashboard with Flask! (Python Example)
- #12Managing Command Cooldowns and Permissions! (Python Example)
- #13Automating Roles and Channels to Manage Your Server! (Python Example)
- #14Saving Data! JSON vs SQLite (Python Example)
- #15슬래시 명령어 그룹(Group)으로 명령어 정리하기! (파이썬 예제) (Korean)
- #16리마인더·알림 기능 만들기! 봇이 먼저 말 걸게 하기 (파이썬 예제) (Korean)
- #17RAG로 문서 기반 답변봇 만들기! 우리 서버 전용 FAQ 봇 (파이썬 예제) (Korean)
- #18투표(Poll) 기능 만들기! 다수결로 정하는 서버 규칙 (파이썬 예제) (Korean)
- #19Cog로 코드 쪼개기! 1000줄 봇도 안 더러워지는 구조 (파이썬 예제) (Korean)
- #20자동 환영 메시지·온보딩 만들기! 규칙 동의 버튼으로 자동 역할 부여 (파이썬 예제) (Korean)
- #21키워드 자동응답·금지어 필터 만들기! 경고 누적으로 자동 제재까지 (파이썬 예제) (Korean)
- #22슬래시 명령어 자동완성(Autocomplete) 만들기! 금지어를 골라서 추가·삭제 (파이썬 예제) (Korean)
- #23aiosqlite로 비동기 DB 제대로 설계하기! JSON 탈출 (파이썬 예제) (Korean)
- #24채널 난독화(Channel Obfuscation) 대응하기! 11/16부터 안 보이는 채널이 생겨요 (파이썬 예제) (Korean)
- #25봇이 죽지 않게! 에러 핸들링·로깅 체계 잡기 (파이썬 예제) (Korean)
- #26티켓(Ticket) 문의 시스템 만들기! 버튼 하나로 1:1 상담 채널 자동 생성 (파이썬 예제) (Korean)
- #27티켓 담당자 배정·우선순위 만들기! 스태프가 여러 명이어도 안 꼬이게 (파이썬 예제) (Korean)
- #28레벨·경험치(XP) 시스템 만들기! 채팅할수록 레벨업, 랭킹판까지 (파이썬 예제) (Korean)
- #29화폐·상점(Economy) 시스템 만들기! 코인 벌어서 아이템 사기 (파이썬 예제) (Korean)
- #30Build a Poll & Survey Bot! Native Polls + Buttons with Real-Time Tallies (Python Example) 🗳️
- #32Build a Server Log & Audit Log Channel! Auto-Log Message Deletes, Edits, Joins/Leaves, and Kicks (Python Example) 🕵️
- #33임시 음성방 확장, 파티방 만들기! 방장 위임·강퇴·초대 전용(비공개) 방 + 전용 채팅방 자동 생성 (파이썬 예제) 🎉 (Korean)
