@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')按钮和消息确实会出现,但是单击按钮时该按钮没有动作。
编辑:包
import json, discord, random, datetime, asyncio
from discord.ext import commands
from discord import utils
import discord
from discord_components import *发布于 2022-04-11 15:58:02
在您的check()方法中,您将交互视为m,但您正在尝试访问尚未定义的interaction的label属性。
@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:
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')https://stackoverflow.com/questions/71823952
复制相似问题