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

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

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

        使用 discord.py 访问命令之间的变量

        时间:2023-09-09
      1. <legend id='IYtV0'><style id='IYtV0'><dir id='IYtV0'><q id='IYtV0'></q></dir></style></legend>
          <tbody id='IYtV0'></tbody>
          <bdo id='IYtV0'></bdo><ul id='IYtV0'></ul>
          <tfoot id='IYtV0'></tfoot>

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

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

                1. 本文介绍了使用 discord.py 访问命令之间的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我有这个(过于简化的)Discord 机器人

                  I have this (overly simplified) Discord bot

                  voting_enabled = False
                  
                  @bot.command()
                  async def start():
                      voting_enabled = True
                  
                  @bot.command()
                  async def finish():
                      voting_enabled = False
                  
                  @bot.command()
                  async def vote():
                      if voting_enabled:
                          # Do something
                      else:
                          # Do something else
                  

                  问题

                  当我调用 vote() 命令时,它总是通过代码的 else 部分.即使调用了 start() 命令

                  The problem

                  When I call call the vote() command, it always goes through the else part of the code. Even after calling the start() command

                  我希望 vote() 命令的行为有所不同,具体取决于之前调用的其他两个命令是否

                  I want that the vote() command behave differently depending on if the other two commands where called previously

                  我尝试在第一行像这样使用 global 关键字

                  I tried using the global keyword like this on the first line

                  global voting_enabled
                  voting_enabled = False
                  

                  但它什么也没做

                  推荐答案

                  global 关键字使用不正确.

                  global 应该在每个函数中定义.

                  global should be defined within every function.

                  例子:

                  voting_enabled = False
                  
                  @bot.command()
                  async def start():
                      global voting_enabled
                  
                      voting_enabled = True
                  
                  @bot.command()
                  async def finish():
                      global voting_enabled
                  
                      voting_enabled = False
                  
                  @bot.command()
                  async def vote():
                      global voting_enabled
                  
                      if voting_enabled:
                          # Do something
                      else:
                          # Do something else
                  

                  这篇关于使用 discord.py 访问命令之间的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:discord.py 循环导入(AttributeError:部分初始化模块& 下一篇:使用 discord.py 进行反应检查

                  相关文章

                  最新文章

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

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

                    <tfoot id='QwAPX'></tfoot>
                    <legend id='QwAPX'><style id='QwAPX'><dir id='QwAPX'><q id='QwAPX'></q></dir></style></legend>