如何在discord.py中只让某些人使用命令?

How to let only certain people use a command in discord.py?

我想做一个这样的命令:

@client.event
@asyncio.coroutine
def on_message(message):
    if message.content.startswith('~superknot'):
        if message.author == "random id here":
            yield from client.say('are you sure?')
            msg = yield from client.wait_for_message(author=message.author, content='yes')
            yield from client.say("---")

所以只有一个人可以执行这个命令,但是,它不起作用,怎么会?

谢谢!

您目前使用它来检查整个 message.author 值是否只等于其自身的一部分。要解决此问题,请将 message.author 替换为 message.author.id

您想要的只是将 message.author 更改为 message.author.id。 但我推荐的是使用 checks.py for async, and discord.ext.commands.checks 进行重写。两个示例都使用命令扩展。