我有这个
async def deletechar(ctx):
em = discord.Embed(title = f"Are you sure you want to erase your character?",color = discord.Color.red())
em.add_field(name = "Yes, delete it please",value = "Y")
em.add_field(name = "Nevermind",value = "N")
await ctx.send(embed = em)
response = await client.wait_for_message('message')
if response.content == 'Y' and ctx.author == response.author:
await ctx.send("Successfully Deleted Character")
elif response.content == 'N' and ctx.author == response.author:
await ctx.send("Not Deleted")
这可能写得不好,虽然它有效,只是如果消息不是作者所写,它将被踢出功能。我想在上下文中等待作者的响应,同时忽略其他消息但在执行此操作时不使用太多 CPU。有什么建议吗?
我不希望它挂在这个函数中,因为我希望它在等待这个函数时能够处理来自其他用户的消息
答案 0 :(得分:1)
使用 check
response = await client.wait_for_message('message', check=lambda m: m.author.id == ctx.author.id)