【发布时间】:2021-10-29 18:41:24
【问题描述】:
所以我正在制作一个 Discord 机器人,而且我对它的 API 还比较陌生。我希望按钮能够在不向用户发送消息或任何形式的响应的情况下编辑嵌入。但是,如果我尝试发送空响应或根本没有响应,则每次单击按钮时都会显示“此交互失败”。如果我添加诸如 content = 'text' 之类的内容来响应它可以工作,但我不想发送任何东西。这是我的代码:
@commands.command()
async def assist(self, ctx):
embed = discord.Embed(title = 'Commands', description = 'sdgsdgsdgds', color = 0x0099ff)
message = await ctx.send(
embed = embed,
components = self.buttons
)
while True:
event = await self.client.wait_for('button_click')
if event.channel is not ctx.channel:
return
if event.channel == ctx.channel:
response = event.component.id
if response is None:
await event.channel.send('Something went wrong. Please try again.')
if event.channel == ctx.channel:
if response == '1':
await message.edit(embed = discord.Embed(title = 'New', description = 'HDFGSFGS'))
await event.respond()
【问题讨论】:
-
我不相信“button_click”是一个有效的 discord.py 事件,你应该定义一个按钮回调:discordpy.readthedocs.io/en/master/…
-
它是,所有的代码我只需要一个解决方案来解决我提出的问题。最后一行,即只有在我等待 event.respond(content = 'message') 时才有效。但是,我不想在用户每次单击按钮时都向他们发送消息,以产生有效的交互。
-
您找到解决方案了吗?
标签: python discord bots interaction