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

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

        • <bdo id='9svH4'></bdo><ul id='9svH4'></ul>

        Bot前缀中的空格

        Space in the Bot Prefix(Bot前缀中的空格)

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

      1. <tfoot id='OZvwK'></tfoot>

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

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

                • <bdo id='OZvwK'></bdo><ul id='OZvwK'></ul>
                    <tbody id='OZvwK'></tbody>
                  本文介绍了Bot前缀中的空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  是否可以在服务器的前缀中留出一个空格,因为我想,这样用户就可以ping我的机器人作为前缀 前缀应为: <;@bot.id>;<;-(ping后带空格) 我怎么才能做这个呢? 我的代码是:

                  def get_prefix(client, message):
                  try:
                      with open('./rsc/databases/prefixes.json', 'r') as f:
                          prefixes = json.load(f)
                  
                      if str(message.guild.id) in prefixes:
                          prefix = prefixes[str(message.guild.id)]
                          return [str(prefix), '<@!801443216595353642>', "<@!801443216595353642> "]
                      else:
                          return ["!", '<@!801443216595353642>', "<@!801443216595353642> "]
                  except:
                      return ["!", '<@!801443216595353642>', "<@!801443216595353642> "]
                  

                  如果我没有在服务器名称后加空格,它可以工作,但空格不是:/

                  因为如果您使用TAB完成ping,它会自动设置空格:/,这样机器人就不会收到命令.

                  推荐答案

                  更新

                  您可以在创建机器人时使用commands.when_mentioned_or

                  from discord.ext import commands
                  
                  bot_prefix = commands.when_mentioned_or('!')
                  
                  bot=commands.Bot(command_prefix=bot_prefix)
                  
                  @bot.command()
                  async def ping(ctx):
                      await ctx.send('Pong')
                  
                  @bot.event
                  async def on_message(message):
                      await bot.process_commands(message)
                  
                  bot.run('token')
                  

                  旧方法

                  您可以检查on_message事件中的每条消息,并在处理命令之前将bot提及更改为命令前缀。这是通过检查message.content的开头来完成的,如果它与'<@!botid> '匹配,请将其替换为bot前缀。

                  from discord.ext import commands
                  
                  bot_prefix = '!'
                  
                  bot=commands.Bot(command_prefix=bot_prefix)
                  
                  @bot.command()
                  async def ping(ctx):
                      await ctx.send('Pong')
                  
                  @bot.event
                  async def on_message(message):
                      bot_mention_str = bot.user.mention.replace('@', '@!') + ' '
                      bot_mention_len = len(bot_mention_str)
                  
                      if message.content[:bot_mention_len] == bot_mention_str:
                          message.content = bot_prefix + message.content[bot_mention_len:]
                          await bot.process_commands(message)
                      else:
                          await bot.process_commands(message)
                  
                  bot.run('token')
                  

                  这篇关于Bot前缀中的空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  groupby multiple coords along a single dimension in xarray(在xarray中按单个维度的多个坐标分组)
                  Group by and Sum in Pandas without losing columns(Pandas中的GROUP BY AND SUM不丢失列)
                  Group by + New Column + Grab value former row based on conditionals(GROUP BY+新列+基于条件的前一行抓取值)
                  Groupby and interpolate in Pandas(PANDA中的Groupby算法和插值算法)
                  Pandas - Group Rows based on a column and replace NaN with non-null values(PANAS-基于列对行进行分组,并将NaN替换为非空值)
                  Grouping pandas DataFrame by 10 minute intervals(按10分钟间隔对 pandas 数据帧进行分组)

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

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

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

                              <tbody id='IWTYN'></tbody>