【问题标题】:Invalid syntax in discord bot pythondiscord bot python中的语法无效
【发布时间】:2022-01-25 04:30:51
【问题描述】:

我在 python 中制作了一个不和谐的机器人,效果很好。但现在我想实现一个坏词过滤器。如果他或她说坏话,机器人会警告他。我也希望它被嵌入。错误在最后一行(即 await message.channel.send(embed=embedwarn)。它说语法无效,但我找不到。

#bad words for the bot to detect
bad_words = ["Word1", "Word2"]

#send person a warning message
@bot.event
async def on_message(message):

    if message.author == bot.user:
      return
    if any(word in message.content.lower() for word in bad_words):
      embedwarn=discord.Embed(title="Warning", description=f"Server: {member.name} \nReason: bad word")
      await message.channel.send(embed=embedwarn)

【问题讨论】:

  • 尝试使用discord.py 标签以获得更好的答案!另外,你能发送完整的错误信息吗?此外,对于您的坏词检测,请尝试if message.content.lower() in bad_words: 以获得更简洁的方法。
  • 每个 if 语句的缩进都不同
  • @Sayse 确实如此,但这不应该在最后一行给出无效的语法错误。如果我是对的?我使用的 if 语句很好。

标签: python discord discord.py


【解决方案1】:

这部分代码没有正确缩进。

if any(word in message.content.lower() for word in bad_words):
    embedwarn=discord.Embed(title="Warning", description=f"Server: {member.name} \nReason: bad word")
    await message.channel.send(embed=embedwarn)

【讨论】:

    猜你喜欢
    • 2020-04-28
    • 2021-04-29
    • 2023-01-22
    • 2021-06-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多