python - discord.py 自动删除链接无响应

标签 python discord.py

所以我正在制作一个机器人,如果您发送任何包含 .com 的内容,它会删除该消息并发送一条消息说“您的消息包含一个链接”,但该机器人是不工作。我尝试了很多不同的方法,但仍然无法正常工作!

#--- blacklisted words --- 
@bot.event
async def on_message(message):
  links = [
    ".com"
  ]
  if any(word in message.content.lower() for word in links):
    await message.delete()
    await message.channel.send("Your message contained a blacklisted word!")

我已确保该机器人具有烫发、检查拼写以及我能想到的一切。

最佳答案

添加

intents = discord.Intents(message_content=True)

kwarg 到你的机器人。

例如

bot = discord.Client(intents=intents)

确保您已在开发人员面板上启用消息意图

尝试通过添加打印来测试您的命令

@bot.event
async def on_message(message):
  links = [
    ".com"
  ]
  if any(word in message.content.lower() for word in links):
    print('filter matched for message')
    await message.delete()
    print('deleted message')
    await message.channel.send("your emssage contained a blacklisted word!")
    print('sent response')

检查哪里出了问题

如果您使用的是 discord.py V2,这就是解决方案。 您提供的代码无法重现问题

关于python - discord.py 自动删除链接无响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71707429/

相关文章:

python - 等待一个有 for 循环语法错误的函数

python - 如何在不和谐服务器中以用户身份而不是机器人身份登录并运行命令?

python - 将文本添加到 pandas dataframe plot

python - 没有带有 python 代码的名为 'redis' 的模块

python - 通过更改字体嵌入减小使用 matplotlib 创建的 PDF 的文件大小

python - 从数据框中的值计算增量

python - 如何在没有 discord.py 的情况下获取用户在 discord 服务器中发送的消息数?

Python 2.4.3 : ConfigParser. NoSectionError:无节: 'formatters'

python - 如何使 pyodbc 输出更具可读性/更好?

python - discord.py 如何使用 wait_for 等待作者消息?