我正在从 Novus 切换到 Pycord 并尝试转换按钮功能。我正在尝试获取一个列表并添加按钮 1-n 来表示列表的长度,然后获取所选按钮的 custom_id 。选择后,我想继续该命令并在命令的其余部分中使用 custom_id。到目前为止,这就是我所拥有的:
@bot.slash_command(name='bombs', description='Returns bombs to destroy base and airfield.')
async def bomb(ctx):
await ctx.interaction.response.defer()
countries = ["America", "Britain", "China", "France", "Germany", "Italy", "Japan", "Russia", "Sweden"]
view = DefaultView()
for number in list(range(1, len(countries) + 1)):
view.add_item(DefaultButton(label=str(number), custom_id=str(number)))
country_choice_message = await ctx.interaction.followup.send("Select a country to view bombs from:", view=view)
timed_out_ = await view.wait()
if timed_out_:
view.disable_all_items()
view.stop()
await country_choice_message.edit(view=view)
await ctx.interaction.followup.send("Timed out.", ephemeral=True)
return
# country_number = button_custom_id
# do …Run Code Online (Sandbox Code Playgroud)