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

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

    1. <tfoot id='mcQuw'></tfoot>
          <bdo id='mcQuw'></bdo><ul id='mcQuw'></ul>

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

        如何制作一个在 Python 中提供角色的不和谐机器人

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

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

              • <legend id='tL741'><style id='tL741'><dir id='tL741'><q id='tL741'></q></dir></style></legend>

                  <bdo id='tL741'></bdo><ul id='tL741'></ul>
                  <tfoot id='tL741'></tfoot>
                • <i id='tL741'><tr id='tL741'><dt id='tL741'><q id='tL741'><span id='tL741'><b id='tL741'><form id='tL741'><ins id='tL741'></ins><ul id='tL741'></ul><sub id='tL741'></sub></form><legend id='tL741'></legend><bdo id='tL741'><pre id='tL741'><center id='tL741'></center></pre></bdo></b><th id='tL741'></th></span></q></dt></tr></i><div id='tL741'><tfoot id='tL741'></tfoot><dl id='tL741'><fieldset id='tL741'></fieldset></dl></div>
                • 本文介绍了如何制作一个在 Python 中提供角色的不和谐机器人?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我想创建一个 Discord 机器人,在 Python 中为成员分配角色.

                  I want to create a discord bot that gives roles to members in Python.

                  我试过了:

                  @async def on_message(message):
                       if message.content == "give me admin"
                             role = discord.utils.get(server.roles, name="Admin")
                             await client.add_roles(message.author.id, role)
                  

                  推荐答案

                  import discord
                  from discord.utils import get
                  
                  client = discord.Client()
                  
                  @client.event
                  async def on_message(message):
                      if message.author == client.user:
                          return
                      if message.content == 'give me admin':
                          role = get(message.server.roles, name='Admin')
                          await client.add_roles(message.author, role)
                  

                  我认为这应该可行.discord.py 的文档是这里.

                  I think this should work. The documentation for discord.py is here.

                  你也可以使用 discord.ext.commands 扩展:

                  You could also use the discord.ext.commands extension:

                  from discord.ext.commands import Bot
                  import discord
                  
                  bot = Bot(command_prefix='!')
                  
                  @bot.command(pass_context=True)
                  async def addrole(ctx, role: discord.Role, member: discord.Member=None):
                      member = member or ctx.message.author
                      await client.add_roles(member, role)
                  
                  bot.run("token")
                  

                  这篇关于如何制作一个在 Python 中提供角色的不和谐机器人?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:Discord 机器人没有响应命令 下一篇:没有了

                  相关文章

                  最新文章

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

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

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

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