【问题标题】:Error-ing out attempting to post a message to discord when a twitter post is made发布推特帖子时尝试发布不和谐的消息时出错
【发布时间】:2021-07-21 09:06:57
【问题描述】:

所以这个想法很简单,我有一个 twitter ID 列表,当这些帐户中的任何一个发布帖子时,我希望这个机器人接收该帖子,并在特定的不和谐频道中分享指向它的链接。目前,当我在 Twitter 上发帖时,它会向我抛出一个错误。 相关代码:

class MyStreamListener(tweepy.StreamListener): #this runs whenever a tweet is posted
    async def on_status(self, status):
        send(status)

bot = commands.Bot(command_prefix='=')
@bot.event
async def on_ready():
    print(f'{bot.user.name} has connected to Discord!')
    myStreamListener = MyStreamListener() #sets up the listener
    myStream = tweepy.Stream(auth = auth_api.auth, listener=myStreamListener)
    myStream.filter(follow=[{ids of the accounts}], is_async = True)
    
async def send(postID):
    channel = bot.get_channel(834887013756305490)
    channel.send('https://twitter.com/twitter/statuses/'+str(postID.id)) #error happens here. 

这是错误: C:...site-packages\tweepy\streaming.py:54: RuntimeWarning: coroutine 'MyStreamListener.on_status' 从未等待 如果 self.on_status(status) 为 False: RuntimeWarning: E​​nable tracemalloc 获取对象分配回溯

我试图在非异步通道中执行此操作,这给了我一个错误,并且我试图在 channel.send 之前添加“等待”(这就是它在例如命令上发送消息的工作方式提示),但这些都不起作用。

如果有人知道我在这里缺少什么,我们将不胜感激。

【问题讨论】:

    标签: python twitter discord discord.py bots


    【解决方案1】:

    Messageable.send是协程,需要等待

    async def send(postID):
        channel = bot.get_channel(834887013756305490)
        await channel.send('https://twitter.com/twitter/statuses/'+str(postID.id))
    

    【讨论】:

      猜你喜欢
      • 2021-06-28
      • 2011-02-27
      • 1970-01-01
      • 1970-01-01
      • 2019-07-19
      • 2019-12-10
      • 1970-01-01
      • 1970-01-01
      • 2014-03-24
      相关资源
      最近更新 更多