如何解决如何在普通函数中等待函数
在以下代码中,我将通过 Tweepy 从 Twitter API 接收推文。我想在 Discord 频道中发送这些推文,但如何在普通类中使用 await 函数。
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)
解决方法
您需要使用 asyncio.Task
来运行协程。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。