【问题标题】:How do I implement a wait_for function into my command?如何在我的命令中实现 wait_for 函数?
【发布时间】:2021-09-03 12:05:28
【问题描述】:

我正在尝试制作一个机器人,它会从文本文件中挑选一个单词,然后对其进行加扰,然后用户解译该单词并键入它。但是我不知道如何在命令中实现wait_for函数。

@client.command()
async def start(ctx):
    await ctx.send('Time for chaos')
    Unscrambled_word = random.choice(list(open('C:\\Users\\user\\Desktop\\Discord Bots\\Fake Speedjar\\words.txt')))

【问题讨论】:

    标签: discord discord.py bots


    【解决方案1】:

    我建议阅读文档here

    它带有一个很好的简单示例。

    还有一个名为 dpytools 的库,它有一个帮助器 (wait_for_author) 来处理这种简单的情况,你可以查看它here

    基本上,wait_for 方法会等待某些东西,然后将其返回给您。在这种情况下是“消息”。

    def check(msg):
        return msg.author == ctx.author and msg.channel == ctx.channel
    
    message = await client.wait_for('message', check=check)
    

    检查函数只接受等待的对象并返回一个布尔值,指示消息是否符合您的期望。

    请查看文档以获取更多信息。

    【讨论】:

      猜你喜欢
      • 2011-04-29
      • 1970-01-01
      • 2020-08-25
      • 2014-01-28
      • 2020-09-10
      • 2020-09-25
      • 2014-02-23
      • 2021-05-20
      • 1970-01-01
      相关资源
      最近更新 更多