0

In the following code I'll receive Tweets from the Twitter API over Tweepy. I want to send these Tweets in a Discord channel, but how can I work with an await function in a normal class.

import discord
import tweepy 

class Client(discord.Client):
    async def on_ready(self):
        print('ready')

class TweepyStream(tweepy.Stream):
    def on_connect(self):
        print('connceted')

    def on_status(self, status):
        print(status.text)
        #How can I here send a message into a discord channel ?


stream = TweepyStream(keys)
stream.filter(follow = [],  threaded=True)

client = Client()
client.run(token)
Harmon758
  • 5,084
  • 3
  • 22
  • 39

1 Answers1

0

You'll want to use an asyncio.Task to run the coroutine.

Harmon758
  • 5,084
  • 3
  • 22
  • 39
  • 3
    "Use X" is more of a comment. If you are answering a question, you should include an example or some context so that your post answers the question fully. – Pranav Hosangadi Jun 03 '21 at 19:58
  • But when i want to send a message 'await channel.send(message)' it doesnt work it gives me the error: 'RuntimeError: Timeout context manager should be used inside a task' What do i have to do now ? – Moritttzzzz Jun 04 '21 at 16:04
  • Are you using a new event loop? You should use the existing event loop. – Harmon758 Jun 04 '21 at 17:58