일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
- ark plugin
- 마인크래프트 공지 플러그인 만들기
- 파이썬
- discord embed
- 명령어
- 플러그인 제작
- DISCORD BOT
- 플러그인
- 아크서바이벌 플러그인
- slash command
- 마인크래프트 공지 플러그인
- 만들기
- 디스코드 봇 만들기
- 슬래시 커맨드
- 디스코드 봇
- 공지
- discord.py
- 자살명령어
- 아크서바이벌 플러그인 만들기
- 파이썬 봇
- ARK Survival Evolved
- 아크 플러그인
- 파이썬으로 디스코드 봇 만들기
- 디스코드 임베드
- 슬래시 명령어
- 개발자 툴
- ARK
- discord
- 디스코드
- Ark Survival
- Today
- Total
Mojangcam
디스코드 봇 만들기 #2 - Slash Command에 옵션(Arguments) 추가하기! 본문
안녕하세요! Mojangcam입니다 🙌
지난 시간에는 기본적인 슬래시 커맨드 /hello
를 만들어봤죠?
이번에는 사용자 입력값을 받아서 동작하는 Slash Command 를 만들어볼게요.
예를 들면 /say message:안녕
처럼 말이죠!
📦 준비된 코드
이번에도 Python과 discord.py
를 기반으로 합니다.
먼저 아래 코드를 참고해주세요👇
```python
import discord
from discord.ext import commands
from discord import app_commands
intents = discord.Intents.default()
bot = commands.Bot(command_prefix="/", intents=discord.Intents.all())
@bot.event
async def on_ready():
try:
synced = await bot.tree.sync()
await bot.change_presence(activity=discord.Game("디스코드 봇 상태메시지"))
print(f"synced {len(synced)} command(s)")
for i in synced:
print(f"command : {i}")
except Exception as e:
print(e)
기본 hello 명령어
@bot.tree.command(name="hello", description="간단한 인사 명령어")
async def hello(interaction: discord.Interaction):
await interaction.response.send_message("안녕하세요!")
옵션(Arguments)이 있는 say 명령어
@bot.tree.command(name="say", description="입력한 메시지를 따라 말해요!")
@app_commands.describe(message="반복할 메시지를 입력해주세요.")
async def say(interaction: discord.Interaction, message: str):
await interaction.response.send_message(f"당신이 한 말: {message}")
bot.run("YOUR_BOT_TOKEN")
🧪 실제 사용 모습
디스코드 채팅창에 아래처럼 입력하면?
/say message:안녕 나는 봇이야
👇 봇이 이렇게 대답합니다:
📌 다양한 타입의 옵션도 가능해요!
str | 문자열 | message:안녕하세요 |
int | 숫자 | count:3 |
bool | true/false 선택 | is_public:true |
discord.User | 유저 선택 | user:@홍길동 |
discord.TextChannel | 텍스트 채널 선택 | channel:#일반 |
🧠 마무리
옵션을 받는 슬래시 커맨드는 봇의 기능을 한층 더 다양하게 만들어줍니다!
다음 시간에는 선택지를 제한하는 Enum 스타일 옵션,
또는 서브 커맨드 분류(Command Groups) 에 대해서도 알아볼게요!
궁금한 점은 댓글이나 방명록에 남겨주세요 🙌
읽어주셔서 감사합니다!
'Python' 카테고리의 다른 글
디스코드 봇 만들기 #4 - Slash Command로 임베드 전송하기! (0) | 2025.04.18 |
---|---|
디스코드 봇 만들기 #3 - Slash Command에 서브 커맨드(Subcommand) 넣기! (0) | 2025.04.15 |
디스코드 봇 만들기 - Slash Command 완전 정복! (0) | 2025.04.14 |
디스코드 봇 특정 채널에 메시지 보내기 (3) | 2023.12.22 |
디스코드 봇 임베드 만들기 (1) | 2023.12.22 |