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

    2. <legend id='1I65W'><style id='1I65W'><dir id='1I65W'><q id='1I65W'></q></dir></style></legend>
      <tfoot id='1I65W'></tfoot>
      • <bdo id='1I65W'></bdo><ul id='1I65W'></ul>

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

      如何检查用户是否在不和谐中具有特定角色

      时间:2023-09-09

        • <bdo id='NEGeD'></bdo><ul id='NEGeD'></ul>
          • <tfoot id='NEGeD'></tfoot>
            • <small id='NEGeD'></small><noframes id='NEGeD'>

                <tbody id='NEGeD'></tbody>

            • <i id='NEGeD'><tr id='NEGeD'><dt id='NEGeD'><q id='NEGeD'><span id='NEGeD'><b id='NEGeD'><form id='NEGeD'><ins id='NEGeD'></ins><ul id='NEGeD'></ul><sub id='NEGeD'></sub></form><legend id='NEGeD'></legend><bdo id='NEGeD'><pre id='NEGeD'><center id='NEGeD'></center></pre></bdo></b><th id='NEGeD'></th></span></q></dt></tr></i><div id='NEGeD'><tfoot id='NEGeD'></tfoot><dl id='NEGeD'><fieldset id='NEGeD'></fieldset></dl></div>
                <legend id='NEGeD'><style id='NEGeD'><dir id='NEGeD'><q id='NEGeD'></q></dir></style></legend>
                本文介绍了如何检查用户是否在不和谐中具有特定角色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                这应该检查特定的人是否具有静音角色

                This should check if the specific person does or doesn't have the mute role

                    @bot.command(pass_context=True)
                    @commands.has_role("Admin")
                    async def unmute(ctx, user: discord.Member):
                        role = discord.utils.find(lambda r: r.name == 'Member', 
                    ctx.message.server.roles)
                        if user.has_role(role):
                            await bot.say("{} is not muted".format(user))
                        else:
                            await bot.add_roles(user, role)
                

                抛出此错误

                命令引发异常:AttributeError: 'Member' object has no attribute 'has_role'

                Command raised an exception: AttributeError: 'Member' object has no attribute 'has_role'

                我不知道该怎么做,所以我非常感谢我能得到的每一个帮助

                I don't know how to do it so i would really appreciate every help I can get

                推荐答案

                成员没有 .has_role() 方法,但是您可以使用 获取他们所有角色的列表.角色.

                Member does not have a .has_role() method, you can however get a list of all their roles using .roles.

                要查看用户是否具有给定角色,我们可以使用 role in user.roles.

                To see if a user has a given role we can use role in user.roles.

                    @bot.command(pass_context=True)
                    @commands.has_role("Admin")
                    async def unmute(ctx, user: discord.Member):
                        role = discord.utils.find(lambda r: r.name == 'Member', ctx.message.guild.roles)
                        if role in user.roles:
                            await bot.say("{} is not muted".format(user))
                        else:
                            await bot.add_roles(user, role)
                

                参考文档:https://discordpy.readthedocs.io/en/最新/api.html#member

                注意: ctx.message.guild.roles 使用 ctx.message.server.roles.由于 API 更改而更新.

                Note: ctx.message.guild.roles use to be ctx.message.server.roles. Updated due to API change.

                这篇关于如何检查用户是否在不和谐中具有特定角色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:获取所有成员 discord.py 下一篇:如何修复运行时错误:无法关闭正在运行的事件循

                相关文章

                最新文章

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

                    <tfoot id='RSdMy'></tfoot>
                  1. <small id='RSdMy'></small><noframes id='RSdMy'>

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