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

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

        如何创建一个简单的机器人来自动响应包含某个

        时间:2023-09-09
        <tfoot id='ICVSr'></tfoot>
          • <legend id='ICVSr'><style id='ICVSr'><dir id='ICVSr'><q id='ICVSr'></q></dir></style></legend>

            • <bdo id='ICVSr'></bdo><ul id='ICVSr'></ul>

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

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

                  本文介绍了如何创建一个简单的机器人来自动响应包含某个触发语句的消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在为我和我的朋友设置一个 Discord 服务器,我需要一个能够对输入了某个触发短语的任何消息添加 20 条反应的机器人.我曾经有一个机器人可以做到这一点,但它已经更新并限制为 3 个反应,这对我不起作用.

                  I'm setting up a Discord server for me and my friends, and I'm in need of a bot able to add 20 reactions to any message in which a certain trigger phrase was typed. I used to have a bot that could do that, but it has been updated and limited to 3 reactions, which isn't working for me.

                  所以我在这里,以我对编程的非常基本的了解,试图为这个唯一目的设置一个非常基本的机器人.

                  So here I am, with my very basic understanding of programming, trying to setup a very basic bot for that sole purpose.

                  我已经尝试过在 YT 上找到的一个简单的机器人提议,但它根本不起作用,我不知道为什么以及如何解决它.

                  I already tried a simple bot proposition found on YT, but it didn't work at all, and I'm at a loss to know why and how to fix it.

                  所以这是我尝试过但没有成功的提议:

                  So this was the proposition I tried and didn't manage to make functional:

                  import discord
                  from discord.ext    import commands
                  from discord.ext.commands   import Bot
                  import asyncio
                  
                  bot = commands.Bot(command_prefix='!')
                  
                  @bot.event
                  async def on_ready():
                      print ("Ready to react, boss !")
                  
                  
                  @bot.event
                  async def on_message(message):
                      if(message.channel.id == "550373218758688790"):
                          await bot.add_reaction(message, ":war_tank:552569109108490252")
                  
                  
                  bot.run("NTY5OTQ0NTMyMzIyNjE1MzI2.XL4IBg.WH-Ms1DWKJN8qGBBLAxdGye0q2I")
                  

                  所以这个应该对每条消息做出反应,我打算从那里开始工作,但它甚至没有用.相反,我在每条消息的 cmd 日志中都收到一条消息,看起来像这样:

                  So this one was supposed to react to every message with a reaction, and I was planning on working from there, but it didn't even work. Instead, I got a message in the cmd log for each message and that looked like this:

                  Ignoring exception in on_message
                  Traceback (most recent call last):
                    File "G:JeuxDiscord Botlibsite-packagesdiscordclient.py", line 255, in _run_event
                      await coro(*args, **kwargs)
                    File "G:BureauTotemReact Botot.py", line 16, in on_message
                      await bot.add_reaction(message, ":war_tank:552569109108490252")
                  AttributeError: 'Bot' object has no attribute 'add_reaction'
                  

                  因此,如果任何有实际技能的人(考虑到我的技能,我会很容易留下深刻印象)能给我指明正确的方向,我会非常高兴.

                  So if anyone with actual skills (considering mine, I will be easily impressed) can point me in the right direction, I will be more than happy.

                  感谢您的时间和关注.

                  推荐答案

                  您正在查看旧教程.Client.add_reaction 已移至 <代码>Message.add_reaction 在 discord.py 1.0

                  You're looking at old tutorials. Client.add_reaction was moved to Message.add_reaction in discord.py 1.0

                  您描述的功能可能类似于:

                  The functionality you describe could look something like:

                  default_emojis = [
                      "N{GRINNING FACE}",
                      "N{KEYCAP DIGIT ONE}"
                  ]
                  
                  custom_emojis = [
                      "war_tank"
                  ]
                  
                  async def react(message):
                      for emoji in default_emojis:
                          await message.add_reaction(emoji)
                      for emoji in message.guild.emojis:
                          if emoji.name in custom_emojis:
                              await message.add_reaction(emoji)
                  
                  @bot.event
                  async def on_message(message):
                      if message.author == bot.user:
                          return
                      if "react to me" in message.content.lower():
                          await react(message)
                  

                  这篇关于如何创建一个简单的机器人来自动响应包含某个触发语句的消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:捕获 CommandOnCooldown 错误 下一篇:由于“错误请求"而未发送消息与不和谐.py

                  相关文章

                  最新文章

                    <bdo id='qCBR4'></bdo><ul id='qCBR4'></ul>
                1. <small id='qCBR4'></small><noframes id='qCBR4'>

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