下面是一个简单的硬币翻转例子,我为这个问题做了一个简单的例子:有任何方法可以-edit原始的斜杠命令消息和硬币翻转的结果,以去掉按钮-delete,原始斜杠命令消息
class CoinFlipButtons(disnake.ui.View):
def __init__(self):
super().__init__(timeout=60)
@bot.slash_command(description="starts coin flip game")
async def coinflip(inter):
await inter.response.send_message("Coin has been flipped what shall you choose?", view=CoinFlipButtons())
@disnake.ui.button(label="Heads", style=ButtonStyle.green)
async def first_button(self, button: disnake.ui.Button, inter: disnake.MessageInteraction):
coin = random.randrange(1,2)
if coin == 1:
coin = "heads"
else:
coin = "tails"
if coin == "heads":
await inter.response.send_message(content=f"You were correct! It was {coin}")
else:
await inter.response.send_message(content=f"Oh no! The coin was {coin}")
@disnake.ui.button(label="Tails", style=ButtonStyle.red)
async def second_button(self, button: disnake.ui.Button, inter: disnake.MessageInteraction):
coin = random.randrange(1,2)
if coin == 1:
coin = "heads"
else:
coin = "tails"
if coin == "tails":
await inter.response.send_message(f"You were correct! It was {coin}")
else:
await inter.response.send_message(f"Oh no! The coin was {coin}")我尝试在文档中搜索编辑、原始响应、消息函数或其他类似的东西,但是这些函数都无法工作,因为当我向按钮发送新的响应时,交互是重新定义的,这是im遇到困难的地方,因为我想在按钮交互之后编辑/删除斜杠命令交互。
发布于 2022-11-27 10:29:12
编辑:
await inter.response.edit_message()https://stackoverflow.com/questions/74577232
复制相似问题