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

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

      1. <tfoot id='fxizD'></tfoot>

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

        Python discord.py 阅读全文

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

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

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

                3. 本文介绍了Python discord.py 阅读全文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在使用 discord.py 来制作 discord 机器人.我想在用户提到的两个数字之间生成一个随机数.因此,如果用户键入 %rand 1 9,我希望机器人返回 1 到 9 之间的随机整数,比如 4.到目前为止,这是我的代码:

                  I am using discord.py to make a discord bot. I would like to generate a random number between 2 numbers mentioned by the user. So if the user types %rand 1 9, I would like the bot to return with a random integer between 1 and 9, so say 4. Here is my code so far:

                  async def on_message(message):
                      x = str(1)
                      y = str(2)
                      if message.content.startswith('%rand ' + x + y):
                          NumberX = int(x)
                          NumberY = int(y)
                          msg = "Random Number Is: " + str(random.randint(NumberX,NumberY))
                          await client.send_message(message.channel, msg)
                  

                  但是,它不起作用.我不太明白我哪里出错了.我在其他任何地方都找不到其他解决方案.我想我需要强制机器人阅读完整的消息或类似的东西.任何帮助将不胜感激.提前谢谢你.

                  However, it doesn't work. I don't quite understand where I am going wrong. I couldn't find another solution anywhere else. I assume I need to force the bot to read the full message or something similar. Any help will be appreciated. Thank you in advance.

                  推荐答案

                  问题在于您的 if 语句从未真正触发过.您正在检查它是否以%rand 12"开头,这不是您想要的.你的代码应该是这样的:

                  The problem comes from the fact that your if statement is never actually triggered. You are checking whether it starts with "%rand 12" which is not what you are looking for. Here's how your code should look:

                  async def on_message(message):
                      if message.content.startswith('%rand '):
                          vals = message.content.split(" ")
                          NumberX = int(vals[1])
                          NumberY = int(vals[2])
                          msg = "Random Number Is: " + str(random.randint(NumberX,NumberY))
                          await client.send_message(message.channel, msg)
                  

                  另外,不要忘记 import random 以使用该功能.

                  Also, don't forget to import random in order to use that function.

                  这篇关于Python discord.py 阅读全文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:在 discord.py 中访问成员的横幅 下一篇:discord.py 中的提醒命令问题

                  相关文章

                  最新文章

                    <bdo id='NK5bb'></bdo><ul id='NK5bb'></ul>

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

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

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