【发布时间】:2022-01-08 14:35:38
【问题描述】:
我一直在用 discord.py 和 python 创建一个不和谐的机器人。我希望机器人自动发布从 twitter 检索到的每日 covid 号码。我通过在服务器中发送“$QLD”来启动机器人,如果发布今天的数字,然后休眠 24 小时并再次循环返回发布数字。我唯一的问题是继续发布从原始日期检索到的相同数字。我怎样才能让机器人每天研究推特号码?这是我到目前为止的代码。
import tweepy
import discord
from asyncio import sleep as s
auth = tweepy.OAuthHandler("twitterCodes", "twitterCodes")
auth.set_access_token("twitterCodes", "twitterCodes")
api = tweepy.API(auth)
# a function to get the latest tweet and return it as a string
anna_covid_tweet = api.user_timeline(screen_name="annastaciaMP", count=3, tweet_mode="extended", include_rts=False)
for info in anna_covid_tweet:
if "coronavirus" in info.full_text:
covidnum = info.full_text
else:
print("No tweet found")
#discord bot stuff
client = discord.Client()
bottoken = 'discord bot token'
@client.event
async def on_ready():
print('Logged in as {0.user}'.format(client))
@client.event
async def on_message(message):
while message.content.startswith('$QLD'):
await message.channel.send('These are the QLD covid numbers for today!')
await message.channel.send(covidnum)
await s(86400) - 86400 is 24hours in seconds fyi
client.run(bottoken)
提前谢谢你。非常感谢您的帮助。
【问题讨论】:
标签: python discord discord.py python-asyncio tweepy