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

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

        <tfoot id='JMDjO'></tfoot>
      1. 猜谜游戏,discord.py 机器人

        时间:2023-09-09

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

            <small id='9ij4S'></small><noframes id='9ij4S'>

          1. <tfoot id='9ij4S'></tfoot>
              <bdo id='9ij4S'></bdo><ul id='9ij4S'></ul>

                  <tbody id='9ij4S'></tbody>

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

                  本文介绍了猜谜游戏,discord.py 机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在尝试制作一个不和谐的机器人猜谜游戏(使用 python),但它一直失败.我查看了许多类似的帖子,但没有发现任何帮助.

                  Im trying to make a discord bot guessing game (using python) but it keeps failing. I have looked at many similar posts and haven't found anything that helps.

                  @bot.command(name='play')
                  async def play(ctx):
                    number = random.randint(1,100)
                    await ctx.send('I have a number in mind between 1 and 100, guess')
                    for i in range(0,5):
                      guess = await client.wait_for('message') **(see below the code)
                          if guess.content == number:
                            await ctx.send('You got it!')
                          elif guess.content < number:
                            await ctx.send('Higher!')
                          elif guess.content > number:
                            await ctx.send('Lower!')
                        else:
                          await ctx.send("You lost, type $play to play again.")
                  

                  ** 通常它会说: , check=check,但这似乎不起作用,它说,检查未定义或类似的东西

                  ** normaly it would say: , check=check, but that doesnt seem to work, it says, check not defined or something like that

                  代码似乎卡在:for i in range(0,5):,或:guess = await client.wait_for('message')

                  有人可以帮忙吗?或者发布一个有效的猜谜游戏+解释?

                  could someone help?, or post a guessing game that works + explanation?

                  推荐答案

                  正如评论中提到的,你需要包含你自己的check.如下所示:

                  As mentioned in the comments, you need to include your own check. This looks like the following:

                      def check(m):
                          return m.author == ctx.author and m.channel == ctx.message.channel
                  

                  这确保只有来自命令作者的消息被识别和接受.我们将其包含在代码中.

                  This ensures that only the message from the author of the command is recognized and accepted. We include this in the code.

                  另外,你不能使用 </>number,你会得到如下错误:

                  Also, you can't use </> number, you will get the following error:

                  TypeError: '<' not supported between instances of 'str' and 'int'.
                  

                  要解决这个问题,只需将 number 更改为 str:

                  To fix this, simply change number to a str:

                  </> str(number)
                  

                  可能的代码是:

                  @bot.command(name='play')
                  async def play(ctx):
                      def check(m):
                          return m.author == ctx.author and m.channel == ctx.message.channel
                  
                      number = random.randint(1, 100)
                      await ctx.send('I have a number in mind between 1 and 100, guess')
                  
                      for i in range(0, 5):
                          guess = await bot.wait_for('message', check=check)
                  
                          if guess.content == number:
                              await ctx.send('You got it!')
                  
                          elif guess.content < str(number):
                              await ctx.send('Higher!')
                  
                          elif guess.content > str(number):
                              await ctx.send('Lower!')
                  
                          else:
                              return # Or something else
                          
                      else:
                          await ctx.send("You lost, type $play to play again.")
                  

                  这篇关于猜谜游戏,discord.py 机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:在 message.guild.get_member_named("member_name") 中 下一篇:如何在没有命令的情况下使用 discord.py 发送消息

                  相关文章

                  最新文章

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

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

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