dislash.py
v1.4.8
이 라이브러리는 더 이상 Disnake 에 유리하게 유지되지 않습니다. Disnake는 최신 API 기능이 구현 된 Discord.py의 업데이트 된 버전입니다. 슬래시 명령의 구문은 매우 편리하므로 2022 년 4 월 이전에 슬래시 명령으로 전환하려는 경우 Disnake를 사용하는 것이 좋습니다.
궁금한 점이 있으시면 Discord 서버에 가입하십시오
멋진 메시지 구성 요소 및 슬래시 명령을 구축 할 수있는 Discord.py의 확장 라이브러리.
Discord.py는 더 이상 최신 상태를 유지하지 않기 때문에 Fork : Disnake를 만들기로 결정했습니다. DPY 2.0 + 응용 프로그램 명령의 모든 기능이 있습니다.
터미널에서 이러한 명령을 실행하십시오.
pip install dislash.py
python -m pip install dislash.py
이 라이브러리에는 discord.py가 필요합니다.
from discord . ext import commands
from dislash import InteractionClient
bot = commands . Bot ( command_prefix = "!" )
inter_client = InteractionClient ( bot , test_guilds = [ 12345 , 98765 ])
# If 'test_guilds' param isn't specified, the commands are registered globally.
# Global registration takes up to 1 hour.
@ inter_client . slash_command (
name = "hello" , # Defaults to the function name
description = "Says hello" ,
guild_ids = test_guilds
)
async def hello ( inter ):
await inter . reply ( "Hello!" )
bot . run ( "BOT_TOKEN" )이 예제는 버튼으로 메시지를 보내는 방법을 보여줍니다.
from discord . ext import commands
from dislash import InteractionClient , ActionRow , Button , ButtonStyle
bot = commands . Bot ( command_prefix = "!" )
inter_client = InteractionClient ( bot )
@ bot . command ()
async def test ( ctx ):
# Make a row of buttons
row_of_buttons = ActionRow (
Button (
style = ButtonStyle . green ,
label = "Green button" ,
custom_id = "green"
),
Button (
style = ButtonStyle . red ,
label = "Red button" ,
custom_id = "red"
)
)
# Send a message with buttons
msg = await ctx . send (
"This message has buttons!" ,
components = [ row_of_buttons ]
)
# Wait for someone to click on them
def check ( inter ):
return inter . message . id == msg . id
inter = await ctx . wait_for_button_click ( check )
# Send what you received
button_text = inter . clicked_button . label
await inter . reply ( f"Button: { button_text } " )
bot . run ( "BOT_TOKEN" )이 예제는 메뉴와 함께 메시지를 보내는 방법을 보여줍니다.
from discord . ext import commands
from dislash import InteractionClient , SelectMenu , SelectOption
bot = commands . Bot ( command_prefix = "!" )
inter_client = InteractionClient ( bot )
@ bot . command ()
async def test ( ctx ):
msg = await ctx . send (
"This message has a select menu!" ,
components = [
SelectMenu (
custom_id = "test" ,
placeholder = "Choose up to 2 options" ,
max_values = 2 ,
options = [
SelectOption ( "Option 1" , "value 1" ),
SelectOption ( "Option 2" , "value 2" ),
SelectOption ( "Option 3" , "value 3" )
]
)
]
)
# Wait for someone to click on it
inter = await msg . wait_for_dropdown ()
# Send what you received
labels = [ option . label for option in inter . select_menu . selected_options ]
await inter . reply ( f"Options: { ', ' . join ( labels ) } " )
bot . run ( "BOT_TOKEN" )이 예는 컨텍스트 메뉴를 생성하고 그들과 상호 작용하는 방법을 보여줍니다.
from discord . ext import commands
from dislash import InteractionClient
bot = commands . Bot ( command_prefix = "!" )
inter_client = InteractionClient ( bot )
@ inter_client . user_command ( name = "Press me" )
async def press_me ( inter ):
# User commands are visible in user context menus
# They can be global or per guild, just like slash commands
await inter . respond ( "Hello there!" )
@ inter_client . message_command ( name = "Resend" )
async def resend ( inter ):
# Message commands are visible in message context menus
# inter is instance of ContextMenuInteraction
await inter . respond ( inter . message . content )
bot . run ( "BOT_TOKEN" )