1. <i id='xfYES'><tr id='xfYES'><dt id='xfYES'><q id='xfYES'><span id='xfYES'><b id='xfYES'><form id='xfYES'><ins id='xfYES'></ins><ul id='xfYES'></ul><sub id='xfYES'></sub></form><legend id='xfYES'></legend><bdo id='xfYES'><pre id='xfYES'><center id='xfYES'></center></pre></bdo></b><th id='xfYES'></th></span></q></dt></tr></i><div id='xfYES'><tfoot id='xfYES'></tfoot><dl id='xfYES'><fieldset id='xfYES'></fieldset></dl></div>
      • <bdo id='xfYES'></bdo><ul id='xfYES'></ul>
      <legend id='xfYES'><style id='xfYES'><dir id='xfYES'><q id='xfYES'></q></dir></style></legend>

      1. <tfoot id='xfYES'></tfoot>

        <small id='xfYES'></small><noframes id='xfYES'>

        Discord.py 显示谁邀请了用户

        时间:2023-10-11

            <tbody id='Rhs43'></tbody>

              <bdo id='Rhs43'></bdo><ul id='Rhs43'></ul>
              <legend id='Rhs43'><style id='Rhs43'><dir id='Rhs43'><q id='Rhs43'></q></dir></style></legend>

              1. <i id='Rhs43'><tr id='Rhs43'><dt id='Rhs43'><q id='Rhs43'><span id='Rhs43'><b id='Rhs43'><form id='Rhs43'><ins id='Rhs43'></ins><ul id='Rhs43'></ul><sub id='Rhs43'></sub></form><legend id='Rhs43'></legend><bdo id='Rhs43'><pre id='Rhs43'><center id='Rhs43'></center></pre></bdo></b><th id='Rhs43'></th></span></q></dt></tr></i><div id='Rhs43'><tfoot id='Rhs43'></tfoot><dl id='Rhs43'><fieldset id='Rhs43'></fieldset></dl></div>
                <tfoot id='Rhs43'></tfoot>

                • <small id='Rhs43'></small><noframes id='Rhs43'>

                • 本文介绍了Discord.py 显示谁邀请了用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我目前正在尝试找出一种方法来了解谁邀请了用户.从官方文档中,我认为 member 类将具有显示谁邀请他们的属性,但事实并非如此.我对获取邀请的用户的可能方法有一个非常模糊的想法,那就是获取服务器中的所有邀请,然后获取使用次数,当有人加入服务器时,它会检查是否有增加的邀请一种用途.但我不知道这是否是最有效的方法,或者至少是使用过的方法.

                  I am currently trying to figure out a way to know who invited a user. From the official docs, I would think that the member class would have an attribute showing who invited them, but it doesn't. I have a very faint idea of a possible method to get the user who invited and that would be to get all invites in the server then get the number of uses, when someone joins the server, it checks to see the invite that has gone up a use. But I don't know if this is the most efficient method or at least the used method.

                  推荐答案

                  制作一个 config.json 文件,内容为

                  Make a config.json file with the content of

                  {
                      "token": "Bot token here",
                      "server-id": "server id here",
                      "logs-channel-id": "invite channel here"
                  }
                  

                  然后保存.

                  创建一个名为 invites 的频道,然后填写 config.json 文件.然后创建一个名为 bot.py 的文件并将内容放入:

                  Make a channel called invites then fill in the config.json file. And then create a file called bot.py and put the contents of:

                  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.如需更多帮助,请加入 this.

                  Then open the terminal and run python3 bot.py. And for more help join this.

                  这篇关于Discord.py 显示谁邀请了用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:前缀和非前缀命令在 python discord bot 上不能一起工 下一篇:如何在 discord.py 中设置可选参数?

                  相关文章

                  最新文章

                • <legend id='ZivP4'><style id='ZivP4'><dir id='ZivP4'><q id='ZivP4'></q></dir></style></legend>
                  • <bdo id='ZivP4'></bdo><ul id='ZivP4'></ul>

                    1. <small id='ZivP4'></small><noframes id='ZivP4'>

                      <i id='ZivP4'><tr id='ZivP4'><dt id='ZivP4'><q id='ZivP4'><span id='ZivP4'><b id='ZivP4'><form id='ZivP4'><ins id='ZivP4'></ins><ul id='ZivP4'></ul><sub id='ZivP4'></sub></form><legend id='ZivP4'></legend><bdo id='ZivP4'><pre id='ZivP4'><center id='ZivP4'></center></pre></bdo></b><th id='ZivP4'></th></span></q></dt></tr></i><div id='ZivP4'><tfoot id='ZivP4'></tfoot><dl id='ZivP4'><fieldset id='ZivP4'></fieldset></dl></div>
                      <tfoot id='ZivP4'></tfoot>