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

        <tfoot id='iF0jV'></tfoot>
          <bdo id='iF0jV'></bdo><ul id='iF0jV'></ul>

      2. Discord.py 静音命令

        时间:2023-09-09

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

                  <tbody id='R25I5'></tbody>

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

                <i id='R25I5'><tr id='R25I5'><dt id='R25I5'><q id='R25I5'><span id='R25I5'><b id='R25I5'><form id='R25I5'><ins id='R25I5'></ins><ul id='R25I5'></ul><sub id='R25I5'></sub></form><legend id='R25I5'></legend><bdo id='R25I5'><pre id='R25I5'><center id='R25I5'></center></pre></bdo></b><th id='R25I5'></th></span></q></dt></tr></i><div id='R25I5'><tfoot id='R25I5'></tfoot><dl id='R25I5'><fieldset id='R25I5'></fieldset></dl></div>
                1. 本文介绍了Discord.py 静音命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我最近问了很多关于 discord.py 的问题,这就是其中之一.

                  I have been asking lots of questions lately about discord.py and this is one of them.

                  有时有些人会向您的不和谐服务器发送垃圾邮件,但踢或禁止他们似乎过于严厉.我想到了一个 silence 命令,它会在给定的时间内删除频道上的每条新消息.

                  Sometimes there are those times when some people spam your discord server but kicking or banning them seems too harsh. I had the idea for a silence command which would delete every new message on a channel for a given amount of time.

                  到目前为止我的代码是:

                  My code so far is:

                  @BSL.command(pass_context = True)
                  async def silence(ctx, lenghth = None):
                          if ctx.message.author.server_permissions.administrator or ctx.message.author.id == ownerID:
                               global silentMode
                               global silentChannel
                               silentChannel = ctx.message.channel
                               silentMode = True
                               lenghth = int(lenghth)
                               if lenghth != '':
                                    await asyncio.sleep(lenghth)
                                    silentMode = False
                               else:
                                    await asyncio.sleep(10)
                                    silentMode = False
                          else:
                               await BSL.send_message(ctx.message.channel, 'Sorry, you do not have the permissions to do that @{}!'.format(ctx.message.author))
                  

                  我的 on_message 部分中的代码是:

                  The code in my on_message section is:

                  if silentMode == True:
                          await BSL.delete_message(message)
                          if message.content.startswith('bsl;'):
                                  await BSL.process_commands(message)
                  

                  所有使用的变量都是在机器人顶部预定义的.

                  All the variables used are pre-defined at the top of the bot.

                  我的问题是机器人删除了它有权访问的所有频道中的所有新消息.我尝试将 if silentChannel == ctx.message.channel 放在 on_message 部分,但这使命令完全停止工作.

                  My problem is that the bot deletes all new messages in all channels which it has access to. I tried putting if silentChannel == ctx.message.channel in the on_message section but this made the command stop working completely.

                  非常感谢任何关于为什么会发生这种情况的建议.

                  Any suggestions as to why this is happening are much appreciated.

                  推荐答案

                  类似

                  silent_channels = set()
                  
                  @BSL.event
                  async def on_message(message):
                      if message.channel in silent_channels:
                          if not message.author.server_permissions.administrator and  message.author.id != ownerID:
                              await BSL.delete_message(message)
                              return
                      await BSL.process_commands(message)
                  
                  @BSL.command(pass_context=True)
                  async def silent(ctx, length=0): # Corrected spelling of length
                      if ctx.message.author.server_permissions.administrator or ctx.message.author.id == ownerID:
                          silent_channels.add(ctx.message.channel)
                          await BSL.say('Going silent.')
                          if length:
                              length = int(length)
                              await asyncio.sleep(length)
                              if ctx.message.channel not in silent_channels: # Woken manually
                                  return
                              silent_channels.discard(ctx.message.channel)
                              await BSL.say('Waking up.')
                  
                  @BSL.command(pass_context=True)
                  async def wake(ctx):
                      silent_channels.discard(ctx.message.channel)
                  

                  应该可以(我没有测试过,测试机器人很痛苦).搜索集合很快,因此对每条消息都进行搜索不会对您的资源造成真正的负担.

                  Should work (I haven't tested it, testing bots is a pain). Searching through sets is fast, so doing it for every message shouldn't be a real burden on your resources.

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

                  上一篇:如何获取对 discord.py 中的消息做出反应的成员列 下一篇:如何停止运行不和谐的机器人进程(python)

                  相关文章

                  最新文章

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

                      <legend id='NK8Wn'><style id='NK8Wn'><dir id='NK8Wn'><q id='NK8Wn'></q></dir></style></legend>
                    2. <tfoot id='NK8Wn'></tfoot>

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