使用分页器和 select-menu 制作帮助命令
Making a help command with paginator and select-menu
我正在使用 discord_components 来获取帮助命令。我正在尝试在 python.
中创建类似 dank memer 的帮助命令 下面是 dank-memer
的帮助命令
这是我的代码
@commands.command()
async def select_and_buttons(self, ctx):
embed1=discord.Embed(title="no:1")
embed2=discord.Embed(title="no:2")
embed3=discord.Embed(title="no:3")
embed4=discord.Embed(title="no:4")
embed5=discord.Embed(title="no:5")
embed6=discord.Embed(title="no:6")
embed7=discord.Embed(title="no:7")
embed8=discord.Embed(title="no:8")
embed9=discord.Embed(title="no:9")
embed10=discord.Embed(title="no:10")
pages = [embed1, embed2, embed3, embed4, embed5]
page0 = [embed1, embed2, embed3, embed4, embed5]
page1 = [embed6, embed7, embed8, embed9, embed10]
total_pages=[page0,page1]
page = 0
category="Moderation ️"
components = [
[
Select(
placeholder="Select something",
options=[
SelectOption(label='Moderation', value='Moderation', emoji='️',default=True),
SelectOption(label='Giveaway', value='Giveaway', emoji='',default=False),
SelectOption(label='Games', value='Games', emoji='',default=False),
SelectOption(label='Music', value='Music', emoji='',default=False),
SelectOption(label='Fun', value='Fun', emoji='',default=False),
SelectOption(label='Utils', value='Utils', emoji='️',default=False),
SelectOption(label='Tickets', value='Tickets', emoji='',default=False),
SelectOption(label='Others', value='Others', emoji='✨',default=False)
]
)
],
[
Button(emoji="⏮️",label=' ', style=ButtonStyle.blue, custom_id='move_to_first',disabled=True),
Button(emoji="⬅️",label=' ', style=ButtonStyle.blue, custom_id='move_to_back',disabled=True),
Button(emoji="➡️",label=' ', style=ButtonStyle.blue, custom_id='move_to_next'),
Button(emoji="⏭️",label=' ', style=ButtonStyle.blue, custom_id='move_to_last')
]
]
message = await ctx.send(embed=pages[page], components=components)
while True:
try:
interaction = await self.bot.wait_for(
'interaction',
check=lambda inter: inter.message.id == message.id,
timeout=60
)
except asyncio.TimeoutError:
for row in components:
row.disable_components()
return await message.edit(content='Timed out!', components=components)
if isinstance(interaction.component, Select):
components[0][0].default=False
SelectOption.default=True
pages=page1
page=0
try:
components[1][0].disabled=True
components[1][1].disabled=True
print("check")
except:
pass
await interaction.edit_origin(embed=pages[page], components = components)
# else:
if isinstance(interaction.component, Button):
if interaction.custom_id=="move_to_first":
if(page==len(pages)-1):
components[1][2].disabled = False
components[1][3].disabled = False
page=0
components[1][1].disabled = True
components[1][0].disabled = True
if interaction.custom_id=="move_to_last":
if(page==0):
components[1][1].disabled = False
components[1][0].disabled = False
page=len(pages)-1
components[1][2].disabled = True
components[1][3].disabled = True
if interaction.custom_id == 'move_to_back':
if page == len(pages)-1:
components[1][2].disabled = False
components[1][3].disabled = False
page -= 1
if page == 0:
components[1][1].disabled = True
components[1][0].disabled = True
elif interaction.custom_id == 'move_to_next':
if page == 0:
components[1][1].disabled = False
components[1][0].disabled = False
page += 1
if page == len(pages)-1:
components[1][2].disabled = True
components[1][3].disabled = True
await interaction.edit_origin(embed=pages[page], components=components)
在这部分代码中,按钮命令运行良好,但是当我使用这个 select 部分(下拉)时,它 select 是特定的东西,但没有更新嵌入和禁用按钮,甚至停止按钮的工作。
无论如何要解决这个问题。我不明白是什么问题。有人帮我解决这个问题。
提前感谢您的帮助
经过一番努力,我发现问题出在 select 命令上。
我将 components[0][0].default=False
更改为 components[0][0].options[0].default=False
因为我意识到我没有得到选项。那么这对我来说很好。
感谢那些试图为我解决此代码的人
下面是我的代码,现在可以完美运行(:
@commands.command()
async def select_and_buttons(self, ctx):
embed1=discord.Embed(title="no:1")
embed2=discord.Embed(title="no:2")
embed3=discord.Embed(title="no:3")
embed4=discord.Embed(title="no:4")
embed5=discord.Embed(title="no:5")
embed6=discord.Embed(title="no:6")
embed7=discord.Embed(title="no:7")
embed8=discord.Embed(title="no:8")
embed9=discord.Embed(title="no:9")
embed10=discord.Embed(title="no:10")
pages = [embed1, embed2, embed3, embed4, embed5]
page0 = [embed1, embed2, embed3, embed4, embed5]
page1 = [embed6, embed7, embed8, embed9, embed10]
total_pages=[page0,page1]
page = 0
category="Moderation"
components = [
[
Select(
placeholder="Select something",
options=[
SelectOption(label='Moderation', value='Moderation', emoji='️',default=True),
SelectOption(label='Giveaway', value='Giveaway', emoji=''),
SelectOption(label='Games', value='Games', emoji='',default=False),
SelectOption(label='Music', value='Music', emoji='',default=False),
SelectOption(label='Fun', value='Fun', emoji='',default=False),
SelectOption(label='Utils', value='Utils', emoji='️',default=False),
SelectOption(label='Tickets', value='Tickets', emoji='',default=False),
SelectOption(label='Others', value='Others', emoji='✨',default=False),
SelectOption(label='All', value='All', emoji='✨',default=False)
],min_values=1,
max_values=1
)
],
[
Button(emoji="⏮️",label=' ', style=ButtonStyle.blue, custom_id='move_to_first',disabled=True),
Button(emoji="⬅️",label=' ', style=ButtonStyle.blue, custom_id='move_to_back',disabled=True),
Button(emoji="➡️",label=' ', style=ButtonStyle.blue, custom_id='move_to_next'),
Button(emoji="⏭️",label=' ', style=ButtonStyle.blue, custom_id='move_to_last')
]
]
message = await ctx.send(embed=pages[page], components=components)
while True:
try:
interaction = await self.bot.wait_for(
'interaction',
check=lambda inter: inter.message.id == message.id,
timeout=60
)
except asyncio.TimeoutError:
for row in components:
row.disable_components()
return await message.edit(content='Timed out!', components=components)
if isinstance(interaction.component, Select):
categories=["Moderation","Giveaway","Games","Music","Fun","Utils","Tickets","Others"]
index_before = categories.index(category)
index_now=categories.index(interaction.values[0])
category=interaction.values[0]
components[0][0].options[index_before].default=False
components[0][0].options[index_now].default=True
pages=page1
page=0
components[1][1].disabled = True
components[1][0].disabled = True
await interaction.edit_origin(embed=pages[page],components=components)
# else:
if isinstance(interaction.component, Button):
if interaction.custom_id=="move_to_first":
if(page==len(pages)-1):
components[1][2].disabled = False
components[1][3].disabled = False
page=0
components[1][1].disabled = True
components[1][0].disabled = True
if interaction.custom_id=="move_to_last":
if(page==0):
components[1][1].disabled = False
components[1][0].disabled = False
page=len(pages)-1
components[1][2].disabled = True
components[1][3].disabled = True
if interaction.custom_id == 'move_to_back':
if page == len(pages)-1:
components[1][2].disabled = False
components[1][3].disabled = False
page -= 1
if page == 0:
components[1][1].disabled = True
components[1][0].disabled = True
elif interaction.custom_id == 'move_to_next':
if page == 0:
components[1][1].disabled = False
components[1][0].disabled = False
page += 1
if page == len(pages)-1:
components[1][2].disabled = True
components[1][3].disabled = True
await interaction.edit_origin(embed=pages[page], components=components)
我正在使用 discord_components 来获取帮助命令。我正在尝试在 python.
中创建类似 dank memer 的帮助命令 下面是 dank-memer
的帮助命令
这是我的代码
@commands.command()
async def select_and_buttons(self, ctx):
embed1=discord.Embed(title="no:1")
embed2=discord.Embed(title="no:2")
embed3=discord.Embed(title="no:3")
embed4=discord.Embed(title="no:4")
embed5=discord.Embed(title="no:5")
embed6=discord.Embed(title="no:6")
embed7=discord.Embed(title="no:7")
embed8=discord.Embed(title="no:8")
embed9=discord.Embed(title="no:9")
embed10=discord.Embed(title="no:10")
pages = [embed1, embed2, embed3, embed4, embed5]
page0 = [embed1, embed2, embed3, embed4, embed5]
page1 = [embed6, embed7, embed8, embed9, embed10]
total_pages=[page0,page1]
page = 0
category="Moderation ️"
components = [
[
Select(
placeholder="Select something",
options=[
SelectOption(label='Moderation', value='Moderation', emoji='️',default=True),
SelectOption(label='Giveaway', value='Giveaway', emoji='',default=False),
SelectOption(label='Games', value='Games', emoji='',default=False),
SelectOption(label='Music', value='Music', emoji='',default=False),
SelectOption(label='Fun', value='Fun', emoji='',default=False),
SelectOption(label='Utils', value='Utils', emoji='️',default=False),
SelectOption(label='Tickets', value='Tickets', emoji='',default=False),
SelectOption(label='Others', value='Others', emoji='✨',default=False)
]
)
],
[
Button(emoji="⏮️",label=' ', style=ButtonStyle.blue, custom_id='move_to_first',disabled=True),
Button(emoji="⬅️",label=' ', style=ButtonStyle.blue, custom_id='move_to_back',disabled=True),
Button(emoji="➡️",label=' ', style=ButtonStyle.blue, custom_id='move_to_next'),
Button(emoji="⏭️",label=' ', style=ButtonStyle.blue, custom_id='move_to_last')
]
]
message = await ctx.send(embed=pages[page], components=components)
while True:
try:
interaction = await self.bot.wait_for(
'interaction',
check=lambda inter: inter.message.id == message.id,
timeout=60
)
except asyncio.TimeoutError:
for row in components:
row.disable_components()
return await message.edit(content='Timed out!', components=components)
if isinstance(interaction.component, Select):
components[0][0].default=False
SelectOption.default=True
pages=page1
page=0
try:
components[1][0].disabled=True
components[1][1].disabled=True
print("check")
except:
pass
await interaction.edit_origin(embed=pages[page], components = components)
# else:
if isinstance(interaction.component, Button):
if interaction.custom_id=="move_to_first":
if(page==len(pages)-1):
components[1][2].disabled = False
components[1][3].disabled = False
page=0
components[1][1].disabled = True
components[1][0].disabled = True
if interaction.custom_id=="move_to_last":
if(page==0):
components[1][1].disabled = False
components[1][0].disabled = False
page=len(pages)-1
components[1][2].disabled = True
components[1][3].disabled = True
if interaction.custom_id == 'move_to_back':
if page == len(pages)-1:
components[1][2].disabled = False
components[1][3].disabled = False
page -= 1
if page == 0:
components[1][1].disabled = True
components[1][0].disabled = True
elif interaction.custom_id == 'move_to_next':
if page == 0:
components[1][1].disabled = False
components[1][0].disabled = False
page += 1
if page == len(pages)-1:
components[1][2].disabled = True
components[1][3].disabled = True
await interaction.edit_origin(embed=pages[page], components=components)
在这部分代码中,按钮命令运行良好,但是当我使用这个 select 部分(下拉)时,它 select 是特定的东西,但没有更新嵌入和禁用按钮,甚至停止按钮的工作。
无论如何要解决这个问题。我不明白是什么问题。有人帮我解决这个问题。
提前感谢您的帮助
经过一番努力,我发现问题出在 select 命令上。
我将 components[0][0].default=False
更改为 components[0][0].options[0].default=False
因为我意识到我没有得到选项。那么这对我来说很好。
感谢那些试图为我解决此代码的人
下面是我的代码,现在可以完美运行(:
@commands.command()
async def select_and_buttons(self, ctx):
embed1=discord.Embed(title="no:1")
embed2=discord.Embed(title="no:2")
embed3=discord.Embed(title="no:3")
embed4=discord.Embed(title="no:4")
embed5=discord.Embed(title="no:5")
embed6=discord.Embed(title="no:6")
embed7=discord.Embed(title="no:7")
embed8=discord.Embed(title="no:8")
embed9=discord.Embed(title="no:9")
embed10=discord.Embed(title="no:10")
pages = [embed1, embed2, embed3, embed4, embed5]
page0 = [embed1, embed2, embed3, embed4, embed5]
page1 = [embed6, embed7, embed8, embed9, embed10]
total_pages=[page0,page1]
page = 0
category="Moderation"
components = [
[
Select(
placeholder="Select something",
options=[
SelectOption(label='Moderation', value='Moderation', emoji='️',default=True),
SelectOption(label='Giveaway', value='Giveaway', emoji=''),
SelectOption(label='Games', value='Games', emoji='',default=False),
SelectOption(label='Music', value='Music', emoji='',default=False),
SelectOption(label='Fun', value='Fun', emoji='',default=False),
SelectOption(label='Utils', value='Utils', emoji='️',default=False),
SelectOption(label='Tickets', value='Tickets', emoji='',default=False),
SelectOption(label='Others', value='Others', emoji='✨',default=False),
SelectOption(label='All', value='All', emoji='✨',default=False)
],min_values=1,
max_values=1
)
],
[
Button(emoji="⏮️",label=' ', style=ButtonStyle.blue, custom_id='move_to_first',disabled=True),
Button(emoji="⬅️",label=' ', style=ButtonStyle.blue, custom_id='move_to_back',disabled=True),
Button(emoji="➡️",label=' ', style=ButtonStyle.blue, custom_id='move_to_next'),
Button(emoji="⏭️",label=' ', style=ButtonStyle.blue, custom_id='move_to_last')
]
]
message = await ctx.send(embed=pages[page], components=components)
while True:
try:
interaction = await self.bot.wait_for(
'interaction',
check=lambda inter: inter.message.id == message.id,
timeout=60
)
except asyncio.TimeoutError:
for row in components:
row.disable_components()
return await message.edit(content='Timed out!', components=components)
if isinstance(interaction.component, Select):
categories=["Moderation","Giveaway","Games","Music","Fun","Utils","Tickets","Others"]
index_before = categories.index(category)
index_now=categories.index(interaction.values[0])
category=interaction.values[0]
components[0][0].options[index_before].default=False
components[0][0].options[index_now].default=True
pages=page1
page=0
components[1][1].disabled = True
components[1][0].disabled = True
await interaction.edit_origin(embed=pages[page],components=components)
# else:
if isinstance(interaction.component, Button):
if interaction.custom_id=="move_to_first":
if(page==len(pages)-1):
components[1][2].disabled = False
components[1][3].disabled = False
page=0
components[1][1].disabled = True
components[1][0].disabled = True
if interaction.custom_id=="move_to_last":
if(page==0):
components[1][1].disabled = False
components[1][0].disabled = False
page=len(pages)-1
components[1][2].disabled = True
components[1][3].disabled = True
if interaction.custom_id == 'move_to_back':
if page == len(pages)-1:
components[1][2].disabled = False
components[1][3].disabled = False
page -= 1
if page == 0:
components[1][1].disabled = True
components[1][0].disabled = True
elif interaction.custom_id == 'move_to_next':
if page == 0:
components[1][1].disabled = False
components[1][0].disabled = False
page += 1
if page == len(pages)-1:
components[1][2].disabled = True
components[1][3].disabled = True
await interaction.edit_origin(embed=pages[page], components=components)