这是代码:
class ticket_launcher(discord.ui.View):
def __init__(self) -> None:
super().__init__(timeout=None)
@discord.ui.Button(label='Create a ticket', style = discord.ButtonStyle.blurple, custom_id = 'ticket_button')
async def ticket(self, button: discord.ui.Button, interaction: discord.Interaction):
ticket = discord.utils.get(interaction.guild.text_channels, name = f'ticket-for-{interaction.user.name}-{interaction.user.discriminator}')
if ticket is not None: await interaction.response.send_message(f'You already have a ticket open at {ticket.mention}!', ephemeral = True)
else:
overwrites = {
interaction.guild.default_role: discord.PermissionOverwrite(view_channel = False),
interaction.user: discord.PermissionOverwrite(view_channel = True, send_messages = True, attach_files = True, embed_links = True),
interaction.guild.me: discord.PermissionOverwrite(view_channel = True, send_messages = True, read_message_history = True)
}
channel = await interaction.guild.create_text_channel(name=f'ticket-for-{interaction.user.name}-{interaction.user.discriminator}', overwrites=overwrites, reason=f'Ticket for {interaction.user}.')
await channel.send(f'{interaction.user.mention} created a ticket!')
await interaction.response.send_message(f'I have opened a ticket for you at {channel.mention}.', ephemeral=True)
tree = app_commands.CommandTree(client=client)
@tree.command(guild = discord.Object(id=TICKET_CHANNEL), name='ticket', description='Launches the ticket system.')
async def ticket(interaction: discord.Interaction):
embed = discord.Embed(title='If you have any problems click the big blue button below!', color=discord.Colour.blue())
await interaction.channel.send(embed=embed, view=ticket_launcher())
await interaction.response.send_message('Ticketing system has been launched successfully.', ephemeral=True)
它在输出中给我这个错误消息:
Traceback (most recent call last):
File "c:UsersschulDesktopMORE PYTHONbot.py", line 214, in <module>
class ticket_launcher(discord.ui.View):
File "c:UsersschulDesktopMORE PYTHONbot.py", line 219, in ticket_launcher
async def ticket(self, button: discord.ui.Button, interaction: discord.Interaction):
TypeError: 'Button' object is not callable
所以,有人介意帮我解决这个问题吗,因为这有点烦人,如果你能帮我的话,那将是谢天谢地:(
在按钮装饰器中,使用小写的button
:
@discord.ui.button(label='Create a ticket', style = discord.ButtonStyle.blurple, custom_id = 'ticket_button')
文档:https://discordpy.readthedocs.io/en/latest/interactions/api.html?highlight=button#discord.ui.button