Mojangcam

디스코드 봇 만들기 - Slash Command 완전 정복! 본문

Python

디스코드 봇 만들기 - Slash Command 완전 정복!

Mojangcam 2025. 4. 14. 21:33
반응형

오늘은 디스코드 봇 만들기 시리즈 중에서도, 요즘 대세인 슬래시 커맨드(Slash Command) 를 만들어보려고 합니다.
/명령어 형태로 입력하는 그거 아시죠?
일반 텍스트 명령어보다 훨씬 깔끔하고, 자동완성도 돼서 요즘은 거의 필수 기능이에요!

 

일단 왜 이 글을 쓰는지 간단하게 설명드리도록 하겠습니다

슬래시 커맨드에 대해서 올라온 글이 몇개 없더라구요 그래서 제가 그냥 필기용으로 하나 쓰려고 합니다

 

💡 준비물

  • Python 3.x
  • Discord 개발자 계정
  • discord.py 라이브러리 (v2 이상, 슬래시 명령어 지원 버전!)
  • 봇 토큰

 

pip install -U discord

 

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)

@bot.tree.command(name="hello", description="간단한 인사 명령어")
async def hello(interaction: discord.Interaction):
    await interaction.response.send_message("안녕하세요!")

bot.run("YOUR_BOT_TOKEN")

 

🚀 실행 후 디스코드에서 /hello 입력해보면?

"안녕하세요! 👋"
이렇게 슬래시 명령어가 짜잔~ 하고 작동합니다!

 

🧠 마무리 + 다음 편 예고

이번엔 아주 기본적인 슬래시 명령어를 만들어봤어요!
다음 편에서는 옵션(Arguments) 을 넣는 방법이나,
명령어 카테고리로 분리하는 법도 다뤄볼게요.

궁금한 점은 댓글로 남겨주세요~
읽어주셔서 감사합니다! 😊

반응형