• <small id='4KsGI'></small><noframes id='4KsGI'>

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

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

        <tfoot id='4KsGI'></tfoot>

        使用机器人 Discord.py 授予和删除角色

        时间:2023-10-10

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

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

                <tbody id='djp4y'></tbody>
                  <tfoot id='djp4y'></tfoot>

                  <i id='djp4y'><tr id='djp4y'><dt id='djp4y'><q id='djp4y'><span id='djp4y'><b id='djp4y'><form id='djp4y'><ins id='djp4y'></ins><ul id='djp4y'></ul><sub id='djp4y'></sub></form><legend id='djp4y'></legend><bdo id='djp4y'><pre id='djp4y'><center id='djp4y'></center></pre></bdo></b><th id='djp4y'></th></span></q></dt></tr></i><div id='djp4y'><tfoot id='djp4y'></tfoot><dl id='djp4y'><fieldset id='djp4y'></fieldset></dl></div>
                • 本文介绍了使用机器人 Discord.py 授予和删除角色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  如何在 Discord.py 中创建一个机器人,该机器人将分配 role.json 文件中存在的角色,同时使用相同的命令来删除和添加相同的角色.例如,?role 将添加和删除角色,具体取决于用户是否分配了角色.我对如何实现这一点有点困惑.

                  How do I make a bot in Discord.py that will assign roles present in a role.json file, while using the same command to both remove and add the same role. For example, ?role <rolename> will both add and remove a role, depending on if the user has the role assigned. I'm a bit confused on how to achieve this.

                  我当前的机器人使用 ?roleadd <rolename> ?roleremove <rolename>.

                  My current bot uses ?roleadd <rolename> ?roleremove <rolename>.

                  推荐答案

                  我不确定你的 role.json 文件在哪里发挥作用,但我将如何实现这样的命令

                  I'm not sure where your role.json file comes into play, but here's how I would implement such a command

                  @bot.command(name="role")
                  async def _role(ctx, role: discord.Role):
                      if role in ctx.author.roles:
                          await ctx.author.remove_roles(role)
                      else:
                          await ctx.author.add_roles(role)
                  

                  这使用 Role 转换器 自动从 role 对象的名称、id 或提及中解析.

                  This uses the Role converter to automatically resolve the role object from its name, id, or mention.

                  这篇关于使用机器人 Discord.py 授予和删除角色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何让不和谐的机器人加你为朋友 下一篇:使用 Python Discord 机器人删除消息?

                  相关文章

                  最新文章

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

                    • <bdo id='d7Mvs'></bdo><ul id='d7Mvs'></ul>

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

                    <legend id='d7Mvs'><style id='d7Mvs'><dir id='d7Mvs'><q id='d7Mvs'></q></dir></style></legend>
                  1. <tfoot id='d7Mvs'></tfoot>