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

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

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

      1. get_user(id) 找不到用户 - 返回无(self bot discord.py)

        时间:2023-09-09

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

              <bdo id='GN6nI'></bdo><ul id='GN6nI'></ul>
                  <tbody id='GN6nI'></tbody>

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

                  <tfoot id='GN6nI'></tfoot>
                • 本文介绍了get_user(id) 找不到用户 - 返回无(self bot discord.py)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在尝试使用自我机器人与自己联系.我正在尝试在我的代码中使用 get_user() 函数.

                  I am trying to DM myself using a self bot. I am trying to use the get_user() function in my code.

                  bot = commands.Bot(command_prefix='', self_bot=True)
                  
                  counter = 0
                  userID = 695724603406024726
                  
                  @bot.event
                  async def dm(userID):
                      print('Running Function')
                      global counter
                  
                      if counter <= 0:
                          print('Finding user.')
                          counter += 1
                  
                          user = bot.get_user(userID)
                  
                          print('user:',user)
                  
                          await user.send("Hello")
                          print('message sent')
                  
                      return
                  
                  
                  bot.loop.create_task(dm(userID))
                  bot.run(token, bot=False)
                  

                  相反,我返回此错误:

                    File "<ipython-input-1-90e5e962a6e9>", line 24, in dm
                      await user.send("Hello")
                  AttributeError: 'NoneType' object has no attribute 'send'
                  

                  机器人找不到用户并返回 None 值.我已经测试了多个 ID,但不确定是什么问题.

                  The bot can't find the user and returns a None value. I have tested multiple ID's and am unsure what the problem is.

                  推荐答案

                  你总是可以使用协程 client.fetch_user(id) 来完成它.get_user() 从缓存中获取它,所以当新鲜时,大多数时候都不起作用.

                  You could always use the coroutine client.fetch_user(id) to get it done. get_user() takes it from cache so when fresh, doesn't work most of the times.

                  在你的情况下:

                  bot = commands.Bot(command_prefix='', self_bot=True)
                  
                  counter = 0
                  userID = 695724603406024726
                  
                  async def dm(userID):
                      print('Running Function')
                      global counter
                  
                      if counter <= 0:
                          print('Finding user.')
                          counter += 1
                  
                          user = await bot.fetch_user(userID)
                  
                          print('user:',user)
                  
                          await user.send("Hello")
                          print('message sent')
                  
                      return
                  
                  
                  bot.loop.create_task(dm(userID))
                  bot.run(token, bot=False)```
                  

                  这篇关于get_user(id) 找不到用户 - 返回无(self bot discord.py)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:discord.py emoji 所有服务器机器人 下一篇:如何在 discord.py cogs 中创建别名?

                  相关文章

                  最新文章

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

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

                      <tfoot id='xEj92'></tfoot>

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