gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 05:43:57 26 4
gpt4 key购买 nike

所以我正在制作一个机器人,如果您发送任何包含 .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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com