首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在执行discord.py期间停止命令

如何在执行discord.py期间停止命令
EN

Stack Overflow用户
提问于 2020-05-22 13:08:47
回答 1查看 858关注 0票数 1
代码语言:javascript
复制
@client.command()
async def spam(ctx):
  while True:
    time.sleep(2)
    await ctx.send("spam")
    @client.event
    async def on_message(message):
      if message.content == "!stop":
        # stop spamming 

我想要密码停止垃圾邮件,但我不知道怎么做。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-05-22 19:55:29

使用wait_for尝试这个示例

代码语言:javascript
复制
@client.command()
async def spam(ctx):

    def check(m):
        return m.author == ctx.author and m.channel == ctx.channel

    stopped = False
    await ctx.send("spam")
    while not stopped:
        try:
            message = await client.wait_for("message", check=check, timeout=2)
            stopped = True if message.content.lower() == "!stop" else False
        except asyncio.TimeoutError: # make sure you've imported asyncio
            await ctx.send("spam")
    await ctx.send("spam finished!")

参考资料:

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61955827

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档