首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在按钮中使用wait_for()

在按钮中使用wait_for()
EN

Stack Overflow用户
提问于 2022-04-11 07:15:12
回答 1查看 280关注 0票数 0
代码语言:javascript
复制
@commands.command(name='e')
async def edit(self, ctx):
    firstbutton = Button(label="test")
    await ctx.send('test', components=[firstbutton])
    def check(m): return interaction.component.label == 'test'
    interaction = await self.bot.wait_for("button_click", check=check)
    if interaction.component.label == 'test':
        await ctx.send(content='Clicked')

按钮和消息确实会出现,但是单击按钮时该按钮没有动作。

编辑:包

代码语言:javascript
复制
import json, discord, random, datetime, asyncio
from discord.ext import commands
from discord import utils
import discord
from discord_components import *
EN

回答 1

Stack Overflow用户

发布于 2022-04-11 15:58:02

在您的check()方法中,您将交互视为m,但您正在尝试访问尚未定义的interactionlabel属性。

代码语言:javascript
复制
@commands.command()
async def edit(self, ctx):
    firstbutton = Button(label="test")
    await ctx.send('test', components=[firstbutton])
    def check(m): 
        return m.component.label == 'test'
    interaction = await self.bot.wait_for("button_click", check=check)
    if interaction.component.label == 'test':
        await ctx.send(content='Clicked')

此外,您还提到您没有收到任何错误,您可能需要设置日志记录的不和谐。它将帮助您调试。

对于不和谐-ui:

代码语言:javascript
复制
from discord.ext import commands
from discord_ui import Components, Button, UI

import discord

@bot.command()
async def edit(ctx):
    firstbutton = Button(label="test")
    msg = await ctx.send('test', components=[firstbutton])

    def check(m):
        return m.component.label == 'test'
    interaction = await msg.wait_for("button", bot, check=check)
    if interaction.component.label == 'test':
        await ctx.send(content='Clicked')
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71823952

复制
相关文章

相似问题

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