Wait_For_组件未在cogs中工作[discordpyslashcommandscomponents]

2024-09-30 22:26:57 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图用discord py slash commands lib在cogs中发送一个按钮,但问题是wait_for_component不起作用,我在控制台中没有收到任何错误,但如果我单击按钮,它会显示交互失败!这是我的齿轮文件

import discord
from discord.ext import commands
from discord_slash.context import ComponentContext
from discord_slash.model import ButtonStyle
from discord_slash.utils.manage_components import create_actionrow, create_button, wait_for_component

class buttons(commands.Cog):
    def __init__(self, client):
        self.client = client
    
    @commands.command()
    async def button(self, ctx):
        btns = [create_button(
                    style=ButtonStyle.green,
                    label="Button!"
                )]
        action_row = create_actionrow(*btns)
        await ctx.send("My Message", components=[action_row])
        button_ctx: ComponentContext = await wait_for_component(self.client,components=actionrow)
        await button_ctx.edit_origin(content="You pressed a button!")
        
def setup(client):
    client.add_cog(buttons(client))

Tags: fromimportselfclientforcreatecomponentsbutton