discord.py异步功能阻止

时间:2020-05-19 22:41:49

标签: python asynchronous python-asyncio discord.py

我不是处理异步问题的专家,但是我不明白这一点。我正在使用TwitterAPI来获取Twitter API流端点的新帖子。我设置了频道,它应该收听新帖子,并且效果很好。但是为什么在set_channel函数运行时不能使用foo命令?我以为是异步的... 无论如何,我可能都在理解完全错误的东西。帮助将不胜感激。

@bot.command()
async def set_channel(ctx):
    while True:
        try:
            iterator = api.request(
                'statuses/filter', {'follow': user_ids}).get_iterator()
            for item in iterator:
                if 'text' in item:
                    await ctx.channel.send(item['text'])
                elif 'disconnect' in item:
                    event = item['disconnect']
                    if event['code'] in [2, 5, 6, 7]:
                        raise Exception(event['reason'])
                    else:
                        break
        except TwitterRequestError as e:
            if e.status_code < 500:
                raise
            else:
                pass
        except TwitterConnectionError:
            pass


@bot.command()
async def foo(ctx):
    await ctx.channel.send("bar")

```

0 个答案:

没有答案