即使调用“message.channel.send”等待,Bot 也没有响应。怎么了?

时间:2021-05-19 23:06:00

标签: discord.py

我这几天一直在做的这个 discord.py 项目给我带来的只是麻烦。在这里说明问题所在。基本上整个应用程序都没有响应,即使启用了每个 await 和每个意图(在 commands.Bot main.py 上,这只是一个扩展)。我已经尝试了所有可能的解决方案。我尝试重新键入字典的键和值。我什至删除了嵌入的消息并用普通的字符串消息替换它们。而我仍然一无所获。这是“问题”的一小部分。无论如何,如果我能得到一些帮助,我会很感激吗?

@commands.Cog.listener()
async def on_message(self, message, member:discord.Member=None):
  ARI=discord.utils.get(message.guild.roles,name=teamnames['ARI'])
  ATL=discord.utils.get(message.guild.roles,name=teamnames['ATL'])
  if message.content.startswith('<:ARI:844709003871387648> sign'):
    member = message.mentions[0]
    if ARI or ATL in member.roles:
      embed=discord.Embed(title="Signing Failed", description=f"**{member.mention} Wasnt Signed due to there being another team role in that users role. If this is incorrect, have this user either: \nAsk for Release or Demand from the team that they are currently roled as. . .**")
      await message.channel.send(embed=embed)
    else:
      embed=discord.Embed(title="Signing Transaction", description=f"**{member.mention} Was Signed to the <:ARI:844709003871387648> as the **`{len(ARI.members)}`** Player Signed Accordingly. If this was an error use command: <:ARI:844709003871387648> **`Release @user.mention`** To release the player of your initially signed roster.")
      await member.add_roles(ARI)
      await message.channel.send(embed=embed)

2 个答案:

答案 0 :(得分:0)

通过恢复到字典键和值解决了这个问题,但现在显示了一个新错误。机器人仍然出于某种原因没有响应?下面的片段:

@commands.Cog.listener()
@commands.has_any_role('Franchise Owner', 'General Manager', 'Head Coach')
async def on_message(self, message):
  if 'have signed' in message.content:
    member = message.mentions[0]
    teamemojis = ["ARI", "ATL", "BAL", "BUF", "CAR", "CHI", "CIN", "CLE"]
    teamsids = [784827425422573608, 784827426093793330, 784827440324804639, 784827439221047317, 784827427029385246, 784827427796025364, 784827441205477386, 784827442174623745,]
    teams=[]
    if teamsids.id in teamsids:
      teams.append(teamsids.id)
      step2=str(teams)
      step3=step2.replace("[","")
      step4=step3.replace("]","")
      print(step4)
      step5=teamsids.index(int(step4))
      print(step5)
      emote=discord.utils.get(message.guild.emojis,name=teamemojis[step5])
      team = discord.utils.get(message.guild.roles,id=int(step4))
      pass
      if team not in message.author.roles:
        print('return')
        return
      elif team in message.author.roles:
        print('pass')
        pass
        if team not in member.roles:
          for role in message.author.roles:
            role.name == team.name
            await member.add_roles(role, reason="Signed by the Bot!")
            embed=discord.Embed(title="Signing Transaction", description=f"**{member.mention} Was Signed to the {str(emote)} accordingly. If this was a mistake, please refer to the `have released` Command in the bot commands**")
            embed.set_thumbnail(url=emote.url)
            await message.channel.send(embed=embed)
        elif team in member.roles:
          await message.channel.send("**Cannot sign this user, as this user is already signed!**")
          return

答案 1 :(得分:0)

对于 on_message 事件。在此处阅读文档:https://discordpy.readthedocs.io/en/stable/faq.html#why-does-on-message-make-my-commands-stop-working

添加行:

await bot.process_commands(message)

on_message 事件底部应使其再次正常运行