• <small id='3OAhP'></small><noframes id='3OAhP'>

      <tfoot id='3OAhP'></tfoot>

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

        Discord.py 狙击命令

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

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

                <bdo id='fVb8G'></bdo><ul id='fVb8G'></ul>
                1. <legend id='fVb8G'><style id='fVb8G'><dir id='fVb8G'><q id='fVb8G'></q></dir></style></legend>
                  本文介绍了Discord.py 狙击命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我试图在机器人狙击"的地方发出命令.最后删除的消息.这是我当前的代码:

                  Im trying to make a command where the bot "snipes" the last deleted message. this is my current code:

                  
                  snipe_message_content = None
                  snipe_message_author = None
                  
                  @client.event
                  async def on_message_delete(message):
                      snipe_message_author.remove(None)
                      snipe_message_content.remove(None)
                      snipe_message_content.append(message.content) 
                      snipe_message_author.append(message.author.id) 
                      await asyncio.sleep(str(60))
                      snipe_message_author.remove(message.author.id)
                      snipe_message_content.remove(message.content)
                      
                  
                  @client.command()
                  async def snipe(message):
                      if snipe_message_content==None:
                          await message.channel.send("Theres nothing to snipe.")
                      else:
                          embed = discord.Embed(description=f"{snipe_message_content}")
                          embed.set_footer(text=f"Asked by {message.author.name}#{message.author.discriminator}", icon_url=message.author.avatar_url)
                          embed.set_author(name= f"<@{snipe_message_author}>")
                          await message.channel.send(embed=embed)
                          return
                  
                  

                  await message.channel.send("Theres nothing to snip.") 部分可以正常工作,但其余部分无法正常工作.有人可以帮忙吗?

                  the await message.channel.send("Theres nothing to snipe.") part works perfectly fine, but the rest wont work. Can anyone help?

                  推荐答案

                  你的 on_message_delete() 函数只是不工作.

                  Well your on_message_delete() function is just not working.

                  我会将您的变量缩短为 smc (snipe_message_content) 和 sma (snipe_message_author).

                  I'll shorten your variables as smc (snipe_message_content) and sma (snipe_message_author).

                  首先,你的变量 smasmc 的类型是 None,但是方法 removeappendlist 类型的一部分,所以你必须声明列表

                  First of all, your variables sma and smc are of the type None, but the methods remove and append are part of the type list, so you'd have to declare lists

                  smc = []
                  sma = []
                  

                  为了让他们工作.

                  不过,无论如何您都不必这样做.只需给您当前的变量一个新值:

                  Still, you wouldn't have to do this anyway. Just give your current variables a new value:

                  snipe_message_content = None
                  snipe_message_author = None
                  
                  @client.event
                  async def on_message_delete(message):
                  
                      global snipe_message_content
                      global snipe_message_author
                      # Variables outside a function have to be declared as global in order to be changed
                  
                      snipe_message_content = message.content
                      snipe_message_author = message.author.id
                      await asyncio.sleep(60)
                      snipe_message_author = None
                      snipe_message_content = None
                  

                  此外,您不应将 60 转换为字符串.time.sleepasyncio.sleep 都需要一个 integer 才能工作.(顺便说一句,如果你想让 60 成为一个字符串,只需将 60" 写成带引号.

                  Also, you should not convert 60 to a string. time.sleep and asyncio.sleep both need an integer in order to work. (And by the way, if you wanted 60 to be a string, just write "60" with quotation marks.

                  另外,请注意以下情况:如果一条消息被删除,但在新消息被删除 50 秒后,smasmc 将分配给新消息.但是 10 秒后,之前消息执行的函数会将 smasmc 的值设置为 None.

                  Also, be careful of the following case: If a message gets deleted, but 50 seconds after a new message gets deleted, sma and smc would be assigned to the new message. But 10 seconds later, the function executed by the message before would set he value of sma and smc to None.

                  因此,在 await asyncio.sleep(60) 之后检查您的消息是否仍然与之前相同:

                  Therefore, after await asyncio.sleep(60) check wether your message is still the same as before:

                  snipe_message_content = None
                  snipe_message_author = None
                  snipe_message_id = None
                  
                  @client.event
                  async def on_message_delete(message):
                  
                      global snipe_message_content
                      global snipe_message_author
                      global snipe_message_id
                  
                      snipe_message_content = message.content
                      snipe_message_author = message.author.id
                      snipe_message_id = message.id
                      await asyncio.sleep(60)
                  
                      if message.id == snipe_message_id:
                          snipe_message_author = None
                          snipe_message_content = None
                          snipe_message_id = None
                  

                  这篇关于Discord.py 狙击命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:使用 tweepy 和 discord.py 将推文发布到特定频道 下一篇:Python - 在用户加入时发送消息

                  相关文章

                  最新文章

                2. <small id='90da6'></small><noframes id='90da6'>

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