首页 > 解决方案 > 语法错误 || 不和谐.py || 第 18 行代码

问题描述

我正在创建预售票系统,但我在第 18 行遇到问题,它给了我一个语法错误。请在您的 IDE 中尝试并帮助我

@bot.event

async def on_raw_reaction_add(payload):
    if payload.member.id != bot.user.id and payload.emoji== u"\U0001F3AB":
        msg_id, channel_id, category_id= bot.ticket_configs[payload.guild_id]

        if payload.message_id == msg_id:
            guild= bot.get_guild(payload.guild_id)

            for category in guild.categories:
                if category.id == category_id:
                    break

            channel = guild.get_channel(channel_id)

            ticket_num= 1 if len(category.channels) == 0 else int(category.channels.split("-")[-1]) + 1
            ticket_channel= await category.create_text_channel(f"Ticket {ticket_num}", topic= f"Channel for ticket number {ticket_num}.", permission_synced= True)

            await ticket_channel.set_permissions(payload.member, read_messages= True, send_messages= True) 

            message= await channel.fetch_message(msg_id)
            await message.remove_reaction(payload.emoji, payload.member)

            await ticket_channel.send(f"{payload.member.mention} Thank You! for creating this ticket staff will contact you soon. Type **-close** to close the ticket.")

            try:
                await bot.wait_for("message", check=lamda m: m.channel== ticket_channel and m.author== payload.member and m.content == "-close", timeout= 3600)
            
            except asyncio.TimeoutError:
                await ticket_channel.delete()

            else:
                await ticket_channel.deleted()

标签: pythonlambdadiscorddiscord.py

解决方案


你有一个错字在线

await bot.wait_for("message", check=lamda m: m.channel== ticket_channel and m.author== payload.member and m.content == "-close", timeout= 3600)

应该是lam b da,即

await bot.wait_for(
    "message",
    check=lambda m: m.channel == ticket_channel and m.author == payload.member and m.content == "-close",
    timeout=3600,
)

推荐阅读