不和谐的回调.py 2.0没有开火



我有一个交互角色系统,我的回调不起作用。我没有从中得到任何错误。这是我使用的代码:

class IRRoleButton(discord.ui.Button["InteractionRoles"]):
def __init__(self, role: discord.Role):
super().__init__(style=discord.ButtonStyle.primary, label=role.name, custom_id=role.id)
# role = discord.utils.get(interaction.guild.roles, id=id)
self.role = role

async def callback(self, interaction: discord.Interaction):
print("wow")
try:
await interaction.user.add_roles(self.role)
embed = discord.Embed(title="IR role added", description=f"You have been given the IR role {self.role.name}.", color=bot.success)
except Exception as e:
embed = discord.Embed(title="Something went wrong", description=f"Contact the server administrator.", color=bot.error)
print(e)
await interaction.response.send_message(embed=embed, ephemeral=True)

class InteractionRoles(discord.ui.View):
def __init__(self, interaction: discord.Interaction, irroles: list):
super().__init__()
for button in irroles:
role = discord.utils.get(interaction.guild.roles, id=button["rid"])
if role:
self.add_item(IRRoleButton(role)) 
@apptree.command(description="Opens a public IR panel.", guild=discord.Object(id=956522017983725588))
@app_commands.describe(group="The ID of the group to open.")
async def iropen(interaction: discord.Interaction, group: int):
await interaction.response.defer()
group = await bot.db.fetchrow("SELECT * FROM irgroups WHERE grid = $1", group)
if not group:
embed = discord.Embed(title="IR group not found", description=f"An IR group with the ID `{group}` does not exist.", color=bot.error)
return await interaction.followup.send(embed=embed) 

irroles = await bot.db.fetch("SELECT * FROM irroles WHERE grid = $1", group["grid"])
await interaction.channel.send(embed=discord.Embed(title=str(group['gname']), description="Press a button to get the corresponding role.", color=bot.accent), view=InteractionRoles(interaction, irroles))
await interaction.followup.send(embed=discord.Embed(title="IR panel opened", description=f"The IR panel for {group['gname']} has been opened.", color=bot.success))

我知道回拨不起作用,因为"哇"根本没有打印。

我使用的是不和谐.py 2.0版

预期:赋予用户的角色

结果:什么也没发生

我似乎用int传递了custom_id,但它需要str.

最新更新