Reputation:
so I'm trying to code a basic discord moderation bot for my server. What I'm attempting to do is have the bot check a message to see if it contains a word from a text file (in the same directory). Here is my code:
import os
from keep_alive import keep_alive
from datetime import datetime
client = discord.Client()
@client.event
async def on_message(message):
if message.author == client.user:
return
for word in bad_words:
if message.content.contains(word):
await message.delete()
badwordEmbed = discord.Embed(title="You have sent a bad word!", description="", colour=0xff0000, timestamp=datetime.utcnow())
await message.channel.send(embed=badwordEmbed)
keep_alive()
client.run(os.getenv('TOKEN'))
However, when I send a discord message containing a word from the .txt file, I get this error:
if message.content.contains(word):
AttributeError: 'str' object has no attribute 'contains'
I have a feeling this is a basic error, but for now I'm not sure so I'd appreciate any help.
Upvotes: 0
Views: 326
Reputation: 45726
It's in
you need:
if word in message.content:
Strings have a __contains__
method (note the underscores), but this is used by in
.
Upvotes: 3