반응형
반응형
보통 슬래시 커맨드를 검색하면
pip install discord-py-slash-command
from discord_slash import SlashCommand, SlashContext
이런식으로 설치하라고 말한다.
하지만 내가 했을 때는 계속해서 no moduel discord_slash
라고 떠서 사용할 수 없었다.
계속 찾다가 쓰는 방법을 발견해서 올린다.
준비
먼저 슬래시 커맨드를 사용하려면 처음 디스코드 봇을 서버에 초대할때 application_commads를 체크해야 한다.
- 디스코드 개발자
- OAuth2
- URL Generator
이렇게 bot과 application_commands를 체크하고 초대할 해야한다.
slash_command 사용
이제 본격적으로 슬래시 커맨드를 사용해보자
from discord import app_command
from discord.ext import commands
# 생략
bot = commands.Bot(command_prefix='!', intents=intents)
# 생략
@bot.tree.command(name='hello', description='testing') # 명령어 이름, 설명
@app_commands.describe(text1='쓸 내용', text2 = '번호') # 같이 쓸 내용들
async def hello(interaction: discord.Interaction, text1:str, text2:int): # 출력
await interaction.response.send_message(f'{interaction.user.mention} : {text1} : {text2}', ephemeral=True)
반응형
'코딩 > 디스코드' 카테고리의 다른 글
디스코드 봇 음성채널 입장 안될때 (1) | 2023.10.10 |
---|---|
디스코드 봇으로 채널 만들기 (0) | 2023.10.10 |
디스코드 봇 특정 채널에 메시지 보내기 (0) | 2023.10.10 |
디스코드 봇 포럼에 글쓰기 (0) | 2023.10.10 |
디스코드 봇 일정한 시간마다 메시지 보내기 (0) | 2023.10.10 |