【问题标题】:How to let only certain people use a command in discord.py?如何只让某些人在 discord.py 中使用命令?
【发布时间】:2018-01-17 03:09:54
【问题描述】:

我想做一个这样的命令:

@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("---")

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

谢谢!

【问题讨论】:

    标签: python python-3.x discord discord.py


    【解决方案1】:

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

    【讨论】:

    • 它表示一个字符串没有名为 author 的属性
    • 更新问题,以便我可以看到您正在使用的新代码
    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-09-09
      • 1970-01-01
      • 1970-01-01
      • 2021-08-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多