【问题标题】:Autoclaimer not working whenever it startsAutoclaimer 启动时不工作
【发布时间】:2022-01-04 01:52:58
【问题描述】:

我正在构建一个与 Discord 集成的 TikTok 用户名声明程序,这样你就可以运行它,它会获得成功,将命中发布到 Discord 上,第一个获得它的人获胜。除非每当我运行程序时,它都会说我已登录,但实际的声明者本身不起作用。 这是我的代码:

import requests
import discord
import sys
class Client(discord.Client):
    async def on_ready(self):
        print('Logged on as', self.user)
def tiktokclaimer():
  url = 'https://tiktok.com/@'
  with open('4s.txt') as f:
      line = f.readline().strip()
      while line:
          line = f.readline().strip()
          req = requests.get(url + line)
          if req.status_code == int(404):
            async def claimer(message):
              response = "go claim @" + line
              message.channel.send(response)
          elif req.status_code == int(403):
            async def ratelimited(message):
              response = "Ratelimited!"
              message.channel.send(response)
              sys.quit()
          elif req.status_code == int(429):
            ratelimited()
            sys.quit()
          else:
            print("An error has occurred that is not already defined. " + str(req.status_code) + " " + str(req.reason))
            break
client = Client()
client.run('MY_TOKEN')
tiktokclaimer()

【问题讨论】:

    标签: python python-requests discord discord.py


    【解决方案1】:

    client.run 是一个阻塞调用。它阻止了它之后的所有代码。因此tiktokclaimer() 永远不会执行。您需要在 client.run 之前使用 treading 库在另一个线程中运行您的函数,或者在 on_ready 事件中调用它。

    【讨论】:

    • 试过了,还是不行:/
    猜你喜欢
    • 2017-05-07
    • 2022-12-26
    • 1970-01-01
    • 1970-01-01
    • 2014-04-19
    • 2015-12-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多