首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在与按钮交互后编辑/删除斜杠命令消息(不和py disnake api包装器)

如何在与按钮交互后编辑/删除斜杠命令消息(不和py disnake api包装器)
EN

Stack Overflow用户
提问于 2022-11-25 19:34:04
回答 1查看 18关注 0票数 0

下面是一个简单的硬币翻转例子,我为这个问题做了一个简单的例子:有任何方法可以-edit原始的斜杠命令消息和硬币翻转的结果,以去掉按钮-delete,原始斜杠命令消息

代码语言:javascript
复制
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遇到困难的地方,因为我想在按钮交互之后编辑/删除斜杠命令交互。

EN

回答 1

Stack Overflow用户

发布于 2022-11-27 10:29:12

编辑:

代码语言:javascript
复制
await inter.response.edit_message()
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74577232

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档