Python Discord.py显示谁邀请了用户
我目前正试图找出一种方法来知道是谁邀请了一个用户。根据官方文档,我认为Python Discord.py显示谁邀请了用户,python,discord,discord.py,Python,Discord,Discord.py,我目前正试图找出一种方法来知道是谁邀请了一个用户。根据官方文档,我认为成员类应该有一个属性来显示谁邀请了他们,但它没有。我有一个非常模糊的想法,一个可能的方法,让用户谁邀请,这将是得到所有的邀请在服务器上,然后得到使用次数,当有人加入服务器,它会检查,看看邀请已上升使用。但我不知道这是最有效的方法还是至少是最常用的方法。在Discord中,你永远无法100%确定是谁邀请了用户 使用Invite,您就知道是谁创建了Invite 使用on_member_join,您知道谁加入了 所以,是的,你可以检
成员
类应该有一个属性来显示谁邀请了他们,但它没有。我有一个非常模糊的想法,一个可能的方法,让用户谁邀请,这将是得到所有的邀请在服务器上,然后得到使用次数,当有人加入服务器,它会检查,看看邀请已上升使用。但我不知道这是最有效的方法还是至少是最常用的方法。在Discord中,你永远无法100%确定是谁邀请了用户
使用Invite,您就知道是谁创建了Invite
使用on_member_join,您知道谁加入了
所以,是的,你可以检查邀请,看看哪个邀请被撤销了。但是,您永远无法确定是谁邀请的,因为任何人都可以在任何地方粘贴相同的invite链接。查看invite的使用次数,或者查看它们用完并被撤销的时间,是查看用户如何被邀请到服务器的唯一方法。制作一个包含以下内容的
config.json
文件:
{
"token": "Bot token here",
"server-id": "server id here",
"logs-channel-id": "invite channel here"
}
那就省省吧
制作一个名为invests
的频道,然后填写config.json
文件。然后创建一个名为bot.py
的文件,并放置以下内容:
import asyncio
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)
然后打开终端并运行
python3 bot.py
。如需更多帮助,请加入。此操作非常有效。一些评论:如果用户通过右键单击配置文件并向服务器发送邀请,则bot不会对此进行重新定义。此外,支持服务器似乎无法工作,因为无法获得验证和允许。您能否告诉我如何获取邀请用户的信息?我只想要这个,而不是完整的代码。但是谢谢。