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

      <legend id='LEGwG'><style id='LEGwG'><dir id='LEGwG'><q id='LEGwG'></q></dir></style></legend>

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

        <tfoot id='LEGwG'></tfoot>
        • <bdo id='LEGwG'></bdo><ul id='LEGwG'></ul>

        如果用户在具有特定角色时离开服务器,则禁止

        时间:2023-10-10
              <tbody id='EeLhS'></tbody>

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

              1. <tfoot id='EeLhS'></tfoot>
                  <bdo id='EeLhS'></bdo><ul id='EeLhS'></ul>
                  <legend id='EeLhS'><style id='EeLhS'><dir id='EeLhS'><q id='EeLhS'></q></dir></style></legend>

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

                  本文介绍了如果用户在具有特定角色时离开服务器,则禁止用户 discord.py的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我想这样做,如果用户在具有 Muted[Banned] 角色时离开服务器,他们将被永久禁止.

                  I want make it so if a user leaves the server while they have the Muted or [Banned] role they get permanently banned.

                  这是我尝试过的代码:

                  @bot.event
                  async def on_member_remove(ctx, member, reason=None):
                      role="[Banned]"
                      guild = ctx.guild
                      if role in member.roles:
                          await guild.ban(discord.Object(id=member.id), reason="Leaved the server when soft banned")
                  

                  *这只是一个尝试,只有被禁止的角色.

                  *this is just a try with only the banned role.

                  用户没有被禁止,也没有错误或任何可以帮助我解决问题的东西.

                  The user doesn't get banned, there is also no error or anything that could help me troubleshoot it.

                  推荐答案

                  member.roles 返回一个列表 角色

                  您需要获取 Role 对象,您可以使用的一种方法是:

                  You need to get the Role object which one way you can use is:

                  role = discord.utils.find(lambda r: r.name == '[Banned]', member.guild.roles)
                  

                  on_member_remove 接受会员.你不能有 reason 或 Context(ctx)

                  on_member_remove takes in Member. You cannot have reason or Context(ctx)

                  @bot.event
                  async def on_member_remove(member):
                      role = discord.utils.find(lambda r: r.name == '[Banned]', member.guild.roles)
                      guild = member.guild
                      if role in member.roles:
                          await guild.ban(discord.Object(id=member.id), reason="Leaved the server when soft banned")
                  

                  还请确保您启用了成员意图.你可以通过here 然后选择 Bot ->服务器成员意图

                  Please also ensure you have the Members intent enabled. You can do this by going here then selecting Bot -> SERVER MEMBERS INTENT

                  您需要在代码中启用意图,方法是:

                  You will need to do enable intents in your code by using:

                  intents = discord.Intents.default()
                  intents.members = True
                  
                  bot = commands.Bot(command_prefix=".", intents=intents)
                  

                  这篇关于如果用户在具有特定角色时离开服务器,则禁止用户 discord.py的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何在 discord.py 中转义 @everyone? 下一篇:如果用户无权踢球,则无法让 discord.py 引发错误

                  相关文章

                  最新文章

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

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

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

                  2. <tfoot id='xgqJM'></tfoot>