【问题标题】:Discord.py How to make something only available after something elseDiscord.py 如何使某些内容仅在其他内容之后可用
【发布时间】:2021-05-09 21:08:25
【问题描述】:

我想让 Yes 或 No 仅在您键入 !Version 后才可访问,您能告诉我如何执行此操作吗?我想不通。我的代码每次都可以访问是和否。

async def on_message(message):
    if message.content.startswith('!Version'):
        await message.channel.send('Sure?')     
    if message.content.startswith('Yes'):
            await message.channel.send('This is the Version 1.0')
    if message.content.startswith('No')
            await message.channel.send('Okay')  ```

【问题讨论】:

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


    【解决方案1】:

    最好不要使用消息事件,而是使用命令函数装饰器,以便在命令运行后发送消息。相反,通过使用wait_for,这将使您的机器人基本上“等待”发送所需的消息。在您的情况下,运行命令后,机器人将等待“是”或“否”来确定它接下来可以发送什么。

    这是一个示例,暗示您的问题中有一个命令和wait_for

    @client.command()
    async def version(ctx):
            await ctx.send(f"Sure?")
            msg = await client.wait_for('message',timeout=10,check=lambda message: message.author == ctx.author)
    
            if msg.content.lower() == "yes":
                    await ctx.send("This is the Version 1.0")
    
            if msg.content.lower() == "no":
                    await ctx.send("Okay")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-07
      • 2014-01-06
      • 1970-01-01
      • 2013-02-10
      • 2012-01-15
      • 2012-05-27
      相关资源
      最近更新 更多