0

I'm not an expert with async stuff but I don't understand this. I'm using TwitterAPI to fetch the Twitter API stream endpoint for new posts. I set the channel and it should listen for new posts and it works fine. But why can't I use my foo command while the set_channel function is running? I thought it's async... I'm probably understanding something completely wrong, whatever. Help would be appreciated.

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

```
itsame
  • 171
  • 4
  • 14
  • See [here](https://stackoverflow.com/a/53597795/7808223). The issue is exactly the same - requests is a synchronous module, meaning that it's blocking your asynchronous code in d.py. – Diggy. May 19 '20 at 23:03
  • You don't `await` anything. Without that your code will always be synchronous. – dirn May 20 '20 at 00:25

0 Answers0