• <tfoot id='gcoBa'></tfoot>

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

    2. <small id='gcoBa'></small><noframes id='gcoBa'>

        有没有办法检查固定的消息,并且只使用 discor

        时间:2023-10-10

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

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

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

                  <tbody id='dKkSq'></tbody>

                • 本文介绍了有没有办法检查固定的消息,并且只使用 discord.py 清除某些成员的消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我想制作一个类似于 Dyne 的清除命令,您可以在其中输入一个用户,它不会清除固定的,只有用户的消息(如果您输入一个用户).我试过做一个单独的检查功能,但它不会清除任何东西.我没有收到任何错误,只是不会清除.

                  I want to make a purge command similar to Dyne's, where you can input a user, and it doesn't purge pinned, only the user's messages (if you input a user). I've tried making a seperate check function, but it doesn't purge anything. I get no error, it just won't purge.

                  @commands.command()
                      @commands.has_permissions(manage_messages=True)
                      async def purge(self, ctx, user: discord.Member = None, num: int = 10000):
                          if user:
                              def check_func(user: discord.Member, message: discord.Message):
                                  return not msg.pinned
                                  return user.id
                              await ctx.message.delete()
                              await ctx.channel.purge(limit=num, check=check_func)
                              verycool = await ctx.send(f'{num} messages deleted.')
                              await verycool.delete()
                  
                          else:
                              await ctx.message.delete()
                              await ctx.channel.purge(limit=num, check=lambda msg: not msg.pinned)
                              verycool = await ctx.send(f'{num} messages deleted.')
                              await verycool.delete()
                  
                  

                  我在服务器上有管理消息的权限.有谁知道如何使 check_func 正常工作?

                  I have manage messages permissions on the server. Does anyone know how to make the check_func work properly?

                  推荐答案

                  我所做的更改应该可以解决您的问题以及其他一些问题.

                  The changes I have made should solve your issue as well as deal with a few other issues.

                  @commands.command()
                  @commands.has_permissions(manage_messages=True)
                  async def purge(self, ctx, num: int = None, user: discord.Member = None):
                      if user:
                          check_func = lambda msg: msg.author == user and not msg.pinned
                      else:
                          check_func = lambda msg: not msg.pinned
                  
                      await ctx.message.delete()
                      await ctx.channel.purge(limit=num, check=check_func)
                      await ctx.send(f'{num} messages deleted.', delete_after=5)
                  

                  仅根据参数更改函数看起来更好,效率更高,否则您会重复代码.此外,您最后发送的消息立即被有效删除.channel.send 有一个参数 delete_after 会在给定的秒数后自动删除一条消息.还有一些我没有提到的其他语法问题,比如 check 函数只接受一个参数,但你解析了两个我也修复了.从技术上讲,PEP8 禁止将 lambda 存储在变量中,但我认为这是可以原谅的.

                  Just changing the function based on the arguments looks better and is more efficient as otherwise you have duplicated code. Furthermore, the message you send at the end was being deleted effectively immediately. channel.send has an argument delete_after which will automatically deletes a message after a given amount of seconds. There are a few other syntax issue I haven't mentioned such as the check function only taking one argument but you parsing two which I have also fixed. Technically PEP8 prohibits storing lambda's in variables but I think this could be excused.

                  编辑:您可以执行类似检查 num == "*" 之类的操作,如果是则删除所有消息.

                  Edit: you could do something like check if num == "*" and delete all messages if it does.

                  这篇关于有没有办法检查固定的消息,并且只使用 discord.py 清除某些成员的消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:discord.py 检查是否有大规模加入(raid) 下一篇:如何防止用户在频道中发送多条消息?

                  相关文章

                  最新文章

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

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

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