【发布时间】:2021-09-06 10:10:08
【问题描述】:
代码做了应该做的事情,但每次按下按钮后都会显示“此交互失败”。按下按钮编辑嵌入以将其更改为另一个。按下按钮后如何消除交互失败消息?
问题:https://i.stack.imgur.com/i4dTd.png
收到的代码来自:https://github.com/elixss/YouTube/blob/main/source/buttons.py
代码如下:
@bot.group(invoke_without_command=True)
async def help(ctx):
# buttons
one = Button(style=1, label="Commands", id="em1")
two = Button(style=1, label="Depression", id="em2")
three = Button(style=1, label="Moderator", id="em3")
four = Button(style=1, label="Language", id="em4")
# embeds
em1 = Embed(title="Commands Plugin",color=0x5865F2)
em2 = Embed(title="Depression Plugin", description="placeholder", color=0x5865F2)
em3 = Embed(title="Moderator Plugin", description="placeholder", color=0x5865F2)
em4 = Embed(title="Language Plugin", description="placeholder", color=0x5865F2)
# main help embed
help_embed = Embed(description="> **Help Module**\nPress on any button to view the commands for that selected plugin.",
color=discord.Color.random())
# buttons to embeds
buttons = {
"em1": em1,
"em2": em2,
"em3": em3,
"em4": em4
}
msg = await ctx.send(embed=help_embed,
components=[[one, two, three, four]])
while True:
event = await bot.wait_for("button_click", timeout=60.0)
if event.channel is not ctx.channel:
return
if event.channel == ctx.channel:
response = buttons.get(event.component.id)
await msg.edit(embed=response)
if response is None:
await event.channel.send("error, try again.")
【问题讨论】:
-
嵌入应该是
discord.Embed()而不仅仅是Embed() -
@ChaoticNebula 不。他本可以使用
from discord import Embed而不是import discord。这没有什么问题。 -
也许..他直接导入了? @ChaoticNebula
-
是的,我用过
from discord import Embed -
我今天学到的新东西????
标签: discord.py