python - 我正在尝试使用不和谐机器人使用 tweepy 自动发布推文
问题描述
我知道这可能是一个简单的修复,但我遇到了一个问题,即机器人发布消息的方法在自定义客户端类中,而接收推文的方法在 MSL 类中。我非常肯定这是一个简单的解决方案,我只是愚蠢,但我无法让机器人发布推文。
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token,access_token_secret)
api = tweepy.API(auth)
load_dotenv('botAttributes.env')
TOKEN = os.getenv('DISCORD_TOKEN')
GUILD = os.getenv('DISCORD_GUILD')
client = discord.Client()
class MSL(tweepy.StreamListener):
def on_status(self, status):
print(status.text)
def on_error(self, status_code):
if status_code == 420:
return False
else:
print(status_code)
class CustomClient(discord.Client):
async def on_ready(self):
print(f'{self.user} has connected to Discord!')
print("the program should start showing tweets")
StreamListener = MSL()
MS = tweepy.Stream(auth = api.auth, listener = StreamListener)
MS.filter(track=['#python'],is_async=True)
client = CustomClient()
client.run(TOKEN)
解决方案
推荐阅读
- java - Tomcat SSL 证书配置:java.lang.Exception,回复中的公钥和密钥库不匹配
- postgresql - 使用 Docker 连接到 Postgres
- php - ld:找不到符号 dyld_stub_binding_helper,通常在 crt1.o/dylib1.o/bundle1.o 中,用于架构 i386
- time-series - 用户定义的脚本超时。超时设置为 30.0 秒
- python - 标头在 ModelAdmin get_form() 中不可见
- python-3.x - Python3 导入错误:没有名为“pytest”的模块
- c# - 对象引用未设置为实例 c#
- firebase - 读取 firebase kotlin 后设置 UI 元素
- python - 如何使用 __getitem__ 方法?
- javascript - 在 three.js 中使用 camera.lookat() 时停止对象的倾斜