• <tfoot id='1DYYU'></tfoot>

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

        <legend id='1DYYU'><style id='1DYYU'><dir id='1DYYU'><q id='1DYYU'></q></dir></style></legend>

      1. discord.py 试图删除用户的所有角色

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

          • <tfoot id='qbYDa'></tfoot>

                <bdo id='qbYDa'></bdo><ul id='qbYDa'></ul>
              • <small id='qbYDa'></small><noframes id='qbYDa'>

                <legend id='qbYDa'><style id='qbYDa'><dir id='qbYDa'><q id='qbYDa'></q></dir></style></legend>
                <i id='qbYDa'><tr id='qbYDa'><dt id='qbYDa'><q id='qbYDa'><span id='qbYDa'><b id='qbYDa'><form id='qbYDa'><ins id='qbYDa'></ins><ul id='qbYDa'></ul><sub id='qbYDa'></sub></form><legend id='qbYDa'></legend><bdo id='qbYDa'><pre id='qbYDa'><center id='qbYDa'></center></pre></bdo></b><th id='qbYDa'></th></span></q></dt></tr></i><div id='qbYDa'><tfoot id='qbYDa'></tfoot><dl id='qbYDa'><fieldset id='qbYDa'></fieldset></dl></div>
                1. 本文介绍了discord.py 试图删除用户的所有角色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我有一个问题,我试图删除用户对某种静音角色的所有角色,但它给了我这个错误 discord.ext.commands.errors.CommandInvokeError: Command raise an exception: NotFound: 404 Not Found (error code: 10011): Unknown Role

                  I have a problem that I`m trying to remove all roles a user has for some kind of mute role but it gives me this error discord.ext.commands.errors.CommandInvokeError: Command raised an exception: NotFound: 404 Not Found (error code: 10011): Unknown Role

                  这是我的代码

                  @client.command(aliases=['m'])
                  @commands.has_permissions(kick_members = True)
                  async def mute(ctx,member : discord.Member):
                      muteRole = ctx.guild.get_role(728203394673672333)
                      for i in member.roles:
                          await member.remove_roles(i)
                      await member.add_roles(muteRole)
                      await ctx.channel.purge(limit = 1)
                      await ctx.send(str(member)+' has been muted!')
                  

                  我知道这种问题已经在这里问过了:如何一次删除所有角色 (Discord.py 1.4.1).但它没有得到回答,根本没有帮助我

                  I know that this kind of questiion was alredy asked here: How to remove all roles at once (Discord.py 1.4.1). But it wasn`t answered and did not help me at all

                  推荐答案

                  问题是所有用户都有一个隐形角色",@everyone.如果你尝试,你会看到它出现

                  The problem is that all users have an "invisible role", @everyone. You will see it show up if you try

                  for i in member.roles:
                      print(i)
                  

                  remove_roles 是一个高级函数,它会尝试删除导致您的错误的 @everyone.

                  remove_roles is a high level function and it will try to remove @everyone, which is causing your error.

                  要清除用户的所有当前角色,您可以:

                  To clear all current roles from the user, you can do:

                  @client.command(aliases=['m'])
                  @commands.has_permissions(kick_members = True)
                  async def mute(ctx, member : discord.Member):
                      muteRole = ctx.guild.get_role(775449115022589982)
                      await member.edit(roles=[muteRole]) # Replaces all current roles with roles in list
                      await ctx.channel.purge(limit = 1)
                      await ctx.send(str(member)+' has been muted!')
                  

                  await member.edit(roles=[]) 将所有当前角色替换为您在列表中拥有的角色.将列表留空以删除用户的所有角色.

                  await member.edit(roles=[]) Replaces all the current roles with the roles you have in the list. Leave the list empty to remove all roles from the user.

                  discord.Member.edit

                  虽然如果你想用 for 循环 来做,你可以使用 try

                  Although if you want to do it with a for loop, you can use try

                  @client.command(aliases=['m'])
                  @commands.has_permissions(kick_members = True)
                  async def mute(ctx, member : discord.Member):
                      muteRole = ctx.guild.get_role(775449115022589982)
                      for i in member.roles:
                          try:
                              await member.remove_roles(i)
                          except:
                              print(f"Can't remove the role {i}")
                      await member.add_roles(muteRole)
                      await ctx.channel.purge(limit = 1)
                      await ctx.send(str(member)+' has been muted!')
                  

                  这篇关于discord.py 试图删除用户的所有角色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:获取服务器 discord.py 中的提升次数 下一篇:检查用户是否在语音频道 discord.py

                  相关文章

                  最新文章

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

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

                    <tfoot id='SWpM1'></tfoot>

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