Reputation: 13
So i've been trying to learn myself Python by making a Discord bot, everything went well until i had this error AttributeError: 'Bot' object has no attribute 'delete'
. I was going to make a feature in which if it detects certain words from a dictionary, it will be deleted. I've read Benjamin Soyka's question asking how to do the same, but with older version of Discord.py
Right now, my code is :
with open("bad_words.txt") as file: # bad-words.txt contains one blacklisted phrase per line
bad_words = [bad_word.strip().lower() for bad_word in file.readlines()]
@client.event
async def on_message(message):
print(message.content) #prints messages in console
for bad_word in bad_words:
if bad_word in message.content:
print("bad words detected") #prints when bad word is found
await client.delete(message) #delete said message
await client.process_commands(message)
I've tried with different ways like making classes or nested functions, but seems like none is working for me. Sorry if this question seems silly, and Thanks for your help!
Upvotes: 0
Views: 214
Reputation: 104
Use (Rewrite version)
await message.delete()
instead of
await client.delete(message)
Upvotes: 1