다음을 수행하여 라이브러리의 최신 PYPI 버전을 설치할 수 있습니다.
$ pip install reactionmenu
또는 개발 버전 :
$ pip install git+https://github.com/Defxult/reactionmenu
필요한 최소 의도
bot = commands . Bot (..., intents = discord . Intents ( messages = True , guilds = True , reactions = True , members = True )) class reactionmenu.ReactionMenu(method: Union[Context, discord.Interaction], /, *, menu_type: MenuType, **kwargs)
ReactionMenu 는 이모티콘을 사용하여 커스텀 길드 이모티콘 또는 일반 이모티콘 인 이모티콘을 사용하여 페이지 매김 과정을 제어하는 메뉴입니다. 멋진 기능을 찾고 있지 않고 단순한 기능을 원한다면 사용하는 것입니다.
from reactionmenu import ReactionMenu , ReactionButton이 라이브러리에는 불일치 반응 메뉴를 간단하게 만들기 위해 몇 가지 방법과 옵션이 제공됩니다. 적절한 클래스를 가져 오면 생성자를 다음과 같이 초기화하게됩니다.
menu = ReactionMenu ( method , menu_type = ReactionMenu . TypeEmbed )method ( Union[discord.ext.commands.Context, discord.Interaction]menu_type ( MenuType ) 메뉴 구성ReactionMenu.TypeEmbed , 정상적인 임베드 페이지 매김 메뉴ReactionMenu.TypeEmbedDynamic , 동적 데이터가 포함 된 임베드 페이지 매김 메뉴ReactionMenu.TypeText , 텍스트 전용 페이지 매김 메뉴| 이름 | 유형 | 기본값 | 사용 | 정보 |
|---|---|---|---|---|
wrap_in_codeblock | str | None | ReactionMenu.TypeEmbedDynamic | Discord CodeBlock 언어 식별자는 데이터를 래핑합니다. 예 : ReactionMenu(ctx, ..., wrap_in_codeblock='py') |
custom_embed | discord.Embed | None | ReactionMenu.TypeEmbedDynamic | ReactionMenu.add_row() 로 데이터를 추가 할 때 사용할 객체를 포함시킵니다. 스타일링 목적으로 사용됩니다 |
delete_on_timeout | bool | False | All menu types | 시간이 시간이되면 메뉴를 삭제하십시오 |
clear_reactions_after | bool | True | All menu types | 메뉴 시간 이후 모든 반응을 삭제하십시오 |
navigation_speed | str | ReactionMenu.NORMAL | All menu types | 페이지를 "돌리는"전에 사용자가 봇이 반응을 제거 할 때까지 기다려야하는 경우 설정합니다. ReactionMenu.FAST 로 속도를 설정하면 대기 할 필요가 없도록 (각 프레스에서 반응이 제거되지 않음). |
only_roles | List[discord.Role] | None | All menu types | 설정된 경우 주어진 역할을 가진 멤버 만 메뉴를 제어 할 수 있습니다. 메뉴 소유자는 항상 메뉴를 제어 할 수 있습니다 |
timeout | Union[int, float, None] | 60.0 | All menu types | 메뉴가 시간이 지나면 타이머. 시간 초과 없이는 None 될 수 없습니다 |
show_page_director | bool | True | All menu types | 각 임베드 페이지의 하단에 표시됩니다. "페이지 1/20" |
name | str | None | All menu types | 메뉴를 위해 설정할 수있는 이름입니다 |
style | str | "Page $/&" | All menu types | 선택할 수있는 사용자 정의 페이지 감독 스타일. "$"는 현재 페이지를 나타냅니다. "&"는 총 페이지의 총량을 나타냅니다. 예 : ReactionMenu(ctx, ..., style='On $ out of &') |
all_can_click | bool | False | All menu types | 버튼을 클릭하면 페이지가 '회전 할 때 모든 사람이 제어 할 수있는 경우 세트 |
delete_interactions | bool | True | All menu types | ReactionButton.Type.GO_TO_PAGE 사용할 때 어떤 페이지에 가고 싶은지 물었을 때 봇의 프롬프트 메시지와 사용자의 응답 메시지를 삭제하십시오. |
rows_requested | int | None | ReactionMenu.TypeEmbedDynamic | ReactionMenu.add_row() 당 정보의 양은 각 포함 페이지에 적용하고자합니다. |
remove_extra_emojis | bool | False | All menu types | True 이라면 원래 메뉴에 추가되지 않은 메뉴 메시지에 추가 된 모든 이모티콘 (반응)이 제거됩니다. |
menu_type 에 따라 페이지는 str , discord.Embed 또는 content 및 files 의 조합 일 수 있습니다 (아래 예).
menu_type 가 ReactionMenu.TypeEmbed 인 경우 embeds를 사용하십시오menu_type 가 ReactionMenu.TypeText (텍스트 전용 메뉴) 또는 ReactionMenu.TypeEmbedDynamic (포함) 인 경우 문자열을 사용하십시오.ReactionMenu.add_page(embed: discord.Embed=MISSING, content: Optional[str]=None, files: Optional[Sequence[discord.File]]=None)ReactionMenu.add_pages(pages: Sequence[Union[discord.Embed, str]])ReactionMenu.add_row(data: str)ReactionMenu.remove_all_pages()ReactionMenu.clear_all_row_data()ReactionMenu.remove_page(page_number: int)ReactionMenu.set_main_pages(*embeds: Embed)ReactionMenu.set_last_pages(*embeds: Embed) # ReactionMenu.TypeEmbed
menu = ReactionMenu ( method , menu_type = ReactionMenu . TypeEmbed )
menu . add_page ( summer_embed )
menu . add_page ( winter_embed )
# ReactionMenu.TypeText
menu = ReactionMenu ( method , menu_type = ReactionMenu . TypeText )
menu . add_page ( content = 'Its so hot!' )
menu . add_page ( content = 'Its so cold!' ) TypeText 메뉴는 텍스트 기반 페이지 매김 메뉴입니다. 페이지 매김 과정에는 임베드가 관여하지 않으며 일반 텍스트 만 사용됩니다.
v3.1.0+ 사용하면 단순히 임베드 나 텍스트 이상으로이를 보낼 수 있습니다. 텍스트, 임베드 및 파일을 결합 할 수 있습니다. 그러나 menu_type 에 따라 조합이 제한 될 수 있습니다. 다음은 쌓인 TypeEmbed 의 menu_type 있는 메뉴의 예입니다.
# You can use regular commands as well
@ bot . tree . command ( description = "These are stacked pages" , guild = discord . Object ( id = ...))
async def stacked ( interaction : discord . Interaction ):
menu = ReactionMenu ( interaction , menu_type = ReactionMenu . TypeEmbed )
menu . add_page ( discord . Embed ( title = "My Embed" ), content = "This content is stacked on top of a file" , files = [ discord . File ( "stacked.py" )])
menu . add_page ( discord . Embed ( title = "Hey Wumpos, can you say hi to the person reading this? ?" ))
menu . add_page ( discord . Embed ( title = "Hi, I'm Wumpos!" ), files = [ discord . File ( "wumpos.gif" )])
menu . add_button ( ReactionButton . back ())
menu . add_button ( ReactionButton . next ())
await menu . start () menu_type 는 TypeEmbed 이므로 항상 각 페이지에 포함되어야합니다. menu_type TypeText 인 경우, Embeds가 허용되지 않으며 files 매개 변수 만 사용하도록 제한됩니다.
메뉴에 얼마나 많은 정보가 적용되는지 모를 때 동적 메뉴가 사용됩니다. 예를 들어, 데이터베이스에서 정보를 요청하려면 해당 정보가 항상 변경 될 수 있습니다. 당신은 무언가를 쿼리하고 1,500 개의 결과를 다시 얻을 수 있고 다음은 800만을 얻을 수 있습니다. 동적 메뉴는이 모든 정보를 함께 모아서 데이터 행으로 포함 된 페이지에 추가합니다. ReactionMenu.add_row() 모든 것을 반복 할 수있는 Iterable 경우에 가장 잘 사용되지만 메뉴 페이지에 원하는 데이터 양만 추가합니다.
참고 : 동적 메뉴에서 모든 추가 된 데이터는 Embed의 설명 섹션에 배치됩니다.
custom_embed사용하기로 선택한 경우 설명의 모든 텍스트는 추가 데이터로 재정의됩니다.
ReactionMenu.add_row(data: str)ReactionMenu.clear_all_row_data()ReactionMenu.set_main_pages(*embeds: Embed)ReactionMenu.set_last_pages(*embeds: Embed)rows_requested 새 페이지를 만들기 전에 각 임베드 페이지에서 원하는 행의 양ReactionMenu(..., rows_requested=5)custom_embed 포함 된 페이지로 사용하기 위해 만든 임베드. 메뉴 미학에 사용됩니다ReactionMenu(..., custom_embed=red_embed)wrap_in_codeblock Discord CodeBlock으로 데이터를 감싸는 언어 식별자.ReactionMenu(..., wrap_in_codeblock='py') menu = ReactionMenu ( ctx , menu_type = ReactionMenu . TypeEmbedDynamic , rows_requested = 5 )
for data in database . request ( 'SELECT * FROM customers' ):
menu . add_row ( data ) menu.clear_all_row_data()
동적 메뉴를 사용하는 경우 표시된 유일한 임베드 페이지는 추가 한 데이터에서 나온 것입니다. 그러나 데이터 이외의 다른 페이지를 표시하려면 Methods ReactionMenu.set_main_pages() 및 ReactionMenu.set_last_pages() 사용할 수 있습니다. 메인 페이지를 설정하면 설정 한 임베드는 메뉴가 시작될 때 표시되는 첫 번째 임베드가됩니다. 마지막 페이지 설정은 마지막으로 표시된 임베드입니다
menu . set_main_pages ( welcome_embed , announcement_embed )
for data in get_information ():
menu . add_row ( data )
menu . set_last_pages ( additional_info_embed )
# NOTE: setting main/last pages can be set in any order버튼/버튼 유형은 특정 기능을 수행하는 메뉴에 반응을 추가하려는 경우 사용됩니다. 버튼과 버튼 유형은 함께 작동하여 원하는 동작을 달성합니다.
class reactionmenu.ReactionButton(*, emoji: str, linked_to: ButtonType, **kwargs)
emoji ( str ) 반응으로 사용하고 싶은 이모티콘linked_to ( ReactionButton.Type ) 반응을 누르면 이것이 무엇을 할 것인지 결정하는 것입니다.| 이름 | 유형 | 기본값 | 사용 |
|---|---|---|---|
embed | discord.Embed | None | 반응을 누르면 지정된 임베드로 이동 |
name | str | None | 버튼의 이름 |
details | 아래 정보 | None | ReactionButton.Type.CALLER 가 누르면 ReactionButton 있는 기능을 할당하고 인수를 호출해야합니다. |
event | ReactionButton.Event | None | 버튼을 몇 번 눌렀을 때 버튼을 제거 해야하는시기를 결정하십시오. |
skip | ReactionButton.Skip | None | ReactionButton.Type.SKIP 의 linked_to 사용할 때 건너 뛰는 작업과 페이지의 양을 설정하십시오. 예를 들어이 버튼 유형을 사용하여 작업을 "+"및 금액 3으로 설정합니다. "페이지 1/20"에있는 경우 해당 버튼을 누르면 "4/20 페이지"로 연결됩니다. |
| 재산 | 반환 유형 | 정보 |
|---|---|---|
clicked_by | Set[discord.Member] | 버튼을 클릭 한 회원 |
total_clicks | int | 버튼에서 클릭량 |
last_clicked | Optional[datetime.datetime] | 버튼이 마지막으로 클릭되었을 때 UTC의 시간 |
menu | Optional[ReactionMenu] | 버튼이 첨부되어 있습니다 |
ReactionMenu.add_button(button: ReactionButton)ReactionMenu.remove_all_buttons()ReactionMenu.remove_button(button: ReactionButton)ReactionMenu.get_button(identity: Union[str, int], *, search_by='name')ReactionButton.set_caller_details(func: Callable[..., None], *args, **kwargs)| 유형 | 정보 |
|---|---|
ReactionButton.Type.NEXT_PAGE | 메뉴 세션의 다음 페이지로 이동하십시오 |
ReactionButton.Type.PREVIOUS_PAGE | 메뉴 세션의 이전 페이지로 이동하십시오 |
ReactionButton.Type.GO_TO_FIRST_PAGE | 메뉴 세션의 첫 페이지로 이동하십시오 |
ReactionButton.Type.GO_TO_LAST_PAGE | 메뉴 세션의 마지막 페이지로 이동하십시오 |
ReactionButton.Type.GO_TO_PAGE | 가고 싶은 페이지를 입력하라는 메시지가 표시됩니다. |
ReactionButton.Type.END_SESSION | 세션을 중지하고 메뉴 메시지를 삭제합니다 |
ReactionButton.Type.CUSTOM_EMBED | 탐색 버튼과 별도로 사용됩니다. 일단 누르면 지정된 임베드로 이동하십시오 |
ReactionButton.Type.CALLER | 호출 할 기능을 지정할 때 사용하고 버튼을 누르면 인수입니다. |
ReactionButton.Type.SKIP | 단일 버튼 누름으로 여러 페이지를 통해 Pagination |
ReactionButton 사용하여 메뉴에 버튼 (반응)을 추가 할 수 있습니다. 다음은 각 ButtonType 사용하는 방법에 대한 예입니다.
참고 :
ReactionButton.Type.CALLER가있는 ReactionButtons는 약간 다르므로 작동 방식과 아래에서 더 구현하는 방법을 설명하는 전용 섹션이 있습니다.
menu = ReactionMenu (...)
# first and last pages
fpb = ReactionButton ( emoji = '⏪' , linked_to = ReactionButton . Type . GO_TO_FIRST_PAGE )
lpb = ReactionButton ( emoji = '⏩' , linked_to = ReactionButton . Type . GO_TO_LAST_PAGE )
# go to page
gtpb = ReactionButton ( emoji = '?' , linked_to = ReactionButton . Type . GO_TO_PAGE )
# end session
esb = ReactionButton ( emoji = '⏹️' , linked_to = ReactionButton . Type . END_SESSION )
# custom embed
ceb = ReactionButton ( emoji = '?' , linked_to = ReactionButton . Type . CUSTOM_EMBED , embed = discord . Embed ( title = 'Hello' ))
# skip button
sb = ReactionButton ( emoji = '5️⃣' , linked_to = ReactionButton . Type . SKIP , skip = ReactionButton . Skip ( action = '+' , amount = 5 ))
menu . add_button ( fpb )
... menu.remove_all_buttons() 로 모든 버튼을 제거하십시오. 이름을 설정 한 경우 이름을 사용하여 개별 버튼을 제거하거나 menu.remove_button() 이있는 버튼 객체 자체를 제거 할 수도 있습니다.
ReactionButton.Type.CALLER 버튼은 메뉴에 자신의 기능을 구현하는 데 사용됩니다. 어쩌면 텍스트 채널을 작성하거나 메시지를 보내거나 데이터베이스에 무언가를 추가하는 버튼을 추가하려고합니다. ReactionButton.Type.CALLER 로 작업하려면 아래 클래스 방법을 사용하십시오.
ReactionButton.set_caller_details(func: Callable[..., None], *args, **kwargs) 이 클래스 방법은 함수를 설정하는 데 사용되며 버튼을 누르면 나중에 호출되는 인수입니다. ReactionButton 생성자는 Kwarg details 가지고 있으며, 이것이 .set_caller_details() 에서 필요한 값을 할당하기 위해 사용할 것입니다. ReactionButton.Type.CALLER 올바르게 구현하는 방법에 대한 몇 가지 예가 있습니다.
@ bot . command ()
async def user ( ctx , name , * , message ):
await ctx . send ( f"Hi { name } ! { message } . We're glad you're here!" )
def car ( year , make , model ):
print ( f"I have a { year } { make } { model } " )
ub = ReactionButton ( emoji = '' , linked_to = ReactionButton . Type . CALLER , details = ReactionButton . set_caller_details ( user , ctx , 'Defxult' , message = 'Welcome to the server' ))
cb = ReactionButton ( emoji = '?' , linked_to = ReactionButton . Type . CALLER , details = ReactionButton . set_caller_details ( car , 2021 , 'Ford' , 'Mustang' ))참고 : 전달한 기능은 아무 것도 반환해서는 안됩니다.
ReactionButton.Type.CALLER로 기능을 호출하여 해당 함수에 의해 반환 된 내용을 저장하거나 처리하지 않습니다.
ReactionButton 클래스에는 linked_to 에 따라 매개 변수가 설정된 ReactionButton 부턴을 반환하는 설정 공장 메소드 (클래스 메소드)가 함께 제공됩니다.
ReactionButton.back()emoji : "linked_to : ReactionButton.Type.PREVIOUS_PAGEReactionButton.next()emoji : "linked_to : ReactionButton.Type.NEXT_PAGEReactionButton.go_to_first_page()emoji : "i"linked_to : ReactionButton.Type.GO_TO_FIRST_PAGEReactionButton.go_to_last_page()emoji : "i"linked_to : ReactionButton.Type.GO_TO_LAST_PAGEReactionButton.go_to_page()emoji : "?"linked_to : ReactionButton.Type.GO_TO_PAGEReactionButton.end_session()emoji : "i️"linked_to : ReactionButton.Type.END_SESSIONReactionButton.all()ReactionButton list 반환합니다.go_to_first_page() .back() .next() .go_to_last_page() .go_to_page() .end_session()ReactionButton.generate_skip(emoji: str, action: str, amount: int)emoji : <emoji>linked_to : ReactionButton.Type.SKIPskip : ReactionButton.Skip(<action>, <amount>)원한다면 "길드", "멤버"또는 "채널" 당 동시에 활성화 될 수있는 반응 메뉴의 양을 제한 할 수 있습니다.
ReactionMenu.set_sessions_limit(limit: int, per='guild', message='Too many active menus. Wait for other menus to be finished.')ReactionMenu.remove_limit()예:
@ bot . command ()
async def limit ( ctx ):
ReactionMenu . set_sessions_limit ( 3 , per = 'member' , message = 'Sessions are limited to 3 per member' )위의 예를 통해 각 멤버마다 3 개의 메뉴 만 한 번에 활성화 될 수 있으며 다른 메뉴가 완료되기 전에 더 많은 메뉴를 만들려고하면 "세션이 멤버 당 3 개로 제한됩니다"라는 오류 메시지가 표시됩니다.
일정량 눌러 눌렀을 때 ReactionButton 제거 할 수 있습니다.
class ReactionButton.Event(event_type: str, value: int)
event_type ( str ) 취할 조치. 사용 가능한 유일한 옵션은 "제거"입니다.value ( int ) 지정된 이벤트에 대한 금액. > = 1이어야합니다. 값이 <= 0이면 암시 적으로 1으로 설정됩니다.예:
menu = ReactionMenu ( ctx , ...)
# remove a button after 10 clicks
button = ReactionButton (..., event = ReactionButton . Event ( 'remove' , 10 ))
menu . add_button ( button )참고 :
ReactionButton.Type.END_SESSION의linked_to있는 버튼에는 이상적이지 않습니다.
메뉴 릴레이는 메뉴를 제외한 버튼을 누르면 언제든지 호출되는 함수입니다. ReactionButton 의 linked_to 으로 ReactionButton.Type.CALLER 의 연장선으로 간주됩니다. 메뉴의 상호 작용에 대한 세부 정보를 제공하지 않는 발신자 버튼과 달리 릴레이는 그렇습니다.
ReactionMenu.set_relay(func: Callable[[NamedTuple], None], *, only: Optional[List[ReactionButton]]=None)ReactionMenu.remove_relay() 릴레이의 함수를 만들 때 해당 함수에는 단일 위치 인수가 포함되어야합니다. 버튼을 누르면 RelayPayload 객체 (이름 튜플)가 해당 함수로 전달됩니다. RelayPayload 의 속성은 다음과 같습니다.
member ( discord.Member ) 버튼을 누른 사람button ( ReactionButton ) 눌린 버튼예:
async def enter_giveaway ( payload ):
member = payload . member
channel = payload . button . menu . message . channel
await channel . send ( f" { member . mention } , you've entered the giveaway!" )
menu = ReactionMenu ( ctx , ...)
menu . set_relay ( enter_giveaway ) set_relay 메소드는 only 매개 변수와 함께 제공됩니다. 해당 매개 변수가 None 누르는 모든 버튼이 전달됩니다. 해당 매개 변수에 버튼 list 제공 할 수 있으므로 지정된 버튼의 버튼 만 누르면 전달됩니다.
def example ( payload ):
...
menu = ReactionMenu ( ctx , ...)
back_button = ReactionButton . back ()
next_button = ReactionButton . next ()
menu . set_relay ( example , only = [ back_button ])await ReactionMenu.start(*, send_to=None, reply=False)await ReactionMenu.stop(*, delete_menu_message=False, clear_reactions=False) 메뉴를 시작할 때 메뉴를 특정 채널로 보낼 수있는 옵션이 있습니다. 매개 변수 send_to 메뉴를 보내려는 채널입니다. send_to 채널 이름 ( str ), 채널 ID ( int ) 또는 채널 객체 ( discord.TextChannel / discord.Thread )로 설정할 수 있습니다. 예:
menu = ReactionMenu (...)
# channel name
await menu . start ( send_to = 'bot-commands' )
# channel ID
await menu . start ( send_to = 1234567890123456 )
# channel object
channel = guild . get_channel ( 1234567890123456 )
await menu . start ( send_to = channel )
# there's no need to specify send_to unless you want the menu to be sent to a different channel
# from the one you're sending the initial message/using the command in. the menu can be started
# in the current channel by omitting the send_to parameter
await menu . start ()참고 : DM에서 메뉴가 시작된 경우
send_to유효하지 않습니다.
다음은 빠른 데모를 위해 복사 및 붙여 넣을 수있는 ReactionMenu 의 기본 구현입니다.
import asyncio
import discord
from discord . ext import commands
from reactionmenu import ReactionMenu , ReactionButton
bot = commands . Bot ( command_prefix = '!' , intents = discord . Intents . all ())
async def start_bot ():
async with bot :
await bot . start ( '...' )
@ bot . command ()
async def example ( ctx ):
menu = ReactionMenu ( ctx , menu_type = ReactionMenu . TypeEmbed )
for member in ctx . guild . members :
if member . avatar :
embed = discord . Embed ( description = f'Joined { member . joined_at . strftime ( "%b. %d, %Y" ) } ' )
embed . set_author ( name = member . name , icon_url = member . avatar . url )
menu . add_page ( embed )
menu . add_button ( ReactionButton . back ())
menu . add_button ( ReactionButton . next ())
menu . add_button ( ReactionButton . end_session ())
await menu . start ()
asyncio . run ( start_bot ()) class reactionmenu.ViewMenu(method: Union[Context, discord.Interaction], /, *, menu_type: MenuType, **kwargs)
ViewMenu 는 Discords 버튼 기능을 사용하는 메뉴입니다. 버튼을 사용하면 이모티콘으로 특정 색상을 설정하고 숨겨진 메시지를 보내는 버튼이 있고 하이퍼 링크를 추가 할 수 있습니다. 이 라이브러리는 버튼을 누가 누가 누가 눌렀는지, 몇 번이나 누르는 것 등과 같은 광범위한 기능을 제공합니다. Views ( discord.ui.View )를 사용하여 버튼 기능을 구현하지만 버튼 페이지 매김 메뉴를 간단하게 만들기 위해 자체 방법을 사용합니다.
from reactionmenu import ViewMenu , ViewButtonmethod ( Union[discord.ext.commands.Context, discord.Interaction]menu_type ( MenuType ) 메뉴 구성ViewMenu.TypeEmbed , 정상적인 임베드 페이지 매김 메뉴ViewMenu.TypeEmbedDynamic , 동적 데이터가 포함 된 임베드 페이지 매김 메뉴ViewMenu.TypeText , 텍스트 전용 페이지 매김 메뉴| 이름 | 유형 | 기본값 | 사용 | 정보 |
|---|---|---|---|---|
wrap_in_codeblock | str | None | ViewMenu.TypeEmbedDynamic | Discrord CodeBlock 언어 식별자는 데이터를 래핑합니다. 예 : ViewMenu(ctx, ..., wrap_in_codeblock='py') |
custom_embed | discord.Embed | None | ViewMenu.TypeEmbedDynamic | ViewMenu.add_row() 로 데이터를 추가 할 때 사용할 객체를 포함시킵니다. 스타일링 목적으로 사용됩니다 |
delete_on_timeout | bool | False | All menu types | 시간이 시간이되면 메뉴를 삭제하십시오 |
disable_items_on_timeout | bool | True | All menu types | 메뉴가 시간이 지나면 메뉴의 항목을 비활성화합니다. |
remove_items_on_timeout | bool | False | All menu types | 메뉴가 시간이 흐르면 메뉴의 항목을 제거합니다. |
only_roles | List[discord.Role] | None | All menu types | 설정된 경우 주어진 역할을 가진 멤버 만 메뉴를 제어 할 수 있습니다. 메뉴 소유자는 항상 메뉴를 제어 할 수 있습니다 |
timeout | Union[int, float, None] | 60.0 | All menu types | 메뉴가 시간이 지나면 타이머. 시간 초과 없이는 None 될 수 없습니다 |
show_page_director | bool | True | All menu types | 각 임베드 페이지의 하단에 표시됩니다. "페이지 1/20" |
name | str | None | All menu types | 메뉴를 위해 설정할 수있는 이름입니다 |
style | str | "Page $/&" | All menu types | 선택할 수있는 사용자 정의 페이지 감독 스타일. "$"는 현재 페이지를 나타냅니다. "&"는 총 페이지의 총량을 나타냅니다. 예 : ViewMenu(ctx, ..., style='On $ out of &') |
all_can_click | bool | False | All menu types | 버튼을 클릭하면 페이지가 '회전 할 때 모든 사람이 제어 할 수있는 경우 세트 |
delete_interactions | bool | True | All menu types | ViewButton.ID_GO_TO_PAGE 사용할 때 어떤 페이지로 가고 싶은지 물었을 때 봇의 프롬프트 메시지와 사용자의 응답 메시지를 삭제하십시오. |
rows_requested | int | None | ViewMenu.TypeEmbedDynamic | ViewMenu.add_row() 당 정보 금액 각 포함 페이지에 적용하려는 정보 |
menu_type 에 따라 페이지는 str , discord.Embed 또는 content 또는 files 의 조합 일 수 있습니다 (아래 예).
menu_type 가 ViewMenu.TypeEmbed 인 경우 Embeds를 사용하십시오menu_type 가 ViewMenu.TypeText (텍스트 전용 메뉴) 또는 ViewMenu.TypeEmbedDynamic (포함) 인 경우 문자열을 사용하십시오.ViewMenu.add_page(embed: discord.Embed=MISSING, content: Optional[str]=None, files: Optional[Sequence[discord.File]]=None)ViewMenu.add_pages(pages: Sequence[Union[discord.Embed, str]])ViewMenu.add_row(data: str)ViewMenu.remove_all_pages()ViewMenu.clear_all_row_data()ViewMenu.remove_page(page_number: int)ViewMenu.set_main_pages(*embeds: Embed)ViewMenu.set_last_pages(*embeds: Embed) # ViewMenu.TypeEmbed
menu = ViewMenu ( method , menu_type = ViewMenu . TypeEmbed )
menu . add_page ( summer_embed )
menu . add_page ( winter_embed )
# ViewMenu.TypeText
menu = ViewMenu ( method , menu_type = ViewMenu . TypeText )
menu . add_page ( content = 'Its so hot!' )
menu . add_page ( content = 'Its so cold!' ) TypeText 메뉴는 텍스트 기반 페이지 매김 메뉴입니다. 페이지 매김 과정에는 임베드가 관여하지 않으며 일반 텍스트 만 사용됩니다.
v3.1.0+ 사용하면 단순히 임베드 나 텍스트 이상으로이를 보낼 수 있습니다. 텍스트, 임베드 및 파일을 결합 할 수 있습니다. 그러나 menu_type 에 따라 조합이 제한 될 수 있습니다. 다음은 쌓인 TypeEmbed 의 menu_type 있는 메뉴의 예입니다.
# You can use regular commands as well
@ bot . tree . command ( description = "These are stacked pages" , guild = discord . Object ( id = ...))
async def stacked ( interaction : discord . Interaction ):
menu = ViewMenu ( interaction , menu_type = ViewMenu . TypeEmbed )
menu . add_page ( discord . Embed ( title = "My Embed" ), content = "This content is stacked on top of a file" , files = [ discord . File ( "stacked.py" )])
menu . add_page ( discord . Embed ( title = "Hey Wumpos, can you say hi to the person reading this? ?" ))
menu . add_page ( discord . Embed ( title = "Hi, I'm Wumpos!" ), files = [ discord . File ( "wumpos.gif" )])
menu . add_button ( ViewButton . back ())
menu . add_button ( ViewButton . next ())
await menu . start () menu_type 는 TypeEmbed 이므로 항상 각 페이지에 포함되어야합니다. menu_type TypeText 인 경우, Embeds가 허용되지 않으며 files 매개 변수 만 사용하도록 제한됩니다.
메뉴에 얼마나 많은 정보가 적용되는지 모를 때 동적 메뉴가 사용됩니다. 예를 들어, 데이터베이스에서 정보를 요청하려면 해당 정보가 항상 변경 될 수 있습니다. 당신은 무언가를 쿼리하고 1,500 개의 결과를 다시 얻을 수 있고 다음은 800만을 얻을 수 있습니다. 동적 메뉴는이 모든 정보를 함께 모아서 데이터 행으로 포함 된 페이지에 추가합니다. ViewMenu.add_row() 모든 것이 반복 될 수있는 Iterable 인 반복 가능하지만 메뉴 페이지에 원하는 데이터의 양만 추가하는 데 가장 적합합니다.
참고 : 동적 메뉴에서 모든 추가 된 데이터는 Embed의 설명 섹션에 배치됩니다.
custom_embed사용하기로 선택한 경우 설명의 모든 텍스트는 추가 데이터로 재정의됩니다.
ViewMenu.add_row(data: str)ViewMenu.clear_all_row_data()ViewMenu.set_main_pages(*embeds: Embed)ViewMenu.set_last_pages(*embeds: Embed)rows_requested 새 페이지를 만들기 전에 각 임베드 페이지에서 원하는 행의 양ViewMenu(..., rows_requested=5)custom_embed 포함 된 페이지로 사용하기 위해 만든 임베드. 메뉴 미학에 사용됩니다ViewMenu(..., custom_embed=red_embed)wrap_in_codeblock Discord CodeBlock으로 데이터를 감싸는 언어 식별자.ViewMenu(..., wrap_in_codeblock='py') menu = ViewMenu ( ctx , menu_type = ViewMenu . TypeEmbedDynamic , rows_requested = 5 )
for data in database . request ( 'SELECT * FROM customers' ):
menu . add_row ( data ) menu.clear_all_row_data()
동적 메뉴를 사용하는 경우 표시된 유일한 임베드 페이지는 추가 한 데이터에서 나온 것입니다. 그러나 데이터 외에 다른 페이지를 표시하려면 Methods ViewMenu.set_main_pages() 및 ViewMenu.set_last_pages() 사용할 수 있습니다. 메인 페이지를 설정하면 설정 한 임베드는 메뉴가 시작될 때 표시되는 첫 번째 임베드가됩니다. 마지막 페이지 설정은 마지막으로 표시된 임베드입니다
menu . set_main_pages ( welcome_embed , announcement_embed )
for data in get_information ():
menu . add_row ( data )
menu . set_last_pages ( additional_info_embed )
# NOTE: setting main/last pages can be set in any order버튼은 메뉴와 상호 작용하는 데 사용하는 것입니다. 반응과 달리, 그들은 더 깨끗해 보이고, 덜 제한 문제를 제공하며, 상호 작용 측면에서 더 많은 것을 제공합니다. 버튼을 활성화 및 비활성화하고 메시지의 Markdown 하이퍼 링크를 사용하고 숨겨진 메시지를 보내십시오.
ViewMenu.add_button(button: ViewButton)ViewMenu.disable_all_buttons()ViewMenu.disable_button(button: ViewButton)ViewMenu.enable_all_buttons()ViewMenu.enable_button(button: ViewButton)ViewMenu.get_button(identity: str, *, search_by='label')ViewMenu.remove_all_buttons()ViewMenu.remove_button(button: ViewButton)await ViewMenu.refresh_menu_items() class reactionmenu.ViewButton(*, style=discord.ButtonStyle.secondary, label=None, disabled=False, custom_id=None, url=None, emoji=None, followup=None, event=None, **kwargs)
ViewButton 은 Discord 버튼을 나타내는 클래스입니다. discord.ui.Button 의 서브 클래스입니다.
다음은 버튼에 대한 불화로 설정된 규칙입니다.
custom_id 있어야 하며 url 가질 수 없습니다.url 있어야 하며 custom_id 없어야합니다.style ( discord.ButtonStyle ) 버튼 스타일label ( str ) 버튼의 텍스트custom_id ( str ) 버튼을 가져야 할 조치를 결정하기위한 ID. 사용 가능한 ID :ViewButton.ID_NEXT_PAGEViewButton.ID_PREVIOUS_PAGEViewButton.ID_GO_TO_FIRST_PAGEViewButton.ID_GO_TO_LAST_PAGEViewButton.ID_GO_TO_PAGEViewButton.ID_END_SESSIONViewButton.ID_CALLERViewButton.ID_SEND_MESSAGEViewButton.ID_CUSTOM_EMBEDViewButton.ID_SKIPemoji ( Union[str, discord.PartialEmoji] ) 이모티콘ViewButton(..., emoji='?')ViewButton(..., emoji='<:miscTwitter:705423192818450453>')ViewButton(..., emoji='U000027a1')ViewButton(..., emoji='N{winking face}')discord.ButtonStyle.link 가있는 버튼에 대한 url ( str ) URLdisabled ( bool )followup ( ViewButton.Followup ) 버튼을 누른 후 보낸 메시지가 표시됩니다. ViewButton.ID_CALLER 또는 ViewButton.ID_SEND_MESSAGE 의 custom_id 가있는 버튼에만 사용할 수 있습니다. ViewButton.Followup discord.abc.Messageable.send() 와 유사한 매개 변수가있는 클래스이며 메시지가 임시 인 경우 제어하는 데 사용되며 파일, 포함, TTS 등을 포함합니다.event ( ViewButton.Event ) 일정 시간이 걸렸을 때 버튼을 비활성화하거나 제거 할 버튼을 설정합니다. | 이름 | 유형 | 기본값 | 사용 |
|---|---|---|---|
name | str | None | 버튼의 이름 |
skip | ViewButton.Skip | None | ViewButton.ID_SKIP 의 custom_id 사용할 때 작업과 페이지의 양을 건너 뛰는 작업량을 설정하십시오. 예를 들어, 조치를 "+"및 금액 3으로 설정합니다. "페이지 1/20"에있는 경우 해당 버튼을 누르면 "4/20 페이지"로 연결됩니다. |
persist | bool | False | 링크 버튼이 비활성화/제거되지 않거나 메뉴가 꺼지거나 중지되면 클릭 가능하게 유지할 수 있습니다. |
| 재산 | 반환 유형 | 정보 |
|---|---|---|
clicked_by | Set[discord.Member] | 버튼을 클릭 한 회원 |
total_clicks | int | 버튼에서 클릭량 |
last_clicked | Optional[datetime.datetime] | 버튼이 마지막으로 클릭되었을 때 UTC의 시간 |
menu | Optional[ViewMenu] | 버튼이 첨부되어 있습니다 |
from reactionmenu import ViewMenu , ViewButton
menu = ViewMenu ( ctx , menu_type = ViewMenu . TypeEmbed )
# Link button
link_button = ViewButton ( style = discord . ButtonStyle . link , emoji = '?' , label = 'Link to Google' , url = 'https://google.com' )
menu . add_button ( link_button )
# Skip button
skip = ViewButton ( style = discord . ButtonStyle . primary , label = '+5' , custom_id = ViewButton . ID_SKIP , skip = ViewButton . Skip ( action = '+' , amount = 5 ))
menu . add_button ( skip )
# ViewButton.ID_PREVIOUS_PAGE
back_button = ViewButton ( style = discord . ButtonStyle . primary , label = 'Back' , custom_id = ViewButton . ID_PREVIOUS_PAGE )
menu . add_button ( back_button )
# ViewButton.ID_NEXT_PAGE
next_button = ViewButton ( style = discord . ButtonStyle . secondary , label = 'Next' , custom_id = ViewButton . ID_NEXT_PAGE )
menu . add_button ( next_button )
# All other ViewButton are created the same way as the last 2 EXCEPT
# 1 - ViewButton.ID_CALLER
# 2 - ViewButton.ID_SEND_MESSAGE
# 3 - ViewButton.ID_CUSTOM_EMBED
# ViewButton.ID_CALLER
def say_hello ( name : str ):
print ( 'Hello' , name )
call_followup = ViewButton . Followup ( details = ViewButton . Followup . set_caller_details ( say_hello , 'John' ))
menu . add_button ( ViewButton ( label = 'Say hi' , custom_id = ViewButton . ID_CALLER , followup = call_followup ))
# ViewButton.ID_SEND_MESSAGE
msg_followup = ViewButton . Followup ( 'This message is hidden!' , ephemeral = True )
menu . add_button ( ViewButton ( style = discord . ButtonStyle . green , label = 'Message' , custom_id = ViewButton . ID_SEND_MESSAGE , followup = msg_followup ))
# ViewButton.ID_CUSTOM_EMBED
custom_embed_button = ViewButton ( style = discord . ButtonStyle . blurple , label = 'Social Media Info' , custom_id = ViewButton . ID_CUSTOM_EMBED , followup = ViewButton . Followup ( embed = discord . Embed (...)))참고 :
ViewButton.ID_CALLER의custom_id,ViewButton.ID_SEND_MESSAGE,ViewButton.ID_CUSTOM_EMBED또는 링크 버튼이있는 버튼과 관련하여 총 25 개의 버튼 이하로 원하는만큼 추가 할 수 있습니다. 다른 모든 버튼 ID의 경우 각 메뉴에만 가질 수 있습니다.
선택은 메뉴에서 정보를 분류하려면 사용됩니다. SELECT는 Menu의 menu_type 가 TypeEmbed 인 경우에만 사용할 수 있습니다. 각 메시지에 몇 개의 메뉴 UI 항목 (행)을 적용 할 수있는 메뉴 UI 항목 수에 대한 불화 제한 사항을 명심해야합니다.
Page.from_embeds(embeds: Sequence[Embed])ViewMenu.add_select(select: ViewSelect)ViewMenu.remove_select(select: ViewSelect)ViewMenu.remove_all_selects()ViewMenu.disable_select(select: ViewSelect)ViewMenu.disable_all_selects()ViewMenu.enable_select(select: ViewSelect)ViewMenu.enable_all_selects()ViewMenu.get_select(title: Union[str, None])예:
from reactionmenu import ViewMenu , ViewSelect , Page
menu = ViewMenu ( ctx , menu_type = ViewMenu . TypeEmbed )
menu . add_page ( discord . Embed ( title = "A showcase of console video games" , color = discord . Color . blurple ()))
menu . add_select ( ViewSelect ( title = "Console Video Games" , options = {
# NOTE: The discord.SelectOption parameter "default" cannot be set to True
discord . SelectOption ( label = "PlayStation" , emoji = "<:PlayStation:549638412538478602>" ) : [
Page ( embed = discord . Embed ( title = "Ratchet & Clank" , description = ..., color = discord . Color . yellow ()). set_image ( url = ...)),
Page ( embed = discord . Embed ( title = "God of War" , description = ..., color = discord . Color . blue ()). set_image ( url = ...))
],
discord . SelectOption ( label = "Xbox" , emoji = "<:Xbox:501880493285834752>" ) : [
Page ( embed = discord . Embed ( title = "Halo Infinite" , description = ..., color = discord . Color . green ()). set_image ( url = ...)),
Page ( embed = discord . Embed ( title = "Gears of War 4" , description = ..., color = discord . Color . red ()). set_image ( url = ...))
]
}))
menu . add_button ( ViewButton . back ())
menu . add_button ( ViewButton . next ())
await menu . start ()UI를 사용하여 이동할 페이지를 선택할 때이 유형의 Select를 사용할 수 있습니다.
ViewMenu.add_go_to_select(goto: ViewSelect.GoTo)ViewMenu.enable_go_to_select(goto: ViewSelect.GoTo)ViewMenu.enable_all_go_to_selects()ViewMenu.disable_go_to_select(goto: ViewSelect.GoTo)ViewMenu.disable_all_go_to_selects()ViewMenu.remove_go_to_select(goto: ViewSelect.GoTo)ViewMenu.remove_all_go_to_selects() ViewSelect.GoTo 의 page_numbers 매개 변수는 3 가지 다른 유형으로 사용할 수 있습니다.
List[int] 정수 목록으로 설정된 경우 지정된 값은 SELECT를 클릭 할 때 사용 가능한 유일한 옵션입니다.page_numbers=[1, 5, 10]Dict[int, Union[str, discord.Emoji, discord.PartialEmoji]]page_numbers={1 : "?️", 2 : ""}ellipsis 문자 그대로의 타원을 설정하여 라이브러리가 메뉴에 추가 한 페이지의 양에 모든 페이지 번호를 자동으로 할당하도록 할 수 있습니다. 25 페이지 이하인 경우 유용 할 수 있습니다.page_numbers=...참고 :
page_numbers매개 변수 설정은 Ellipsis (...)로 설정하면 메뉴에 페이지를 추가 한 후 선택을 추가 한 경우에만 작동합니다.
@ bot . command ()
async def navigate ( ctx ):
menu = ViewMenu ( ctx , menu_type = ViewMenu . TypeEmbed )
menu . add_page ( discord . Embed ( title = "Twitter" ). set_image ( url = "..." ))
menu . add_page ( discord . Embed ( title = "YouTube" ). set_image ( url = "..." ))
menu . add_page ( discord . Embed ( title = "Discord" ). set_image ( url = "..." ))
# ...
menu . add_go_to_select ( ViewSelect . GoTo ( title = "Go to page..." , page_numbers = ...))
menu . add_button ( ViewButton . back ())
menu . add_button ( ViewButton . next ())
await menu . start ()await ViewMenu.refresh_menu_items()await ViewMenu.update(*, new_pages: Union[List[Union[Embed, str]], None], new_buttons: Union[List[ViewButton], None]) 메뉴가 실행될 때 메뉴의 페이지 또는 버튼을 업데이트 할 수 있습니다. ViewMenu.update() 사용하면 페이지와 버튼을 교체 할 수 있습니다. ViewMenu.refresh_menu_items() 사용하면 변경된 버튼이 업데이트됩니다.
@ bot . command ()
async def menu ( ctx ):
menu = ViewMenu (..., name = 'test' )
link_button = ViewButton (..., label = 'Link' )
menu . add_button ( link_button )
menu . add_page (...)
await menu . start ()
@ bot . command ()
async def disable ( ctx ):
menu = ViewMenu . get_session ( 'test' )
link_button = menu [ 0 ]. get_button ( 'Link' , search_by = 'label' )
menu . disable_button ( link_button )
await menu . refresh_menu_items () ViewMenu.refresh_menu_items() 로 버튼이 새로 고침되지 않으면 버튼을 변경할 때 메뉴가 업데이트되지 않습니다.
메소드 ViewMenu.update(...) 는 메뉴의 버튼을 모두 교체 할 때 사용됩니다.
menu = ViewMenu (...)
# in a different .command()
await menu . update ( new_pages = [ hello_embed , goodbye_embed ], new_buttons = [ link_button , next_button ])참고 :
ViewMenu.update(...)사용할 때는 업데이트 호출 중에 업데이트되므로ViewMenu.refresh_menu_items()사용할 필요가 없습니다.
ViewButton 클래스에는 custom_id (링크 버튼 제외)에 따라 매개 변수가 설정된 ViewButton 반환하는 설정 공장 메소드 (클래스 메소드)가 함께 제공됩니다.
ViewButton.link(label: str, url: str)style : discord.ButtonStyle.linklabel : <label> 라벨>url : <url>ViewButton.back()style : discord.ButtonStyle.graylabel : "뒤로"custom_id : ViewButton.ID_PREVIOUS_PAGEViewButton.next()style : discord.ButtonStyle.graylabel : "다음"custom_id : ViewButton.ID_NEXT_PAGEViewButton.go_to_first_page()style : discord.ButtonStyle.graylabel : "첫 페이지"custom_id : ViewButton.ID_GO_TO_FIRST_PAGEViewButton.go_to_last_page()style : discord.ButtonStyle.graylabel : "마지막 페이지"custom_id : ViewButton.ID_GO_TO_LAST_PAGEViewButton.go_to_page()style : discord.ButtonStyle.graylabel : "페이지 선택"custom_id : ViewButton.ID_GO_TO_PAGEViewButton.end_session()discord.ButtonStyle.grayViewButton.ID_END_SESSIONViewButton.all()ViewButton list 반환합니다.go_to_first_page() .back() .next() .go_to_last_page() .go_to_page() .end_session()ViewButton.all_with_emojis()emoji 매개 변수로 ViewButton list 반환합니다..go_to_first_page() .back() .next() .go_to_last_page() .go_to_page() .end_session()ViewButton.generate_skip(label: str, action: str, amount: int)style : discord.ButtonStyle.graylabel : <label> 라벨>custom_id : ViewButton.ID_SKIPskip : ViewButton.Skip(<action>, <amount>) menu = ViewMenu ( ctx , ...)
menu . add_page (...)
menu . add_page (...)
menu . add_button ( ViewButton . back ())
menu . add_button ( ViewButton . next ())
await menu . start () ViewButton 일정량 눌렀을 때 비활성화하거나 제거 할 수 있습니다.
class ViewButton.Event(event_type: str, value: int)
event_type ( str ) 취할 조치. "비활성화"또는 "제거"될 수 있습니다.value ( int ) 지정된 이벤트에 대한 금액. > = 1이어야합니다. 값이 <= 0이면 암시 적으로 1으로 설정됩니다.예:
menu = ViewMenu ( ctx , ...)
# disable a button after 5 clicks
button_1 = ViewButton (..., event = ViewButton . Event ( 'disable' , 5 ))
menu . add_button ( button_1 )
# remove a button after 10 clicks
button_2 = ViewButton (..., event = ViewButton . Event ( 'remove' , 10 ))
menu . add_button ( button_2 )참고 : 링크 버튼에는 유효하지 않습니다. 또한
ViewButton.ID_END_SESSION의custom_id있는 버튼에 이상적이지 않습니다.
메뉴 릴레이는 메뉴를 제외한 버튼을 누르면 언제든지 호출되는 함수입니다. ViewButton.ID_CALLER 의 ID가있는 ViewButton 의 확장으로 간주됩니다. 메뉴의 상호 작용에 대한 세부 정보를 제공하지 않는 발신자 버튼과 달리 릴레이는 그렇습니다.
ViewMenu.set_relay(func: Callable[[NamedTuple], None], *, only: Optional[List[ViewButton]]=None)ViewMenu.remove_relay() 릴레이의 함수를 만들 때 해당 함수에는 단일 위치 인수가 포함되어야합니다. 버튼을 누르면 RelayPayload 객체 (이름 튜플)가 해당 함수로 전달됩니다. RelayPayload 의 속성은 다음과 같습니다.
member ( discord.Member ) 버튼을 누른 사람button ( ViewButton ) 눌린 버튼예:
async def enter_giveaway ( payload ):
member = payload . member
channel = payload . button . menu . message . channel
await channel . send ( f" { member . mention } , you've entered the giveaway!" )
menu = ViewMenu ( ctx , ...)
menu . set_relay ( enter_giveaway ) set_relay 메소드는 only 매개 변수와 함께 제공됩니다. 해당 매개 변수가 None 누르면 모든 버튼이 릴레이됩니다 (링크 버튼은 상호 작용 이벤트를 보내지 않기 때문에 링크 버튼 제외). 해당 매개 변수에 버튼 list 제공 할 수 있으므로 지정된 버튼의 버튼 만 누르면 전달됩니다.
def example ( payload ):
...
menu = ViewMenu ( ctx , ...)
back_button = ViewButton . back ()
next_button = ViewButton . next ()
menu . set_relay ( example , only = [ back_button ])await ViewMenu.start(*, send_to=None, reply=False)await ViewMenu.stop(*, delete_menu_message=False, remove_buttons=False, disable_buttons=False) 메뉴를 시작할 때 메뉴를 특정 채널로 보낼 수있는 옵션이 있습니다. 매개 변수 send_to 메뉴를 보내려는 채널입니다. send_to 채널 이름 ( str ), 채널 ID ( int ) 또는 채널 객체 ( discord.TextChannel / discord.Thread )로 설정할 수 있습니다. 예:
menu = ViewMenu (...)
# channel name
await menu . start ( send_to = 'bot-commands' )
# channel ID
await menu . start ( send_to = 1234567890123456 )
# channel object
channel = guild . get_channel ( 1234567890123456 )
await menu . start ( send_to = channel )
# there's no need to specify send_to unless you want the menu to be sent to a different channel
# from the one you're sending the initial message/using the command in. the menu can be started
# in the current channel by omitting the send_to parameter
await menu . start ()참고 : DM에서 메뉴가 시작된 경우
send_to유효하지 않습니다.
메뉴를 중지하면 하나의 옵션 만 사용할 수 있습니다. True 의 매개 변수가 있으면 하나만 실행합니다.
delete_menu_message > disable_buttonsdisable_buttons > remove_buttons 다음은 빠른 데모를 위해 복사 및 붙여 넣을 수있는 기본적인 ViewMenu 구현입니다.
import asyncio
import discord
from discord . ext import commands
from reactionmenu import ViewMenu , ViewButton
bot = commands . Bot ( command_prefix = '!' , intents = discord . Intents . all ())
async def start_bot ():
async with bot :
await bot . start ( '...' )
@ bot . command ()
async def example ( ctx ):
menu = ViewMenu ( ctx , menu_type = ViewMenu . TypeEmbed )
for member in ctx . guild . members :
if member . avatar :
embed = discord . Embed ( description = f'Joined { member . joined_at . strftime ( "%b. %d, %Y" ) } ' )
embed . set_author ( name = member . name , icon_url = member . avatar . url )
menu . add_page ( embed )
menu . add_button ( ViewButton . back ())
menu . add_button ( ViewButton . next ())
menu . add_button ( ViewButton . end_session ())
await menu . start ()
asyncio . run ( start_bot ())