【问题标题】:Error while running swear filter code (discord.py)运行发誓过滤器代码时出错 (discord.py)
【发布时间】:2021-02-21 06:42:47
【问题描述】:

今天我对我的代码进行了一些编辑,并试图让它提及服务器中的一个人。当我测试它时,它一直说“TypeError:on_message()缺少1个必需的位置参数:'message'”,我不知道如何解决这个问题。我输入了成员参数,但它仍然不起作用。有谁知道如何解决这个问题?

@client.event
async def on_message(message):    
    for bad_word in bad_words:
        if bad_word in message.content.lower().split(" "):
            t = discord.Embed(color=0x039e00, title="Message Removed", description=f":x:   {member.mention}, please do not say that here.")
            t.set_footer(text="DM TheSuperRobert2498#2498 for bot suggestions.")
            await message.channel.send(embed=t)
            await message.delete()
            return

【问题讨论】:

  • 这个错误是从这个函数被调用的时候开始的。这是框架的一部分吗? client.event 是什么?这个函数在哪里被调用?
  • 该函数在我的on_ready函数下被调用。
  • 好的,我们需要看看它是如何被调用的,以便在诊断这个问题时有任何希望
  • 我对 discord.py 还是有点陌生​​。
  • 你自己叫这个吗?如果是这样,您需要将有效消息传递给它。如果不是,那么它似乎是 dpy 的问题,尝试更新它。

标签: python discord.py


【解决方案1】:

member.mention 不起作用,因为您没有在 on_message 事件中传递 member。你仍然可以通过使用message.author.mention 传入message 来做你想做的事情。试试这个:

@client.event
async def on_message(message):    
    for bad_word in bad_words:
        if bad_word in message.content.lower().split(" "):
            t = discord.Embed(color=0x039e00, title="Message Removed", description=f":x:   {message.author.mention}, please do not say that here.")
            t.set_footer(text="DM TheSuperRobert2498#2498 for bot suggestions.")
            await message.channel.send(embed=t)
            await message.delete()
            return

【讨论】:

  • @TheSuperRobert 如果这对您有帮助,请务必点击我帖子旁边的否决按钮下方的接受按钮!
  • 哈哈,我忘了做,刚刚做了
猜你喜欢
  • 1970-01-01
  • 2012-12-10
  • 1970-01-01
  • 2021-12-31
  • 1970-01-01
  • 1970-01-01
  • 2010-12-12
  • 2012-09-30
  • 2014-04-26
相关资源
最近更新 更多