带有 wait_for 的条件语句用于用户身份验证

Conditional statements with wait_for for user authentication

我正在尝试创建一个 'gatekeeper-like' 函数,我必须在其中批准或拒绝某些内容。

def confirm(m):
    return m.author == 'my id' m.content == 'confirm' or m.content == 'Confirm'

def deny(m)
    return m.author == 'my id' and m.content == 'deny' or m.content == 'Deny'

auth = await self.bot.wait_for('message', check=confirm)
deauth = await self.bot.wait_for('message', check=deny)

await target.send("```ini\n[Authenticated.]```".format(auth))
await target.send("```ini\n[Denied.]```.format(deauth)"

这里的问题只是我不确定如何在函数中创建 if else 语句。

可能的解决方案

如有任何帮助,我们将不胜感激。

您需要创建一个检查来查找其中任何一条消息。然后一旦 wait_for returns 消息你可以检查它有哪些内容

def confirm_or_deny(m):
    return m.author.id == id  and m.content.lower() in ['confirm', 'deny']

msg = await self.bot.wait_for('message', check=deny)

if msg.content.lower() == 'confirm':
    ...
else:
    ...