discord.py邀请追踪器

时间:2020-05-14 17:10:41

标签: python discord.py

当我使用此处找到的脚本时,该脚本可让您跟踪用户邀请其他成员 不和谐。脚本运行良好,一会儿我收到以下错误

从未检索到任务异常 将来:exception = AttributeError(“'NoneType'对象没有属性'invites'”)> 追溯(最近一次通话): 正在提取文件“ H:/TheVoidv2/bot.py”,行1509 invs =等待gld.invites()

这个错误,一旦机器人运行了好几个小时

Task exception was never retrieved
future: <Task finished name='Task-1' coro=<fetch() done, defined at C:\Users\Administrator\Desktop\TheVoidv2\bot.py:1416> exception=HTTPException('503 Service Unavailable (error code: 0): upstream connect error or disconnect/reset before headers. reset reason: connection failure')>
Traceback (most recent call last):
  File "C:\Users\Administrator\Desktop\TheVoidv2\bot.py", line 1423, in fetch
    invs = await gld.invites()
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\guild.py", line 1407, in invites
    data = await self._state.http.invites_from(self.id)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\http.py", line 225, in request
    raise HTTPException(r, data)
discord.errors.HTTPException: 503 Service Unavailable (error code: 0): upstream connect error or disconnect/reset before headers. reset reason: connection failure
import datetime
import json
import os
import commands

client = discord.Client()
cfg = open("config.json", "r")
tmpconfig = cfg.read()
cfg.close()
config = json.loads(tmpconfig)

token = config["token"]
guild_id = config["server-id"]
logs_channel = config["logs-channel-id"]


invites = {}
last = ""

async def fetch():
 global last
 global invites
 await client.wait_until_ready()
 gld = client.get_guild(int(guild_id))
 logs = client.get_channel(int(logs_channel))
 while True:
  invs = await gld.invites()
  tmp = []
  for i in invs:
   for s in invites:
    if s[0] == i.code:
     if int(i.uses) > s[1]:
      usr = gld.get_member(int(last))
      testh = f"{usr.name} **joined**; Invited by **{i.inviter.name}** (**{str(i.uses)}** invites)"
      await logs.send(testh)
   tmp.append(tuple((i.code, i.uses)))
  invites = tmp
  await asyncio.sleep(4)


@client.event
async def on_ready():
 print("ready!")
 await client.change_presence(activity = discord.Activity(name = "joins", type = 2))


@client.event
async def on_member_join(meme):
 global last
 last = str(meme.id)




client.loop.create_task(fetch())
client.run(token)

0 个答案:

没有答案